Search in sources :

Example 1 with MissionHealthCheckEvaluator

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));
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch)

Example 2 with MissionHealthCheckEvaluator

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);
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch)

Example 3 with MissionHealthCheckEvaluator

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());
    }
}
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) Supplier(java.util.function.Supplier) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with MissionHealthCheckEvaluator

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());
    }
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) 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) Function(java.util.function.Function) 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 5 with MissionHealthCheckEvaluator

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());
    }
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) ValueSource(org.junit.jupiter.params.provider.ValueSource) 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