コード例 #1
0
 public void testClosedCircuitPassesMessages() throws Exception {
   expectsMessageCount(3, result);
   sendMessage("direct:start", "message one");
   sendMessage("direct:start", "message two");
   sendMessage("direct:start", "message three");
   assertMockEndpointsSatisfied();
 }
コード例 #2
0
  public void testHalfOpenCircuitClosesAfterTimeout() throws Exception {
    expectsMessageCount(2, result);
    result.whenAnyExchangeReceived(
        new Processor() {
          @Override
          public void process(Exchange exchange) throws Exception {
            exchange.setException(new MyCustomException());
          }
        });

    sendMessage("direct:start", "message one");
    sendMessage("direct:start", "message two");
    sendMessage("direct:start", "message three");
    assertMockEndpointsSatisfied();

    result.reset();
    expectsMessageCount(1, result);

    Thread.sleep(1000);
    sendMessage("direct:start", "message four");
    assertMockEndpointsSatisfied();
  }
コード例 #3
0
  public void testFailedMessagesOpenCircuitToPreventMessageThree() throws Exception {
    expectsMessageCount(2, result);

    result.whenAnyExchangeReceived(
        new Processor() {
          @Override
          public void process(Exchange exchange) throws Exception {
            exchange.setException(new MyCustomException());
          }
        });

    Exchange exchangeOne = sendMessage("direct:start", "message one");
    Exchange exchangeTwo = sendMessage("direct:start", "message two");
    Exchange exchangeThree = sendMessage("direct:start", "message three");
    assertMockEndpointsSatisfied();

    assertTrue(exchangeOne.getException() instanceof MyCustomException);
    assertTrue(exchangeTwo.getException() instanceof MyCustomException);
    assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
  }