use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.
the class CucumberLaunchSequenceTemplate method launchImminent.
/**
* Marks completion of the test instance preparation.
*
* @param scenario The test Scenario which is ready for execution.
* @return A stageTimeStopwatch started to measure execution times (won't be present if reporting already happened).
*/
public Optional<StageTimeStopwatch> launchImminent(final Scenario scenario) {
LOGGER.debug("Preparing mission for scenario from URI: {} named: {}", scenario.getUri(), scenario.getName());
final Set<MissionHealthCheckEvaluator> evaluators = scenarioBasedEvaluatorLookup.apply(scenario);
final StageTimeStopwatch countdownStopwatch = new StageTimeStopwatch(scenario.getUri().toString(), StageTimeMeasurement.CLASS_ONLY);
evaluators.forEach(e -> e.countdownLogger().logAndIncrement(countdownStopwatch.stop().apply(StageResult.SUCCESS)));
return evaluateLaunchAbort(evaluators, new StageTimeStopwatch(scenario.getUri().toString(), scenario.getName()), () -> scenario.getSourceTagNames().stream().anyMatch("AbortMission_SuppressAbort"::equalsIgnoreCase));
}
use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.
the class AbstractLaunchSequenceTemplate method performPreLaunchInit.
/**
* Performs pre-launch init steps, like configuring the {@link com.github.nagyesta.abortmission.core.outline.MissionOutline},
* starting the countdown for the matching evaluators and aborting the countdown if needed.
*
* @param testInstanceClass The test class.
* @return A stageTimeStopwatch started to measure execution times (won't be present if reporting already happened).
*/
protected Optional<StageTimeStopwatch> performPreLaunchInit(final Class<?> testInstanceClass) {
annotationContextEvaluator().findAndApplyLaunchPlanDefinition(testInstanceClass);
final StageTimeStopwatch watch = new StageTimeStopwatch(testInstanceClass);
final Set<MissionHealthCheckEvaluator> evaluators = classBasedEvaluatorLookup.apply(testInstanceClass);
final boolean reportingDone = evaluateAndAbortIfNeeded(partitionBy(evaluators, MissionHealthCheckEvaluator::shouldAbortCountdown), annotationContextEvaluator().isAbortSuppressed(testInstanceClass), watch.stop(), MissionHealthCheckEvaluator::countdownLogger);
return emptyIfTrue(reportingDone, watch);
}
use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project abort-mission by nagyesta.
the class RunnableMissionTemplateSupportTest method testSimpleRunnableShouldLogLifeCycleEventsWhenCalled.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void testSimpleRunnableShouldLogLifeCycleEventsWhenCalled(final boolean fail) {
// given
AnnotationContextEvaluator.shared().findAndApplyLaunchPlanDefinition(RunnableMissionTemplateSupportTest.class);
final MissionHealthCheckEvaluator evaluator = getRelevantEvaluator(fail);
final int countdownStart = evaluator.getCountdownStatistics().getSnapshot().getTotal();
final int countdownComplete = evaluator.getCountdownStatistics().getSnapshot().getSucceeded();
final int countdownFail = evaluator.getCountdownStatistics().getSnapshot().getFailed();
final int missionSuccess = evaluator.getMissionStatistics().getSnapshot().getSucceeded();
final RunnableMissionTemplateSupport<Boolean> underTest = new RunnableMissionTemplateSupport<Boolean>(MissionOutlineDefinition.SELF_PROPELLED_RUNNABLE + fail, this.getClass(), AbstractMissionTemplateSupportTest::abort) {
@Override
public Supplier<Boolean> preLaunchPreparationSupplier() {
return () -> {
// no change in advance
Assertions.assertEquals(countdownStart, evaluator.getCountdownStatistics().getSnapshot().getTotal());
Assertions.assertEquals(countdownComplete, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
Assertions.assertEquals(countdownFail, evaluator.getMissionStatistics().getSnapshot().getFailed());
Assertions.assertEquals(missionSuccess, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
if (fail) {
throw new IllegalStateException();
}
return false;
};
}
@Override
public Consumer<Boolean> missionPayloadConsumer() {
return v -> {
};
}
};
// when
try {
underTest.run();
} catch (final IllegalStateException ignore) {
}
// then
Assertions.assertEquals(countdownStart + 1, evaluator.getCountdownStatistics().getSnapshot().getTotal());
if (fail) {
Assertions.assertEquals(countdownComplete, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
Assertions.assertEquals(countdownFail + 1, evaluator.getCountdownStatistics().getSnapshot().getFailed());
Assertions.assertEquals(missionSuccess, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
} else {
Assertions.assertEquals(countdownComplete + 1, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
Assertions.assertEquals(countdownFail, evaluator.getCountdownStatistics().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 SimpleCallableMissionTemplateSupportTest method testSimpleCallableShouldLogLifeCycleEventsWhenCalled.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void testSimpleCallableShouldLogLifeCycleEventsWhenCalled(final boolean fail) {
// given
AnnotationContextEvaluator.shared().findAndApplyLaunchPlanDefinition(SimpleCallableMissionTemplateSupportTest.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 SimpleCallableMissionTemplateSupport<Boolean> underTest = new SimpleCallableMissionTemplateSupport<Boolean>(MissionOutlineDefinition.SELF_PROPELLED_CALLABLE + fail, this.getClass(), AbstractMissionTemplateSupportTest::abort) {
@Override
public Function<Optional<Void>, Boolean> missionPayloadFunction() {
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();
}
return false;
};
}
};
// when
try {
underTest.call();
} catch (final IllegalStateException ignore) {
} catch (final Exception exception) {
Assertions.fail(exception.getMessage());
}
// 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 CallableMissionTemplateSupportTest method testSimpleCallableShouldLogLifeCycleEventsWhenCalled.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void testSimpleCallableShouldLogLifeCycleEventsWhenCalled(final boolean fail) {
// given
AnnotationContextEvaluator.shared().findAndApplyLaunchPlanDefinition(CallableMissionTemplateSupportTest.class);
final MissionHealthCheckEvaluator evaluator = getRelevantEvaluator(fail);
final int countdownStart = evaluator.getCountdownStatistics().getSnapshot().getTotal();
final int countdownComplete = evaluator.getCountdownStatistics().getSnapshot().getSucceeded();
final int countdownFail = evaluator.getCountdownStatistics().getSnapshot().getFailed();
final int missionSuccess = evaluator.getMissionStatistics().getSnapshot().getSucceeded();
final CallableMissionTemplateSupport<Boolean, Boolean> underTest = new CallableMissionTemplateSupport<Boolean, Boolean>(MissionOutlineDefinition.SELF_PROPELLED_CALLABLE + fail, this.getClass(), AbstractMissionTemplateSupportTest::abort) {
@Override
public Supplier<Boolean> preLaunchPreparationSupplier() {
return () -> {
// no change in advance
Assertions.assertEquals(countdownStart, evaluator.getCountdownStatistics().getSnapshot().getTotal());
Assertions.assertEquals(countdownComplete, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
Assertions.assertEquals(countdownFail, evaluator.getMissionStatistics().getSnapshot().getFailed());
Assertions.assertEquals(missionSuccess, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
if (fail) {
throw new IllegalStateException();
}
return false;
};
}
@Override
public Function<Boolean, Boolean> missionPayloadFunction() {
return Function.identity();
}
};
// when
try {
underTest.call();
} catch (final IllegalStateException ignore) {
} catch (final Exception exception) {
Assertions.fail(exception.getMessage());
}
// then
Assertions.assertEquals(countdownStart + 1, evaluator.getCountdownStatistics().getSnapshot().getTotal());
if (fail) {
Assertions.assertEquals(countdownComplete, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
Assertions.assertEquals(countdownFail + 1, evaluator.getCountdownStatistics().getSnapshot().getFailed());
Assertions.assertEquals(missionSuccess, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
} else {
Assertions.assertEquals(countdownComplete + 1, evaluator.getCountdownStatistics().getSnapshot().getSucceeded());
Assertions.assertEquals(countdownFail, evaluator.getCountdownStatistics().getSnapshot().getFailed());
Assertions.assertEquals(missionSuccess + 1, evaluator.getMissionStatistics().getSnapshot().getSucceeded());
}
}
Aggregations