|
33 | 33 | import org.springframework.beans.DirectFieldAccessor;
|
34 | 34 | import org.springframework.beans.factory.BeanFactory;
|
35 | 35 | import org.springframework.integration.MessageDispatchingException;
|
| 36 | +import org.springframework.integration.annotation.AnnotationConstants; |
36 | 37 | import org.springframework.integration.annotation.Gateway;
|
37 | 38 | import org.springframework.integration.annotation.GatewayHeader;
|
| 39 | +import org.springframework.integration.annotation.MessagingGateway; |
38 | 40 | import org.springframework.integration.channel.DirectChannel;
|
39 | 41 | import org.springframework.integration.channel.NullChannel;
|
40 | 42 | import org.springframework.integration.channel.QueueChannel;
|
41 | 43 | import org.springframework.messaging.Message;
|
42 | 44 | import org.springframework.messaging.MessageChannel;
|
43 | 45 | import org.springframework.messaging.PollableChannel;
|
44 | 46 | import org.springframework.messaging.support.ChannelInterceptor;
|
| 47 | +import org.springframework.messaging.support.GenericMessage; |
45 | 48 | import org.springframework.messaging.support.MessageBuilder;
|
46 | 49 |
|
47 | 50 | import reactor.core.publisher.Mono;
|
@@ -233,6 +236,35 @@ public void futureVoid() throws Exception {
|
233 | 236 | .withMessageContaining("intentional dispatcher error");
|
234 | 237 | }
|
235 | 238 |
|
| 239 | + @Test |
| 240 | + public void futureVoidReply() throws Exception { |
| 241 | + QueueChannel requestChannel = new QueueChannel(); |
| 242 | + CountDownLatch readyForReplyLatch = new CountDownLatch(1); |
| 243 | + new Thread(() -> { |
| 244 | + try { |
| 245 | + Message<?> input = requestChannel.receive(); |
| 246 | + CompletableFuture<Void> reply = new CompletableFuture<>(); |
| 247 | + ((MessageChannel) input.getHeaders().getReplyChannel()).send(new GenericMessage<>(reply)); |
| 248 | + readyForReplyLatch.await(10, TimeUnit.SECONDS); |
| 249 | + reply.complete(null); |
| 250 | + } |
| 251 | + catch (InterruptedException e) { |
| 252 | + System.err.println(e); |
| 253 | + } |
| 254 | + }).start(); |
| 255 | + GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean(TestEchoService.class); |
| 256 | + proxyFactory.setDefaultRequestChannel(requestChannel); |
| 257 | + proxyFactory.setBeanName("testGateway"); |
| 258 | + proxyFactory.setBeanFactory(mock(BeanFactory.class)); |
| 259 | + proxyFactory.setAsyncExecutor(null); |
| 260 | + proxyFactory.afterPropertiesSet(); |
| 261 | + TestEchoService service = (TestEchoService) proxyFactory.getObject(); |
| 262 | + Future<Void> f = service.sendAndReceiveFutureVoid("test"); |
| 263 | + readyForReplyLatch.countDown(); |
| 264 | + Object result = f.get(10, TimeUnit.SECONDS); |
| 265 | + assertThat(result).isNull(); |
| 266 | + } |
| 267 | + |
236 | 268 | @Test
|
237 | 269 | public void monoWithMessageReturned() {
|
238 | 270 | QueueChannel requestChannel = new QueueChannel();
|
@@ -375,6 +407,7 @@ private interface TestEchoService {
|
375 | 407 |
|
376 | 408 | Future<Void> asyncSendAndForget(String s);
|
377 | 409 |
|
| 410 | + Future<Void> sendAndReceiveFutureVoid(String s); |
378 | 411 | Mono<Void> monoVoid(String s);
|
379 | 412 |
|
380 | 413 | }
|
|
0 commit comments