Search in sources :

Example 11 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator 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());
    });
}
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)

Example 12 with MissionHealthCheckEvaluator

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

the class LaunchAbortHook method findEvaluators.

private Set<MissionHealthCheckEvaluator> findEvaluators(final Scenario scenario) {
    final Optional<String> context = scenario.getSourceTagNames().stream().filter(tag -> tag.startsWith("@AbortMission_Context_")).map(tag -> tag.replaceFirst("^@AbortMission_Context_", "")).findFirst();
    final AbortMissionCommandOps commandOps = context.map(MissionControl::commandOps).orElse(MissionControl.commandOps());
    return Objects.requireNonNull(commandOps, "Mission context is not found: " + context.orElse("'- DEFAULT - '")).matchingEvaluators(scenario);
}
Also used : MissionOutline(com.github.nagyesta.abortmission.core.outline.MissionOutline) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) java.util(java.util) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) Logger(org.slf4j.Logger) Result(io.cucumber.plugin.event.Result) Scenario(io.cucumber.java.Scenario) LoggerFactory(org.slf4j.LoggerFactory) Status(io.cucumber.plugin.event.Status) ScenarioUriMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher) Field(java.lang.reflect.Field) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch) Consumer(java.util.function.Consumer) MissionControl(com.github.nagyesta.abortmission.core.MissionControl) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ScenarioNameMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps)

Example 13 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project lowkey-vault by nagyesta.

the class MissionOutlineDefinition method defineOutline.

@Override
protected Map<String, Consumer<AbortMissionCommandOps>> defineOutline() {
    return Map.of(SHARED_CONTEXT, ops -> {
        final MissionHealthCheckMatcher integrationTestMatcher = matcher().classNamePattern(".*IntegrationTest").build();
        final MissionHealthCheckEvaluator integrationTests = percentageBasedEvaluator(integrationTestMatcher).build();
        final MissionHealthCheckEvaluator reportOnly = reportOnlyEvaluator(matcher().anyClass().build()).build();
        ops.registerHealthCheck(integrationTests);
        ops.registerHealthCheck(reportOnly);
    });
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)

Example 14 with MissionHealthCheckEvaluator

use of com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator in project lowkey-vault by nagyesta.

the class MissionOutlineDefinition method defineOutline.

@Override
protected Map<String, Consumer<AbortMissionCommandOps>> defineOutline() {
    return Map.of(SHARED_CONTEXT, ops -> {
        final TagDependencyNameExtractor extractor = new TagDependencyNameExtractor();
        Stream.of("Key", "Secret").forEach(type -> {
            final MissionHealthCheckMatcher typeMatcher = matcher().dependencyWith(type).extractor(extractor).build();
            final MissionHealthCheckEvaluator featurePercentage = percentageBasedEvaluator(typeMatcher).abortThreshold(ABORT_THRESHOLD).burnInTestCount(TOTAL_BURN_IN_TEST_COUNT).build();
            ops.registerHealthCheck(featurePercentage);
            Stream.of("Create", "Get", "Delete", "List", "Update", "ListDeleted", "Recover", "Purge", "Backup", "Restore").forEach(subtype -> {
                final MissionHealthCheckMatcher subTypeMatcher = matcher().dependencyWith(type + subtype).extractor(extractor).build();
                final MissionHealthCheckEvaluator subFeaturePercentage = percentageBasedEvaluator(subTypeMatcher).abortThreshold(ABORT_THRESHOLD).burnInTestCount(BURN_IN_TEST_COUNT).build();
                ops.registerHealthCheck(subFeaturePercentage);
            });
        });
        Stream.of("CreateVault", "KeyImport", "KeyEncrypt", "KeySign", "RSA", "EC", "OCT").forEach(tag -> {
            final MissionHealthCheckMatcher matcher = matcher().dependencyWith(tag).extractor(extractor).build();
            final MissionHealthCheckEvaluator tagPercentage = percentageBasedEvaluator(matcher).abortThreshold(ABORT_THRESHOLD).burnInTestCount(BURN_IN_TEST_COUNT).build();
            ops.registerHealthCheck(tagPercentage);
        });
    });
}
Also used : MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) TagDependencyNameExtractor(com.github.nagyesta.abortmission.booster.cucumber.matcher.TagDependencyNameExtractor) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)

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