public void haltTransferThd() { transferQueue.close(); }
private void run(Runnable producer, Runnable consumer, JCQueue queue, int sleepMs, int producerNum) throws InterruptedException { Thread[] producerThreads = new Thread[producerNum]; for (int i = 0; i < producerNum; i++) { producerThreads[i] = new Thread(producer); producerThreads[i].start(); } Thread consumerThread = new Thread(consumer); consumerThread.start(); Thread.sleep(sleepMs); for (int i = 0; i < producerNum; i++) { producerThreads[i].interrupt(); } for (int i = 0; i < producerNum; i++) { producerThreads[i].join(TIMEOUT); assertFalse("producer " + i + " is still alive", producerThreads[i].isAlive()); } queue.close(); consumerThread.interrupt(); consumerThread.join(TIMEOUT); assertFalse("consumer is still alive", consumerThread.isAlive()); }
try { LOG.info("Shutting down executor " + executor.getComponentId() + ":" + executor.getExecutorId()); executor.getReceiveQueue().close(); for (Utils.SmartThread t : threads) { t.interrupt();
@Test public void testNoReOrderingUnderBackPressure() throws Exception { final int MESSAGES = 100; final int CAPACITY = 64; final JCQueue queue = createQueue("testBackPressure", CAPACITY); for (int i = 0; i < MESSAGES; i++) { if (!queue.tryPublish(i)) { Assert.assertTrue(queue.tryPublishToOverflow(i)); } } TestConsumer consumer = new TestConsumer(); queue.consume(consumer); Assert.assertEquals(MESSAGES, consumer.lastMsg); queue.close(); }
@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(); }