php小编新一将为您介绍如何为 integrationflows 创建功能测试。integrationflows是spring integration框架中的一个重要组件,用于定义和管理消息流转的逻辑。功能测试是保证integrationflows正确运行的关键环节之一。在本文中,我们将介绍为integrationflows创建功能测试的步骤和注意事项,以帮助开发人员更好地进行集成测试工作。
我有一个 standardintegrationflow ,它每天运行并删除超过 10 天的文件。
@Bean public StandardIntegrationFlow oldReceiptsCleaner( @Qualifier("receiptSftpRemoteFileTemplate") RecursiveSftpRemoteFileTemplate receiptSftpRemoteFileTemplate, RemoteSftpFileRemover remoteSftpFileRemover) { return IntegrationFlows.from( Sftp.inboundStreamingAdapter(receiptSftpRemoteFileTemplate) .remoteDirectory(properties.getSftpPath()), e -> e.poller( Pollers.cron(properties.getCronExpression()) .maxMessagesPerPoll(-1)).id("oldReceiptsCleanerPoller")) .handle(remoteSftpFileRemover::removeFile) .get(); }
我想创建一个功能测试来验证它是否有效。我已经手动测试了代码,将 cron 表达式设置为每 2 分钟运行一次并删除早于 5 分钟的文件,但当然我需要一些自动化测试。
我曾想过创建 2 个文件,一个超过 10 天,另一个则不然。获取这两个文件并验证它们是否存在。然后使用 sourcepollingchanneladapter 的对象手动触发 standardintegrationflow 并调用 .start() 函数,然后尝试再次获取并验证是否已删除。
第一个问题是这是否是测试 integrationflow 的正确方法。另外,我找不到一种简单的方法来在测试中创建文件并更改其修改时间。
我正在使用 spring-integration 5.5.15 和 spock 框架进行测试。还使用 minio 容器在服务器上存储文件以进行功能测试
您可以将 PollerSpec 作为 bean 并从 oldReceiptsCleaner 流定义中引用它。然后您在测试配置中覆盖该 bean。然后你就有了 LastModifiedFileListFilter ,它可以基于 age 的某些属性并在测试中指定所需的值。
我不熟悉Minio,但可能有API如何使用所需的lastModified创建文件。
那么是的。您可以将 @SpringIntegrationTest 与 noAutoStartup 一起使用作为 Sftp.inboundStreamingAdapter 的 bean 名称。创建文件后,您可以在测试方法中手动启动SourcePollingChannelAdapter。
以上就是如何为 IntegrationFlows 创建功能测试的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号