Search in sources :

Example 6 with TestService

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

the class GatewayParserTests method testSolicitResponse.

@Test
public void testSolicitResponse() {
    PollableChannel channel = (PollableChannel) context.getBean("replyChannel");
    channel.send(new GenericMessage<String>("foo"));
    TestService service = (TestService) context.getBean("solicitResponse");
    String result = service.solicitResponse();
    assertEquals("foo", result);
}
Also used : TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 7 with TestService

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

the class GatewayParserTests method testAsyncCompletableNoAsync.

@Test
public void testAsyncCompletableNoAsync() 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<String> result = service.completable("flowCompletable");
    String reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("SYNC_COMPLETABLE", reply);
    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 8 with TestService

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

the class GatewayParserTests method testOneWayOverride.

@Test
public void testOneWayOverride() {
    TestService service = (TestService) context.getBean("methodOverride");
    service.oneWay("foo");
    PollableChannel channel = (PollableChannel) context.getBean("otherRequestChannel");
    Message<?> result = channel.receive(10000);
    assertNotNull(result);
    assertEquals("fiz", result.getPayload());
    assertEquals("bar", result.getHeaders().get("foo"));
    assertEquals("qux", result.getHeaders().get("baz"));
    GatewayProxyFactoryBean fb = context.getBean("&methodOverride", GatewayProxyFactoryBean.class);
    assertEquals(1000L, TestUtils.getPropertyValue(fb, "defaultRequestTimeout", Expression.class).getValue());
    assertEquals(2000L, TestUtils.getPropertyValue(fb, "defaultReplyTimeout", Expression.class).getValue());
    Map<?, ?> methods = TestUtils.getPropertyValue(fb, "methodMetadataMap", Map.class);
    GatewayMethodMetadata meta = (GatewayMethodMetadata) methods.get("oneWay");
    assertNotNull(meta);
    assertEquals("456", meta.getRequestTimeout());
    assertEquals("123", meta.getReplyTimeout());
    assertEquals("foo", meta.getReplyChannelName());
    meta = (GatewayMethodMetadata) methods.get("oneWayWithTimeouts");
    assertNotNull(meta);
    assertEquals("#args[1]", meta.getRequestTimeout());
    assertEquals("#args[2]", meta.getReplyTimeout());
    service.oneWayWithTimeouts("foo", 100L, 200L);
    result = channel.receive(10000);
    assertNotNull(result);
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) GatewayMethodMetadata(org.springframework.integration.gateway.GatewayMethodMetadata) Test(org.junit.Test)

Example 9 with TestService

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

the class GatewayParserTests method testAsyncCompletableMessage.

@Test
public void testAsyncCompletableMessage() 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("asyncCompletable", TestService.class);
    CompletableFuture<Message<?>> result = service.completableReturnsMessage("foo");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("foo", reply.getPayload());
    assertThat(thread.get().getName(), startsWith("testExec-"));
    assertNotNull(TestUtils.getPropertyValue(context.getBean("&asyncCompletable"), "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 10 with TestService

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

the class GatewayParserTests method testCustomCompletableNoAsyncAttemptAsync.

@Test
public void testCustomCompletableNoAsyncAttemptAsync() throws Exception {
    Object gateway = context.getBean("&customCompletableAttemptAsync");
    Log logger = spy(TestUtils.getPropertyValue(gateway, "logger", Log.class));
    when(logger.isDebugEnabled()).thenReturn(true);
    new DirectFieldAccessor(gateway).setPropertyValue("logger", logger);
    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("customCompletableAttemptAsync", TestService.class);
    MyCompletableFuture result = service.customCompletable("flowCustomCompletable");
    String reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("SYNC_CUSTOM_COMPLETABLE", reply);
    assertEquals(Thread.currentThread(), thread.get());
    assertNotNull(TestUtils.getPropertyValue(gateway, "asyncExecutor"));
    verify(logger).debug("AsyncTaskExecutor submit*() return types are incompatible with the method return type; " + "running on calling thread; the downstream flow must return the required Future: " + "MyCompletableFuture");
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Log(org.apache.commons.logging.Log) TestService(org.springframework.integration.gateway.TestService) AtomicReference(java.util.concurrent.atomic.AtomicReference) MyCompletableFuture(org.springframework.integration.gateway.TestService.MyCompletableFuture) MessageChannel(org.springframework.messaging.MessageChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) 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