Ejemplo n.º 1
0
  protected void assertCommandExecutionEvents(
      HystrixInvokableInfo<?> command, HystrixEventType... expectedEventTypes) {
    boolean emitExpected = false;
    int expectedEmitCount = 0;

    boolean fallbackEmitExpected = false;
    int expectedFallbackEmitCount = 0;

    List<HystrixEventType> condensedEmitExpectedEventTypes = new ArrayList<HystrixEventType>();

    for (HystrixEventType expectedEventType : expectedEventTypes) {
      if (expectedEventType.equals(HystrixEventType.EMIT)) {
        if (!emitExpected) {
          // first EMIT encountered, add it to condensedEmitExpectedEventTypes
          condensedEmitExpectedEventTypes.add(HystrixEventType.EMIT);
        }
        emitExpected = true;
        expectedEmitCount++;
      } else if (expectedEventType.equals(HystrixEventType.FALLBACK_EMIT)) {
        if (!fallbackEmitExpected) {
          // first FALLBACK_EMIT encountered, add it to condensedEmitExpectedEventTypes
          condensedEmitExpectedEventTypes.add(HystrixEventType.FALLBACK_EMIT);
        }
        fallbackEmitExpected = true;
        expectedFallbackEmitCount++;
      } else {
        condensedEmitExpectedEventTypes.add(expectedEventType);
      }
    }
    List<HystrixEventType> actualEventTypes = command.getExecutionEvents();
    assertEquals(expectedEmitCount, command.getNumberEmissions());
    assertEquals(expectedFallbackEmitCount, command.getNumberFallbackEmissions());
    assertEquals(condensedEmitExpectedEventTypes, actualEventTypes);
  }