Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用队列通道的Spring集成测试_Spring_Testing_Spring Integration_Spring Integration Dsl - Fatal编程技术网

使用队列通道的Spring集成测试

使用队列通道的Spring集成测试,spring,testing,spring-integration,spring-integration-dsl,Spring,Testing,Spring Integration,Spring Integration Dsl,在Spring Integration中,我的DSL设置如下所示: ---> ---> ---> ---> Messages --> Gateway ---&

在Spring Integration中,我的DSL设置如下所示:

                                       --->                                        --->
                                       --->                                        --->
Messages --> Gateway ---> QueueChannel ---> MessageHandler(worker) -> QueueChannel ---> MH worker2 --> ...
                                       --->                                        --->
                                       --->                                        --->
我想为此编写一个集成测试,它将测试消息是否在正确的通道中。我现在在任何地方都不充实标题,所以我想使用:

this.someChannel.receive(TIMEOUT)
不幸的是,据我所知,它只阻塞了测试的主线程,而不是所有线程,因此它无法接收异步发送的任何消息。 我知道,存在着这样的情况:

this.someChannel.getReceiveCount()
它给了我很好的结果,但检查对我来说是不够的。 我如何处理它,以异步方式接收发送到队列的消息


编辑:我需要它,这一点很重要,因为在执行工作流期间消息会发生更改

您可以在测试中向这些队列通道添加通道拦截器,以跟踪通过这些通道的任何内容。当然,您需要在测试中设置一些障碍来等待异步消息,或者在测试结束时阻塞队列来收集它们以进行验证。另一种方法是在两者之间模拟或监视消息处理程序,但同样使用类似的
CountDownLatch
BlockingQueue
线程屏障来等待异步消息。查看文档中的更多信息: