use of org.springframework.integration.gateway.TestService.MyCompletableMessageFuture 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.MyCompletableMessageFuture in project spring-integration by spring-projects.
the class GatewayParserTests method testCustomCompletableNoAsyncMessage.
@Test
public void testCustomCompletableNoAsyncMessage() 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);
MyCompletableMessageFuture result = service.customCompletableReturnsMessage("flowCustomCompletableM");
Message<?> reply = result.get(10, TimeUnit.SECONDS);
assertEquals("flowCustomCompletableM", reply.getPayload());
assertEquals(Thread.currentThread(), thread.get());
assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Aggregations