热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

开发笔记:如何在骆驼中对石英进行单元测试

篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何在骆驼中对石英进行单元测试相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何在骆驼中对石英进行单元测试相关的知识,希望对你有一定的参考价值。



我有问题弄清楚如何测试我的路线使用quartz在其from我的spring文件




........... Object Added to DB ...........




我的测试文件

@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(locatiOns= "/beans-test.xml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class MetricExtractionTest{
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "quartz://metricExtractionTimer?fireNow=true")
protected ProducerTemplate producerTemplate;
@Test
public void testQuartzCron() throws Exception {
producerTemplate.sendBody(null);
}
}

例外:

Caused by: org.apache.camel.FailedToStartRouteException: Failed to start route metricExtractionTimer because of startupOrder clash. Route quartz already has startupOrder 1 configured which this route have as well. Please correct startupOrder to be unique among all your routes.
at org.apache.camel.impl.DefaultCamelContext.doCheckStartupOrderClash(DefaultCamelContext.java:3414)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3364)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3147)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3003)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:172)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2799)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2795)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2818)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2795)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2764)
at org.apache.camel.test.spring.CamelSpringTestContextLoader$7.execute(CamelSpringTestContextLoader.java:515)
at org.apache.camel.test.spring.CamelSpringTestHelper.doToSpringCamelContexts(CamelSpringTestHelper.java:92)
at org.apache.camel.test.spring.CamelSpringTestContextLoader.handleCamelContextStartup(CamelSpringTestContextLoader.java:509)
at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:164)
at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:87)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 28 more

答案

看起来Camel在手动触发自触发路线时遇到麻烦,这是可以理解的。此外,您真的不想测试Camel Quartz模块,因为这已经过良好测试的开源代码。

我建议你让石英路线调用一个带有direct:yourRouteName consumer的子路线。然后可以从您的单元测试中顺利调用那个。


另一答案


此外,您真的不想测试Camel Quartz模块,因为这已经过良好测试的开源代码。


不同意本声明。根据这个推理,我们不应该测试我们与其他框架的交互,例如春天,冬眠,骆驼等

@Bilal:你最好的办法是看看camel-quartz2项目如何测试自己[1]。

具体来说,你可以看一下[2]和[3]。

[1] https://github.com/apache/camel/tree/master/components/camel-quartz2/src/test

[2] https://github.com/apache/camel/blob/master/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/SpringQuartzCronRouteTest.java

[3] https://github.com/apache/camel/blob/master/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzCronRouteTest.xml

举个例子:

@Component
public class MyRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("quartz2://myGroup/myTimerName?cron=0/2+*+*+*+*+?")
.to("mock:result");
}
}
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
public class MyRouteTest {
@Autowired
private CamelContext camelContext;
@EndpointInject(uri = "mock:result")
private MockEndpoint resultEndpoint;
@Test
public void testRoute() throws Exception {
resultEndpoint.expectedMinimumMessageCount(3);
MockEndpoint.assertIsSatisfied(camelContext);
}
}


推荐阅读
author-avatar
龙欣23
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有