使用OnlyOnceTrigger测试弹簧集成流程时是否触发了任何钩子?

问题描述 投票:0回答:1

在测试具有弹簧集成的项目时,使用OnlyOnceTrigger,预计很快就会完成流程。但是我找不到一种方法来确定何时我必须使用Thread.sleep(n)等待足够的时间,这是非常低效的。

例如,使用以下示例代码,我如何知道轮询的4个整数都被打印出来?有关此问题的任何建议吗?

@SpringBootApplication
@EnableIntegration
public class DemoApplication {

    Log logger = LogFactory.getLog(DemoApplication.class);

    @Bean
    TaskExecutor taskExecutor(){
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setMaxPoolSize(20);
        taskExecutor.setCorePoolSize(10);
        return taskExecutor;
    }

    @Bean
    PollerSpec poller(){
        return Pollers.trigger(new OnlyOnceTrigger()).maxMessagesPerPoll(1);
    }

    @Bean
    @InboundChannelAdapter(channel = "input",
            poller = @Poller("poller"))
    public MessageSource<Integer[]> inbound(){
        return new MessageSource<Integer[]>() {
            public Message<Integer[]> receive() {
                return MessageBuilder.withPayload(new Integer[]{1,2,3,4}).build();
            }
        };
    }

    @Splitter(inputChannel = "input", outputChannel = "output")
    public Integer[] split(Integer[] list){
        return list;
    }

    @Bean
    QueueChannel output(){
        return new QueueChannel(2);
    }

    @ServiceActivator(inputChannel = "output",
            poller = @Poller(taskExecutor = "taskExecutor", fixedRate = "1", maxMessagesPerPoll = "1"))
    public void markSms(int value) throws Exception {
        System.out.println(value);
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
spring testing spring-integration
1个回答
0
投票

您可以将通道拦截器添加到流中的最后一个通道,以检测流何时结束。有关其他测试建议,请参阅testing-samples。另外advanced-testing-samples和参考手册中的Testing Support Appendix

© www.soinside.com 2019 - 2024. All rights reserved.