use of com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch 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.telemetry.watch.StageTimeStopwatch 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.telemetry.watch.StageTimeStopwatch 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());
});
}
use of com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch in project abort-mission by nagyesta.
the class LaunchSequenceTemplateTest method testPreLaunchInitCompleteShouldEvaluateMissionAbortConditionsWhenCalled.
@Test
void testPreLaunchInitCompleteShouldEvaluateMissionAbortConditionsWhenCalled() {
// given
final Set<MissionHealthCheckEvaluator> evaluators = addEvaluatorMockWithSpyLogger(new HashSet<>(), false);
final Set<MissionHealthCheckEvaluator> aborting = new HashSet<>();
addEvaluatorMockWithSpyLogger(aborting, true);
addEvaluatorMockWithSpyLogger(aborting, true);
evaluators.addAll(aborting);
final LaunchSequenceTemplate underTest = underTestWithNullFunctions();
// when
underTest.evaluateLaunchAbort(evaluators, new StageTimeStopwatch(getClass()), () -> false);
// then
evaluators.forEach(evaluator -> {
verify(evaluator).shouldAbort();
verify(evaluator, never()).shouldAbortCountdown();
});
aborting.forEach(evaluator -> {
verify(evaluator, never()).countdownLogger();
verify(evaluator).missionLogger();
verifyOnlyIncrementAbortedCalled(evaluator.missionLogger());
});
}
use of com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch in project abort-mission by nagyesta.
the class AbstractMissionTemplate method executeLaunch.
private Optional<T> executeLaunch(final P preparedContext) {
final Optional<StageTimeStopwatch> stopwatch = evaluateLaunchAbort(getClassLevelEvaluatorsOnly(), new StageTimeStopwatch(evaluationScope.getName(), "executeLaunch"), () -> annotationContextEvaluator().isAbortSuppressed(evaluationScope));
try {
final Optional<T> result = doLaunch(preparedContext);
missionCompletedSuccessfully(getClassLevelEvaluatorsOnly(), stopwatch);
return result;
} catch (final Exception e) {
missionFailureDetected(getClassLevelEvaluatorsOnly(), stopwatch, Optional.of(e), annotationContextEvaluator().findSuppressedExceptions(evaluationScope));
throw e;
}
}
Aggregations