Search in sources :

Example 36 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class ExternalStageStatisticsCollectorTest method testLogTimeMeasurementShouldCallDoLogTimeMeasurementWhenCalled.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void testLogTimeMeasurementShouldCallDoLogTimeMeasurementWhenCalled(final boolean countdown) {
    // given
    final StageTimeMeasurement measurement = new StageTimeMeasurement(UUID.randomUUID(), ExternalStageStatisticsCollectorTest.class.getName(), StageTimeMeasurement.CLASS_ONLY, StageResult.SUCCESS, 0, 0);
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER);
    final ExternalStageStatisticsCollector underTest = spy(new NoOpExternalStageStatisticsCollector(CONTEXT, matcher, countdown));
    // when
    underTest.logTimeMeasurement(measurement);
    // then
    verify(underTest).doLogTimeMeasurement(eq(CONTEXT), eq(matcher), eq(countdown), same(measurement));
}
Also used : StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class MissionOutlineDefinition method defineOutline.

@Override
@SuppressWarnings("checkstyle:MagicNumber")
protected Map<String, Consumer<AbortMissionCommandOps>> defineOutline() {
    final DependencyNameExtractor extractor = new TagDependencyNameExtractor();
    final DataSource dataSource = H2DataSourceProvider.createDefaultDataSource(PORT_NUMBER);
    final Map<String, Consumer<AbortMissionCommandOps>> plan = new HashMap<>();
    plan.put(STATIC_FIRE, ops -> {
        final StageStatisticsCollectorFactory factory = getCollectorFactory(STATIC_FIRE, dataSource);
        final MissionHealthCheckMatcher sideBoosterMatcher = matcher().dependencyWith(SIDE_BOOSTER).extractor(extractor).build();
        final MissionHealthCheckMatcher centerCoreMatcher = matcher().dependencyWith(CENTER_CORE).extractor(extractor).build();
        ops.registerHealthCheck(percentageBasedEvaluator(sideBoosterMatcher, factory).abortThreshold(10).burnInTestCount(2).build());
        ops.registerHealthCheck(percentageBasedEvaluator(centerCoreMatcher, factory).build());
    });
    plan.put(PARALLEL, ops -> {
        final StageStatisticsCollectorFactory factory = getCollectorFactory(PARALLEL, dataSource);
        final MissionHealthCheckMatcher anyClassMatcher = matcher().anyClass().build();
        ops.registerHealthCheck(reportOnlyEvaluator(anyClassMatcher, factory).build());
    });
    return plan;
}
Also used : TagDependencyNameExtractor(com.github.nagyesta.abortmission.booster.jupiter.extractor.TagDependencyNameExtractor) DependencyNameExtractor(com.github.nagyesta.abortmission.core.extractor.DependencyNameExtractor) Consumer(java.util.function.Consumer) HashMap(java.util.HashMap) StageStatisticsCollectorFactory(com.github.nagyesta.abortmission.core.healthcheck.StageStatisticsCollectorFactory) H2BackedStageStatisticsCollectorFactory(com.github.nagyesta.abortmission.strongback.h2.stats.H2BackedStageStatisticsCollectorFactory) TagDependencyNameExtractor(com.github.nagyesta.abortmission.booster.jupiter.extractor.TagDependencyNameExtractor) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) DataSource(javax.sql.DataSource)

Example 38 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher 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;
}
Also used : StageStatisticsCollector(com.github.nagyesta.abortmission.core.healthcheck.impl.StageStatisticsCollector) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)

Example 39 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class RmiBackedStageStatisticsCollectorIntegrationTest method testGetSnapshotShouldCountAndGroupMeasurementWhenCalled.

@ParameterizedTest
@MethodSource("measurementProvider")
void testGetSnapshotShouldCountAndGroupMeasurementWhenCalled(final List<StageTimeMeasurement> measurements) throws RemoteException {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    final Registry registry = RmiServiceProvider.lookupRegistry(port);
    when(matcher.getName()).thenReturn(MATCHER_PREFIX);
    final RmiBackedStageStatisticsCollector underTestCountdown = new RmiBackedStageStatisticsCollector(contextName, matcher, registry, true);
    final RmiBackedStageStatisticsCollector underTestMission = new RmiBackedStageStatisticsCollector(contextName, matcher, registry, false);
    for (final StageTimeMeasurement m : measurements) {
        final boolean countdown = m.getTestCaseId().equals(CLASS_ONLY);
        service.insertStageTimeMeasurement(contextName, MATCHER_PREFIX, countdown, new RmiStageTimeMeasurement(m));
    }
    // when
    final StageStatisticsSnapshot actualCountdown = underTestCountdown.getSnapshot();
    final StageStatisticsSnapshot actualMission = underTestMission.getSnapshot();
    // then
    verify(matcher, atLeastOnce()).getName();
    assertSnapshotCountersMatch(measurements, actualCountdown, actualMission);
}
Also used : StageStatisticsSnapshot(com.github.nagyesta.abortmission.core.healthcheck.StageStatisticsSnapshot) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) Registry(java.rmi.registry.Registry) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 40 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class RmiBackedStageStatisticsCollectorIntegrationTest method testFetchAllShouldReturnAllSavedMeasurementsInTheRightOrderWhenCalled.

@ParameterizedTest
@MethodSource("measurementProvider")
void testFetchAllShouldReturnAllSavedMeasurementsInTheRightOrderWhenCalled(final List<StageTimeMeasurement> measurements) throws RemoteException {
    // given
    final boolean countdown = false;
    final Registry registry = RmiServiceProvider.lookupRegistry(port);
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER_PREFIX);
    final RmiBackedStageStatisticsCollector underTest = new RmiBackedStageStatisticsCollector(contextName, matcher, registry, countdown);
    for (final StageTimeMeasurement m : measurements) {
        service.insertStageTimeMeasurement(contextName, MATCHER_PREFIX, countdown, new RmiStageTimeMeasurement(m));
    }
    // when
    final List<StageTimeMeasurement> actual = underTest.doFetchAll(contextName, matcher, countdown);
    // then
    verify(matcher, atLeastOnce()).getName();
    Assertions.assertIterableEquals(measurements.stream().sorted().collect(Collectors.toList()), actual);
}
Also used : StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) Registry(java.rmi.registry.Registry) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

MissionHealthCheckMatcher (com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 MethodSource (org.junit.jupiter.params.provider.MethodSource)21 Test (org.junit.jupiter.api.Test)15 Registry (java.rmi.registry.Registry)7 StageTimeMeasurement (com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement)5 MissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator)4 LaunchStatisticsService (com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService)3 RemoteException (java.rmi.RemoteException)3 NullSource (org.junit.jupiter.params.provider.NullSource)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 InOrder (org.mockito.InOrder)3 TagDependencyNameExtractor (com.github.nagyesta.abortmission.booster.jupiter.extractor.TagDependencyNameExtractor)2 DependencyNameExtractor (com.github.nagyesta.abortmission.core.extractor.DependencyNameExtractor)2 StringDependencyNameExtractor (com.github.nagyesta.abortmission.core.extractor.impl.StringDependencyNameExtractor)2 StageStatisticsCollectorFactory (com.github.nagyesta.abortmission.core.healthcheck.StageStatisticsCollectorFactory)2 StageStatisticsSnapshot (com.github.nagyesta.abortmission.core.healthcheck.StageStatisticsSnapshot)2 MissionStatisticsCollector (com.github.nagyesta.abortmission.core.healthcheck.impl.MissionStatisticsCollector)2 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)2