Search in sources :

Example 46 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class ServiceActivatorDefaultFrameworkMethodTests method testReplyingMessageHandlerWithOtherMethod.

@Test
public void testReplyingMessageHandlerWithOtherMethod() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    this.replyingHandlerWithOtherMethodTestInputChannel.send(message);
    Message<?> reply = replyChannel.receive(0);
    assertEquals("bar", reply.getPayload());
    assertEquals("replyingHandlerWithOtherMethodTestInputChannel,replyingHandlerWithOtherMethodTestService", reply.getHeaders().get("history").toString());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 47 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class ServiceActivatorDefaultFrameworkMethodTests method testAsyncError.

@Test
public void testAsyncError() {
    QueueChannel errorChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("test").setErrorChannel(errorChannel).build();
    this.asyncIn.send(message);
    this.asyncService.future.setException(new RuntimeException("intended"));
    Message<?> error = errorChannel.receive(0);
    assertNotNull(error);
    assertThat(error, instanceOf(ErrorMessage.class));
    assertThat(error.getPayload(), instanceOf(MessagingException.class));
    assertThat(((MessagingException) error.getPayload()).getCause(), instanceOf(RuntimeException.class));
    assertThat(((MessagingException) error.getPayload()).getCause().getMessage(), equalTo("intended"));
    assertEquals("test", ((MessagingException) error.getPayload()).getFailedMessage().getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessagingException(org.springframework.messaging.MessagingException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Test(org.junit.Test)

Example 48 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class ServiceActivatorDefaultFrameworkMethodTests method testMessageProcessor.

@Test
public void testMessageProcessor() {
    Object processor = TestUtils.getPropertyValue(processorTestService, "handler.processor");
    assertSame(testMessageProcessor, processor);
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel).setHeader("foo", "foo").build();
    this.processorTestInputChannel.send(message);
    Message<?> reply = replyChannel.receive(0);
    assertEquals("foo:bar", reply.getPayload());
    assertThat(reply, not(hasHeaderKey("foo")));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 49 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class ServiceActivatorDefaultFrameworkMethodTests method testMessageHandler.

@Test
public void testMessageHandler() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    this.handlerTestInputChannel.send(message);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 50 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class ServiceActivatorDefaultFrameworkMethodTests method testReplyingMessageHandler.

@Test
public void testReplyingMessageHandler() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
    this.replyingHandlerTestInputChannel.send(message);
    Message<?> reply = replyChannel.receive(0);
    assertEquals("TEST", reply.getPayload());
    assertEquals("replyingHandlerTestInputChannel,replyingHandlerTestService", reply.getHeaders().get("history").toString());
    StackTraceElement[] st = (StackTraceElement[]) reply.getHeaders().get("callStack");
    assertTrue(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("AbstractSubscribableChannel", "MethodInvokerHelper", // close to the metal
    st));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Aggregations

QueueChannel (org.springframework.integration.channel.QueueChannel)709 Test (org.junit.Test)669 GenericMessage (org.springframework.messaging.support.GenericMessage)186 Message (org.springframework.messaging.Message)173 BeanFactory (org.springframework.beans.factory.BeanFactory)162 MessageChannel (org.springframework.messaging.MessageChannel)100 Matchers.containsString (org.hamcrest.Matchers.containsString)66 CountDownLatch (java.util.concurrent.CountDownLatch)59 DirectChannel (org.springframework.integration.channel.DirectChannel)57 ArrayList (java.util.ArrayList)55 PollableChannel (org.springframework.messaging.PollableChannel)55 MessagingException (org.springframework.messaging.MessagingException)53 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)51 AtomicReference (java.util.concurrent.atomic.AtomicReference)47 Socket (java.net.Socket)44 ErrorMessage (org.springframework.messaging.support.ErrorMessage)42 ServerSocket (java.net.ServerSocket)41 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)39 IOException (java.io.IOException)35 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)35