public void testMulticastParalllelStopOnExceptionStop() throws Exception {
    // we run in parallel so we may get 0 or 1 messages
    getMockEndpoint("mock:foo").expectedMinimumMessageCount(0);
    getMockEndpoint("mock:bar").expectedMinimumMessageCount(0);
    getMockEndpoint("mock:baz").expectedMinimumMessageCount(0);
    // we should not complete and thus 0
    getMockEndpoint("mock:result").expectedMessageCount(0);

    try {
      template.sendBody("direct:start", "Kaboom");
      fail("Should thrown an exception");
    } catch (CamelExecutionException e) {
      ExecutionException ee = assertIsInstanceOf(ExecutionException.class, e.getCause());
      CamelExchangeException cause =
          assertIsInstanceOf(CamelExchangeException.class, ee.getCause());
      assertTrue(cause.getMessage().startsWith("Parallel processing failed for number "));
      assertTrue(cause.getMessage().contains("Exchange[Message: Kaboom]"));
      assertEquals("Forced", cause.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();
  }
コード例 #2
0
  @Test
  public void testSplitStopOnException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    // we expect 1 messages to be split since the 2nd message should fail
    split.expectedBodiesReceived("Camel rocks");

    // and no combined aggregated message since we stop on exception
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);

    // now send a message with an unknown letter (F) which forces an exception to occur
    try {
      template.sendBody("direct:start", "A,F,C");
      fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
      CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
      IllegalArgumentException iae =
          assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
      assertEquals("Key not a known word F", iae.getMessage());
    }

    assertMockEndpointsSatisfied();
  }