如何在测试中测试具有长重新传递延迟的Camel onExceptions代码块

huangapple go评论69阅读模式
英文:

How to test Camel onExceptions blocks with long redeliveryDelays in tests

问题

在测试一个骆驼路由时,我有一个具有处理能力的父类:

onException(org.xyz.SomeException.class)
   .maximumRedeliveries(7)
   .redeliveryDelay(25000)
   .handled()
   .end();

我有一个子类的RouteBuilder类,继承自父类,并使用super.configure()

@Override
public void configure() throws Exception {
  super.configure();

  from("direct:mytest")
      .routeId("mytest")
      .process(new SomeProcessor())
      .to("mock:endpoint");
}

我想在测试中运行它,并在测试中断言它重传了7次... 但是,当测试运行时,我仍然需要等待25秒才能进行每次重传。有没有办法让Camel忽略redeliveryDelay,或者在测试中将其设置为0?

如果我尝试在测试中重新定义redeliveryDelay,它会覆盖从父类继承的值?

有没有一种方法可以获取父类继承的onException定义,并仅修改redeliveryDelay属性?

我尝试过这个:

routeDefintionUnderTest.onException(org.xyz.SomeException.class).getRedeliveryPolicy();

但它返回null,好像无法获取从super.configure()定义的内容。

英文:

When testing a camel route I have a parent class with handling:

 onException(org.xyz.SomeException.class)
    .maximumRedeliveries(7)
    .redeliveryDelay(25000)
    .handled()
    .end();

And I have a child RouteBuilder class that inherits from that one, and uses super.configure()

@Override
public void configure() throws Exception {
  super.configure();

  from("direct:mytest")
      .routeId("mytest")
      .process(new SomeProcessor())
      .to("mock:endpoint");
}

I'd like to run this in a test, and I have a harness where I assert it redelivered 7 times... However, when the test runs I still have to wait 25s between each redelivery. Is there a way to make Camel ignore the redeliveryDelay, or somehow set it to 0 for only tests?

If i try to redefine the redeliveryDelay in the tests, it overwrites what was inherited from the parent?

Is there a way to get the parent inherited onException definition and only modify the redeliveryDelay property?

I've tried this

routeDefintionUnderTest.onException(org.xyzSomeException.class).getRedeliveryPolicy();

but it returns null, as if it can't get what was defined with the super.configure() ?

答案1

得分: 0

Did you try to use
PropertyPlaceholder-OverridingProperties ?
Your timeout could be put into a variable in your blueprint and override on testing purpose.

英文:

Did you try to use
PropertyPlaceholder-OverridingProperties ?
Your timeout could be put into a variable in your blueprint and override on testing purpose.

答案2

得分: 0

我发现我可以通过以下方式以编程方式访问重新发送:

class RouteUnderTest extends MyRoute {

  @Override
  public void configure() throws Exception {
    super.configure();

    final List<OnExceptionDefinition> onExceptionDefinitions = super.getRouteCollection().getOnExceptions();

    for (final OnExceptionDefinition oed : onExceptionDefinitions) {
      oed.redeliveryDelay(0);
    }
  }
}
英文:

I found i could access the redelivery programmatically like this:

class RouteUnderTest extends MyRoute {

  @Override
  public void configure() throws Exception {
    super.configure();

    final List&lt;OnExceptionDefinition&gt; onExceptionDefinitions = super.getRouteCollection().getOnExceptions();

    for (final OnExceptionDefinition oed : onExceptions) {
      oed.redeliveryDelay(0);
    }
  }
}

huangapple
  • 本文由 发表于 2020年9月25日 20:38:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64064336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定