@Before public void initializeBarrier() { barrier = new CorrelatingMessageBarrier(); barrier.setCorrelationStrategy(correlationStrategy); barrier.setReleaseStrategy(releaseStrategy); when(correlationStrategy.getCorrelationKey(isA(Message.class))).thenReturn("foo"); when(releaseStrategy.canRelease(isA(MessageGroup.class))).thenReturn(true); }
@Test(timeout = 10000) public void shouldNotDropMessageOrBlockSendingThread() { OneMessagePerKeyReleaseStrategy trackingReleaseStrategy = new OneMessagePerKeyReleaseStrategy(); barrier.setReleaseStrategy(trackingReleaseStrategy); final CountDownLatch start = new CountDownLatch(1); final CountDownLatch sent = new CountDownLatch(200); ExecutorService exec = Executors.newSingleThreadExecutor(); for (int i = 0; i < 200; i++) { sendAsynchronously(barrier, testMessage(), start, sent, exec); } start.countDown(); try { sent.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } assertThat((barrier.receive()), is(notNullValue())); for (int i = 0; i < 199; i++) { trackingReleaseStrategy.release("foo"); assertThat((barrier.receive()), is(notNullValue())); } exec.shutdownNow(); }