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
}
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());
}
}
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());
}
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;
}
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());
});
}
Aggregations