List of usage examples for org.springframework.integration.gateway TestService customCompletable
MyCompletableFuture customCompletable(String s);
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@Test public void testCustomCompletableNoAsync() throws Exception { QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel"); final AtomicReference<Thread> thread = new AtomicReference<>(); requestChannel.addInterceptor(new ChannelInterceptorAdapter() { @Override/*w ww. j av a2 s .c om*/ 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(1, TimeUnit.SECONDS); assertEquals("SYNC_CUSTOM_COMPLETABLE", reply); assertEquals(Thread.currentThread(), thread.get()); assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor")); }
From source file:org.springframework.integration.config.xml.GatewayParserTests.java
@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//from w w w. j a va 2 s. co m 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(1, 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"); }