Search in sources :

Example 1 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncCompletableNoAsyncMessage.

@Test
public void testAsyncCompletableNoAsyncMessage() throws Exception {
    QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
    final AtomicReference<Thread> thread = new AtomicReference<>();
    requestChannel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            thread.set(Thread.currentThread());
            return super.preSend(message, channel);
        }
    });
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("completableNoAsync", TestService.class);
    CompletableFuture<Message<?>> result = service.completableReturnsMessage("flowCompletableM");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("flowCompletableM", reply.getPayload());
    assertEquals(Thread.currentThread(), thread.get());
    assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 2 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncDisabledGateway.

@Test
public void testAsyncDisabledGateway() throws Exception {
    PollableChannel requestChannel = (PollableChannel) context.getBean("requestChannel");
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("asyncOff", TestService.class);
    Future<Message<?>> result = service.async("futureSync");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("futureSync", reply.getPayload());
    Object serviceBean = context.getBean("&asyncOff");
    assertNull(TestUtils.getPropertyValue(serviceBean, "asyncExecutor"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 3 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testRequestReply.

@Test
public void testRequestReply() {
    PollableChannel requestChannel = (PollableChannel) context.getBean("requestChannel");
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = (TestService) context.getBean("requestReply");
    String result = service.requestReply("foo");
    assertEquals("foo", result);
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 4 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testCustomCompletableNoAsync.

@Test
public void testCustomCompletableNoAsync() throws Exception {
    QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
    final AtomicReference<Thread> thread = new AtomicReference<>();
    requestChannel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            thread.set(Thread.currentThread());
            return super.preSend(message, channel);
        }
    });
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("completableNoAsync", TestService.class);
    MyCompletableFuture result = service.customCompletable("flowCustomCompletable");
    String reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("SYNC_CUSTOM_COMPLETABLE", reply);
    assertEquals(Thread.currentThread(), thread.get());
    assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Also used : MyCompletableFuture(org.springframework.integration.gateway.TestService.MyCompletableFuture) ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 5 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testMonoGateway.

@Test
public void testMonoGateway() throws Exception {
    PollableChannel requestChannel = context.getBean("requestChannel", PollableChannel.class);
    MessageChannel replyChannel = context.getBean("replyChannel", MessageChannel.class);
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("promise", TestService.class);
    Mono<Message<?>> result = service.promise("foo");
    Message<?> reply = result.block(Duration.ofSeconds(1));
    assertEquals("foo", reply.getPayload());
    assertNotNull(TestUtils.getPropertyValue(context.getBean("&promise"), "asyncExecutor"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 TestService (org.springframework.integration.gateway.TestService)14 MessageChannel (org.springframework.messaging.MessageChannel)11 Message (org.springframework.messaging.Message)10 GenericMessage (org.springframework.messaging.support.GenericMessage)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 QueueChannel (org.springframework.integration.channel.QueueChannel)7 PollableChannel (org.springframework.messaging.PollableChannel)7 ChannelInterceptorAdapter (org.springframework.messaging.support.ChannelInterceptorAdapter)7 MyCompletableFuture (org.springframework.integration.gateway.TestService.MyCompletableFuture)2 Log (org.apache.commons.logging.Log)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 GatewayMethodMetadata (org.springframework.integration.gateway.GatewayMethodMetadata)1 GatewayProxyFactoryBean (org.springframework.integration.gateway.GatewayProxyFactoryBean)1 MyCompletableMessageFuture (org.springframework.integration.gateway.TestService.MyCompletableMessageFuture)1