use of org.springframework.messaging.support.ChannelInterceptorAdapter in project spring-integration by spring-projects.
the class ChannelInterceptorTests method testPostSendInterceptorWithUnsentMessage.
@Test
public void testPostSendInterceptorWithUnsentMessage() {
final AtomicInteger invokedCounter = new AtomicInteger(0);
final AtomicInteger sentCounter = new AtomicInteger(0);
final QueueChannel singleItemChannel = new QueueChannel(1);
singleItemChannel.addInterceptor(new ChannelInterceptorAdapter() {
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
assertNotNull(message);
assertNotNull(channel);
assertSame(singleItemChannel, channel);
if (sent) {
sentCounter.incrementAndGet();
}
invokedCounter.incrementAndGet();
}
});
assertEquals(0, invokedCounter.get());
assertEquals(0, sentCounter.get());
singleItemChannel.send(new GenericMessage<String>("test1"));
assertEquals(1, invokedCounter.get());
assertEquals(1, sentCounter.get());
singleItemChannel.send(new GenericMessage<String>("test2"), 0);
assertEquals(2, invokedCounter.get());
assertEquals(1, sentCounter.get());
assertNotNull(singleItemChannel.removeInterceptor(0));
singleItemChannel.send(new GenericMessage<String>("test2"), 0);
assertEquals(2, invokedCounter.get());
assertEquals(1, sentCounter.get());
}
Aggregations