use of org.springframework.integration.gateway.TestService.MyCompletableFuture 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"));
}
use of org.springframework.integration.gateway.TestService.MyCompletableFuture in project spring-integration by spring-projects.
the class GatewayParserTests method startResponder.
private void startResponder(final PollableChannel requestChannel, final MessageChannel replyChannel) {
Executors.newSingleThreadExecutor().execute(() -> {
Message<?> request = requestChannel.receive(60000);
assertNotNull("Request not received", request);
Message<?> reply = MessageBuilder.fromMessage(request).setCorrelationId(request.getHeaders().getId()).build();
Object payload = null;
if (request.getPayload().equals("futureSync")) {
payload = new AsyncResult<Message<?>>(reply);
} else if (request.getPayload().equals("flowCompletable")) {
payload = CompletableFuture.<String>completedFuture("SYNC_COMPLETABLE");
} else if (request.getPayload().equals("flowCustomCompletable")) {
MyCompletableFuture myCompletableFuture1 = new MyCompletableFuture();
myCompletableFuture1.complete("SYNC_CUSTOM_COMPLETABLE");
payload = myCompletableFuture1;
} else if (request.getPayload().equals("flowCompletableM")) {
payload = CompletableFuture.<Message<?>>completedFuture(reply);
} else if (request.getPayload().equals("flowCustomCompletableM")) {
MyCompletableMessageFuture myCompletableFuture2 = new MyCompletableMessageFuture();
myCompletableFuture2.complete(reply);
payload = myCompletableFuture2;
}
if (payload != null) {
reply = MessageBuilder.withPayload(payload).copyHeaders(reply.getHeaders()).build();
}
replyChannel.send(reply);
});
}
use of org.springframework.integration.gateway.TestService.MyCompletableFuture 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");
}
Aggregations