Search in sources :

Example 6 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.

the class AbortMissionCommandOpsTest method testRegisterHealthCheckShouldThrowExceptionWhenCalledTwiceWithTheSame.

@Test
void testRegisterHealthCheckShouldThrowExceptionWhenCalledTwiceWithTheSame() {
    // given
    final AbortMissionCommandOps underTest = AbortMissionCommandOps.newInstance();
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    final MissionHealthCheckEvaluator evaluator = mock(MissionHealthCheckEvaluator.class);
    when(evaluator.getMatcher()).thenReturn(matcher);
    // when
    underTest.registerHealthCheck(evaluator);
    Assertions.assertThrows(IllegalStateException.class, () -> underTest.registerHealthCheck(evaluator));
// then exception
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.

the class SimpleRunnableMissionTemplateSupportTest method testSimpleRunnableShouldLogLifeCycleEventsWhenCalled.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void testSimpleRunnableShouldLogLifeCycleEventsWhenCalled(final boolean fail) {
    // given
    AnnotationContextEvaluator.shared().findAndApplyLaunchPlanDefinition(SimpleRunnableMissionTemplateSupport.class);
    final MissionHealthCheckEvaluator evaluator = getRelevantEvaluator(fail);
    final int countdownStart = evaluator.getCountdownStatistics().getSnapshot().getTotal();
    final int countdownComplete = evaluator.getCountdownStatistics().getSnapshot().getSucceeded();
    final int missionFail = evaluator.getMissionStatistics().getSnapshot().getFailed();
    final int missionSuccess = evaluator.getMissionStatistics().getSnapshot().getSucceeded();
    final SimpleRunnableMissionTemplateSupport underTest = new SimpleRunnableMissionTemplateSupport(MissionOutlineDefinition.SELF_PROPELLED_RUNNABLE + fail, this.getClass(), AbstractMissionTemplateSupportTest::abort) {

        @Override
        public Consumer<Optional<Void>> missionPayloadConsumer() {
            return v -> {
                Assertions.assertEquals(countdownStart + 1, evaluator.getCountdownStatistics().getSnapshot().getTotal());
                Assertions.assertEquals(countdownComplete + 1, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
                Assertions.assertEquals(missionFail, evaluator.getMissionStatistics().getSnapshot().getFailed());
                Assertions.assertEquals(missionSuccess, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
                if (fail) {
                    throw new IllegalStateException();
                }
            };
        }
    };
    // when
    try {
        underTest.run();
    } catch (final IllegalStateException ignore) {
    }
    // then
    Assertions.assertEquals(countdownStart + 1, evaluator.getCountdownStatistics().getSnapshot().getTotal());
    Assertions.assertEquals(countdownComplete + 1, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
    if (fail) {
        Assertions.assertEquals(missionFail + 1, evaluator.getMissionStatistics().getSnapshot().getFailed());
        Assertions.assertEquals(missionSuccess, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
    } else {
        Assertions.assertEquals(missionFail, evaluator.getMissionStatistics().getSnapshot().getFailed());
        Assertions.assertEquals(missionSuccess + 1, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
    }
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) Consumer(java.util.function.Consumer) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AnnotationContextEvaluator(com.github.nagyesta.abortmission.core.annotation.AnnotationContextEvaluator) SuppressAbortDecisions(com.github.nagyesta.abortmission.core.annotation.SuppressAbortDecisions) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Optional(java.util.Optional) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.

the class LaunchTelemetryConverterTest method testProcessClassStatisticsShould.

@Test
void testProcessClassStatisticsShould() {
    // given
    final Map<String, AbortMissionCommandOps> nameSpaces = new HashMap<>();
    final LaunchTelemetryConverter underTest = spy(new LaunchTelemetryConverter());
    final Stream<MissionHealthCheckEvaluator> stream = Stream.<MissionHealthCheckEvaluator>builder().add(new SimpleEvaluator(MATCHER_1, Arrays.asList(FIRST_FAIL_1_10, FIRST_PASS_1_10), Collections.emptyList())).add(new SimpleEvaluator(MATCHER_2, Arrays.asList(FIRST_FAIL_1_10, FIRST_PASS_1_10), Collections.singletonList(SECOND_PASS_2_20))).add(new SimpleEvaluator(MATCHER_3, Collections.emptyList(), Arrays.asList(THIRD_ABORT_5_5, THIRD_PASS_5_5, THIRD_SUPPRESS_5_5))).build();
    doReturn(stream).when(underTest).missionHealthCheckEvaluatorStream(same(nameSpaces));
    // when
    final SortedMap<String, ClassTelemetry> actual = underTest.processClassStatistics(nameSpaces);
    // then
    Assertions.assertNotNull(actual);
    verify(underTest).missionHealthCheckEvaluatorStream(same(nameSpaces));
    Assertions.assertIterableEquals(Collections.singleton(CLASS), actual.keySet());
    final ClassTelemetry classTelemetry = actual.get(CLASS);
    Assertions.assertEquals(CLASS, classTelemetry.getClassName());
    Assertions.assertIterableEquals(Arrays.asList(MATCHER_1, MATCHER_2), classTelemetry.getCountdown().getMatcherNames());
    Assertions.assertIterableEquals(Arrays.asList(MATCHER_2, MATCHER_3), classTelemetry.getLaunches().get(METHOD).getMatcherNames());
}
Also used : ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) AbstractMissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.impl.AbstractMissionHealthCheckEvaluator) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) AbstractTelemetryTest(com.github.nagyesta.abortmission.core.telemetry.stats.AbstractTelemetryTest) Test(org.junit.jupiter.api.Test)

Example 9 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.

the class LaunchSequenceTemplateTest method addEvaluatorMockWithSpyLogger.

private Set<MissionHealthCheckEvaluator> addEvaluatorMockWithSpyLogger(final Set<MissionHealthCheckEvaluator> evaluators, final boolean aborting) {
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    final MissionHealthCheckEvaluator evaluator = mock(MissionHealthCheckEvaluator.class);
    when(evaluator.countdownLogger()).thenReturn(spy(new StageStatisticsCollector(matcher)));
    when(evaluator.missionLogger()).thenReturn(spy(new StageStatisticsCollector(matcher)));
    when(evaluator.shouldAbort()).thenReturn(aborting);
    when(evaluator.shouldAbortCountdown()).thenReturn(aborting);
    evaluators.add(evaluator);
    return evaluators;
}
Also used : StageStatisticsCollector(com.github.nagyesta.abortmission.core.healthcheck.impl.StageStatisticsCollector) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)

Example 10 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.

the class LaunchSequenceTemplateTest method testEvaluateLaunchAbortShouldSuppressAllWhenCalledAndSomeWouldAbort.

@Test
void testEvaluateLaunchAbortShouldSuppressAllWhenCalledAndSomeWouldAbort() {
    // given
    final Set<MissionHealthCheckEvaluator> evaluators = addEvaluatorMockWithSpyLogger(new HashSet<>(), false);
    addEvaluatorMockWithSpyLogger(evaluators, true);
    final LaunchSequenceTemplate underTest = underTestWithNullFunctions();
    // when
    final Optional<StageTimeStopwatch> stopwatch = underTest.evaluateLaunchAbort(evaluators, new StageTimeStopwatch(getClass()), () -> true);
    // then
    Assertions.assertNotNull(stopwatch);
    Assertions.assertFalse(stopwatch.isPresent());
    evaluators.forEach(evaluator -> {
        verify(evaluator).shouldAbort();
        verify(evaluator).missionLogger();
        verifyOnlyIncrementSuppressedCalled(evaluator.missionLogger());
    });
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 MissionHealthCheckMatcher (com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)5 StageTimeStopwatch (com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch)5 Test (org.junit.jupiter.api.Test)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 AnnotationContextEvaluator (com.github.nagyesta.abortmission.core.annotation.AnnotationContextEvaluator)3 SuppressAbortDecisions (com.github.nagyesta.abortmission.core.annotation.SuppressAbortDecisions)3 Consumer (java.util.function.Consumer)3 Assertions (org.junit.jupiter.api.Assertions)3 AbortMissionCommandOps (com.github.nagyesta.abortmission.core.AbortMissionCommandOps)2 Optional (java.util.Optional)2 ScenarioNameMatcher (com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher)1 ScenarioUriMatcher (com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher)1 TagDependencyNameExtractor (com.github.nagyesta.abortmission.booster.cucumber.matcher.TagDependencyNameExtractor)1 MissionControl (com.github.nagyesta.abortmission.core.MissionControl)1 AbstractMissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.impl.AbstractMissionHealthCheckEvaluator)1 StageStatisticsCollector (com.github.nagyesta.abortmission.core.healthcheck.impl.StageStatisticsCollector)1 MissionOutline (com.github.nagyesta.abortmission.core.outline.MissionOutline)1 AbstractTelemetryTest (com.github.nagyesta.abortmission.core.telemetry.stats.AbstractTelemetryTest)1