【问题标题】:Apache Camel Integration Test - NotifyBuilderApache Camel 集成测试 - NotifyBuilder
【发布时间】:2010-11-11 01:28:26
【问题描述】:

我正在编写集成测试来测试现有路由。获得响应的推荐方式如下所示(通过Camel In Action 第 6.4.1 节):

public class TestGetClaim extends CamelTestSupport {

    @Produce(uri = "seda:getClaimListStart")
    protected ProducerTemplate producer;

    @Test
    public void testNormalClient() {
        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

        producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A"));
        boolean matches = notify.matches(5, TimeUnit.SECONDS);
        assertTrue(matches);

        BrowsableEndpoint be = context.getEndpoint("seda:getClaimListResponse", BrowsableEndpoint.class);
        List<Exchange> list = be.getExchanges();
        assertEquals(1, list.size());
        System.out.println("***RESPONSE is type "+list.get(0).getIn().getBody().getClass().getName());
    }
}

测试运行,但我什么也没得到。 assertTrue(matches) 在 5 秒超时后失败。

如果我将测试重写为如下所示,我会得到响应:

@Test
public void testNormalClient() {
    producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A"));
    Object resp = context.createConsumerTemplate().receiveBody("seda:getClaimListResponse");
    System.out.println("***RESPONSE is type "+resp.getClass().getName());
}

文档对此有点轻描淡写,所以谁能告诉我第一种方法我做错了什么?改用第二种方法有什么问题吗?

谢谢。

更新 我已经对此进行了分解,看起来问题在于将 seda 作为起始端点与在路由中使用 recipientList 相结合。我还更改了 NotifyBuilder 的构造(我指定了错误的端点)。

  • 如果我将起始端点更改为 direct 而不是 seda 那么测试将起作用;或
  • 如果我注释掉 recipientList 那么测试将起作用。

这是重现此问题的 Route 的精简版本:

public class TestRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {
//      from("direct:start")    //works
        from("seda:start")  //doesn't work
        .recipientList(simple("exec:GetClaimList.bat?useStderrOnEmptyStdout=true&args=${body.client}"))
        .to("seda:finish");
    }

}

请注意,如果我将 NotifyTest 的源代码从“Camel In Action”源更改为具有这样的路由构建器,那么它也会失败。

【问题讨论】:

    标签: esb apache-camel


    【解决方案1】:

    尝试在 getEndpoint 中使用“seda:getClaimListResponse”以确保端点 uri 100% 正确

    【讨论】:

    • 谢谢克劳斯。我已经更新了这个问题。 GetClaimListRouteBuilder.responseNode 只是一个返回相同字符串的静态方法。我已将其替换并重新运行测试,结果相同。
    • 克劳斯,我发现了一些问题并更新了我的问题。结果你觉得奇怪吗?
    【解决方案2】:

    FWIW:notifyBuilder 与 seda 队列一起似乎不太有效:一个测试类来说明:

    public class NotifyBuilderTest extends CamelTestSupport {
    
    // Try these out!
    // String inputURI = "seda:foo";   // Fails
    // String inputURI = "direct:foo"; // Passes
    
    @Test
    public void testNotifyBuilder() {
    
        NotifyBuilder b = new NotifyBuilder(context).from(inputURI)
                .whenExactlyCompleted(1).create();
    
        assertFalse( b.matches() );
        template.sendBody(inputURI, "Test");
        assertTrue( b.matches() );
    
        b.reset();
    
        assertFalse( b.matches() );
        template.sendBody(inputURI, "Test2");
        assertTrue( b.matches() );
    }
    
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from(inputURI).to("mock:foo");
            }
        };
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 2018-02-08
      • 2018-06-27
      • 2018-02-10
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      相关资源
      最近更新 更多