public SpoutExecutor(final WorkerState workerData, final List<Long> executorId, Map<String, String> credentials) { super(workerData, executorId, credentials, ClientStatsUtil.SPOUT); this.spoutWaitStrategy = ReflectionUtils.newInstance((String) topoConf.get(Config.TOPOLOGY_SPOUT_WAIT_STRATEGY)); this.spoutWaitStrategy.prepare(topoConf, WAIT_SITUATION.SPOUT_WAIT); this.backPressureWaitStrategy = ReflectionUtils.newInstance((String) topoConf.get(Config.TOPOLOGY_BACKPRESSURE_WAIT_STRATEGY)); this.backPressureWaitStrategy.prepare(topoConf, WAIT_SITUATION.BACK_PRESSURE_WAIT); this.lastActive = new AtomicBoolean(false); this.hasAckers = StormCommon.hasAckers(topoConf); this.emittedCount = new MutableLong(0); this.emptyEmitStreak = new MutableLong(0); this.spoutThrottlingMetrics = new SpoutThrottlingMetrics(); this.stats = new SpoutExecutorStats( ConfigUtils.samplingRate(this.getTopoConf()), ObjectReader.getInt(this.getTopoConf().get(Config.NUM_STAT_BUCKETS))); this.builtInMetrics = new BuiltinSpoutMetrics(stats); }
@Test public void testBasicBackPressure() throws Exception { final int MESSAGES = 100; final int CAPACITY = 64; final JCQueue queue = createQueue("testBackPressure", CAPACITY); // pump more msgs than Q size & verify msg count is as expexted for (int i = 0; i < MESSAGES; i++) { if (i >= CAPACITY) { Assert.assertFalse(queue.tryPublish(i)); } else { Assert.assertTrue(queue.tryPublish(i)); } } Assert.assertEquals(CAPACITY, queue.size()); Assert.assertEquals(0, queue.getOverflowCount()); // drain 1 element and ensure BP is relieved (i.e tryPublish() succeeds) final MutableLong consumeCount = new MutableLong(0); queue.consume(new TestConsumer(), () -> consumeCount.increment() <= 1); Assert.assertEquals(CAPACITY - 1, queue.size()); Assert.assertTrue(queue.tryPublish(0)); queue.close(); }