等待ExecutorChannel在junit中完成



我正在使用spring集成和junit

@Test
public void testOnePojo() throws Exception {
ExecutorChannel orderSendChannel = 
context.getBean("validationChannel", ExecutorChannel.class);
ExecutorChannel orderReceiveChannel = context.getBean("auditChannel", ExecutorChannel.class);
orderReceiveChannel.subscribe(t -> {
System.out.println(t);//I want to see this output     
}); 
orderSendChannel.send(getMessageMessage());
}

我看不到接收通道的输出。订阅后JUnit退出。是否有合适的方法在testOnePojo内部等待,直到auditChannel收到响应。

您可以在测试中使用CoundDownLatch,并等待MessageHandler处理您的消息。您的示例看起来像这样:

@Test
public void testOnePojo() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
ExecutorChannel orderSendChannel =
context.getBean("validationChannel", ExecutorChannel.class);
ExecutorChannel orderReceiveChannel = context.getBean("auditChannel", ExecutorChannel.class);
orderReceiveChannel.subscribe(t -> {
System.out.println(t);//I want to see this output
countDownLatch.countDown();
});
orderSendChannel.send(getMessageMessage());
countDownLatch.await();
}

相关内容

  • 没有找到相关文章

最新更新