/** * Await until all of this processor's channels have completed. * * @throws CancellationException if the channel was cancelled * @throws ExecutionException if the channel execution threw an exception * @throws InterruptedException if the current thread is interrupted while waiting */ public void await() throws ExecutionException, InterruptedException, CancellationException { for (CompositeRequestChannel channel : channelBySourceName.values()) { channel.await(); } }
@Test public void shouldSubmitBlockedRequestsToConnection() throws Exception { // Start the channel ... channel.start(executor, context, connectionFactory); // Submit the requests to the channel ... List<CountDownLatch> latches = new ArrayList<CountDownLatch>(); for (Request request : requests) { CountDownLatch latch = new CountDownLatch(1); latches.add(latch); channel.add(request, latch); } // Mark the channel as done ... channel.close(); // Wait until the channel has completed ... channel.await(); // Verify that all of the latches were decremented ... for (CountDownLatch latch : latches) { latch.await(); assertThat(latch.getCount(), is(0L)); } // Verify that all the requests to the channel were processed ... Iterator<Request> iter = executedRequests.iterator(); for (Request expected : requests) { assertThat(iter.hasNext(), is(true)); assertThat(iter.next(), is(sameInstance(expected))); } assertThat(iter.hasNext(), is(false)); }
@Test public void shouldSubmitRequestsToConnection() throws Exception { // Start the channel ... channel.start(executor, context, connectionFactory); // Submit the requests to the channel ... for (Request request : requests) { channel.add(request); } // Mark the channel as done ... channel.close(); // Wait until the channel has completed ... channel.await(); // Verify that all the requests to the channel were processed ... Iterator<Request> iter = executedRequests.iterator(); for (Request expected : requests) { assertThat(iter.hasNext(), is(true)); assertThat(iter.next(), is(sameInstance(expected))); } assertThat(iter.hasNext(), is(false)); }
} finally { try { channel.await(); } catch (CancellationException err) { composite.cancel();