@Test public void testPublisherCallbackChannelImplCloseWithPending() throws Exception { Listener listener = mock(Listener.class); final CountDownLatch latch = new CountDownLatch(2); doAnswer(invocation -> { boolean ack = invocation.getArgument(1); if (!ack) { latch.countDown(); } return null; }).when(listener).handleConfirm(any(PendingConfirm.class), anyBoolean()); when(listener.getUUID()).thenReturn(UUID.randomUUID().toString()); when(listener.isConfirmListener()).thenReturn(true); Channel channelMock = mock(Channel.class); PublisherCallbackChannelImpl channel = new PublisherCallbackChannelImpl(channelMock, this.executorService); channel.addListener(listener); for (int i = 0; i < 2; i++) { long seq = i + 1000; channel.addPendingConfirm(listener, seq, new PendingConfirm(new CorrelationData(Long.toHexString(seq)), System.currentTimeMillis())); } channel.close(); assertTrue(latch.await(10, TimeUnit.SECONDS)); int n = 0; while (n++ < 100 && TestUtils.getPropertyValue(channel, "pendingConfirms", Map.class).size() > 0) { Thread.sleep(100); } assertEquals(0, TestUtils.getPropertyValue(channel, "pendingConfirms", Map.class).size()); }