Example usage for org.springframework.integration.aggregator BarrierMessageHandler setDiscardChannelName

List of usage examples for org.springframework.integration.aggregator BarrierMessageHandler setDiscardChannelName

Introduction

In this page you can find the example usage for org.springframework.integration.aggregator BarrierMessageHandler setDiscardChannelName.

Prototype

public void setDiscardChannelName(String discardChannelName) 

Source Link

Document

Set the name of the channel to which late arriving trigger messages are sent.

Usage

From source file:org.springframework.integration.aggregator.BarrierMessageHandlerTests.java

@Test
public void testLateReply() throws Exception {
    final BarrierMessageHandler handler = new BarrierMessageHandler(0);
    QueueChannel outputChannel = new QueueChannel();
    QueueChannel discardChannel = new QueueChannel();
    handler.setOutputChannel(outputChannel);
    handler.setDiscardChannelName("discards");
    handler.setChannelResolver(s -> discardChannel);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();//www .  ja v a2s.c  o  m
    final CountDownLatch latch = new CountDownLatch(1);
    Executors.newSingleThreadExecutor().execute(() -> {
        handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
        latch.countDown();
    });
    Map<?, ?> suspensions = TestUtils.getPropertyValue(handler, "suspensions", Map.class);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertEquals("suspension not removed", 0, suspensions.size());
    Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
    new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
    final Message<String> triggerMessage = MessageBuilder.withPayload("bar").setCorrelationId("foo").build();
    handler.trigger(triggerMessage);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).error(captor.capture());
    assertThat(captor.getValue(),
            allOf(containsString("Suspending thread timed out or did not arrive within timeout for:"),
                    containsString("payload=bar")));
    assertEquals(0, suspensions.size());
    Message<?> discard = discardChannel.receive(0);
    assertSame(discard, triggerMessage);
    handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
    assertEquals(0, suspensions.size());
}