Search in sources :

Example 41 with MissionHealthCheckMatcher

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

the class RmiBackedStageStatisticsCollectorTest method testDoFetchAllShouldThrowStrongbackExceptionWhenCaughtException.

@Test
void testDoFetchAllShouldThrowStrongbackExceptionWhenCaughtException() throws Exception {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER);
    final LaunchStatisticsService service = mock(LaunchStatisticsService.class);
    when(service.fetchMeasurementsFor(anyString(), anyString(), anyBoolean())).thenThrow(new RemoteException());
    final Registry registry = mock(Registry.class);
    when(registry.lookup(eq(RmiServerConstants.SERVICE_NAME))).thenReturn(service);
    final RmiBackedStageStatisticsCollector underTest = new RmiBackedStageStatisticsCollector(CONTEXT, matcher, registry, true);
    // when
    Assertions.assertThrows(StrongbackException.class, () -> underTest.doFetchAll(CONTEXT, matcher, true));
    // then + exception
    final InOrder inOrder = inOrder(registry, service, matcher);
    inOrder.verify(registry).lookup(eq(RmiServerConstants.SERVICE_NAME));
    inOrder.verify(service).fetchMeasurementsFor(eq(CONTEXT), eq(MATCHER), eq(true));
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Registry(java.rmi.registry.Registry) LaunchStatisticsService(com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService) RemoteException(java.rmi.RemoteException) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) Test(org.junit.jupiter.api.Test)

Example 42 with MissionHealthCheckMatcher

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

the class RmiBackedStageStatisticsCollectorTest method testDoGetSnapshotShouldThrowStrongbackExceptionWhenCaughtException.

@Test
void testDoGetSnapshotShouldThrowStrongbackExceptionWhenCaughtException() throws Exception {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER);
    final LaunchStatisticsService service = mock(LaunchStatisticsService.class);
    when(service.getSnapshot(anyString(), anyString(), anyBoolean())).thenThrow(new RemoteException());
    final Registry registry = mock(Registry.class);
    when(registry.lookup(eq(RmiServerConstants.SERVICE_NAME))).thenReturn(service);
    final RmiBackedStageStatisticsCollector underTest = new RmiBackedStageStatisticsCollector(CONTEXT, matcher, registry, true);
    // when
    Assertions.assertThrows(StrongbackException.class, () -> underTest.doGetSnapshot(CONTEXT, matcher, true));
    // then + exception
    final InOrder inOrder = inOrder(registry, service, matcher);
    inOrder.verify(registry).lookup(eq(RmiServerConstants.SERVICE_NAME));
    inOrder.verify(service).getSnapshot(eq(CONTEXT), eq(MATCHER), eq(true));
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Registry(java.rmi.registry.Registry) LaunchStatisticsService(com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService) RemoteException(java.rmi.RemoteException) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) Test(org.junit.jupiter.api.Test)

Example 43 with MissionHealthCheckMatcher

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

the class H2BackedStageStatisticsCollectorIntegrationTest method testGetSnapshotShouldCountAndGroupMeasurementWhenCalled.

@ParameterizedTest
@MethodSource("measurementProvider")
void testGetSnapshotShouldCountAndGroupMeasurementWhenCalled(final List<StageTimeMeasurement> measurements) {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER_PREFIX);
    final H2BackedStageStatisticsCollector underTestCountdown = new H2BackedStageStatisticsCollector(contextName, matcher, dataSource, true);
    final H2BackedStageStatisticsCollector underTestMission = new H2BackedStageStatisticsCollector(contextName, matcher, dataSource, false);
    jdbi.withExtension(LaunchStatisticsRepository.class, dao -> {
        measurements.forEach(m -> {
            final boolean countdown = m.getTestCaseId().equals(CLASS_ONLY);
            dao.insertStageTimeMeasurement(contextName, MATCHER_PREFIX, countdown, m);
        });
        return null;
    });
    // 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) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 44 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 Registry registry = RmiServiceProvider.lookupRegistry(RmiServerConstants.DEFAULT_RMI_PORT);
    final Map<String, Consumer<AbortMissionCommandOps>> plan = new HashMap<>();
    plan.put(STATIC_FIRE, ops -> {
        final StageStatisticsCollectorFactory factory = getCollectorFactory(STATIC_FIRE, registry);
        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, registry);
        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) RmiBackedStageStatisticsCollectorFactory(com.github.nagyesta.abortmission.strongback.rmi.stats.RmiBackedStageStatisticsCollectorFactory) Registry(java.rmi.registry.Registry) TagDependencyNameExtractor(com.github.nagyesta.abortmission.booster.jupiter.extractor.TagDependencyNameExtractor) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)

Example 45 with MissionHealthCheckMatcher

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

the class H2BackedStageStatisticsCollectorIntegrationTest method testFetchAllShouldReturnAllSavedMeasurementsInTheRightOrderWhenCalled.

@ParameterizedTest
@MethodSource("measurementProvider")
void testFetchAllShouldReturnAllSavedMeasurementsInTheRightOrderWhenCalled(final List<StageTimeMeasurement> measurements) {
    // given
    final boolean countdown = false;
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER_PREFIX);
    final H2BackedStageStatisticsCollector underTest = new H2BackedStageStatisticsCollector(contextName, matcher, dataSource, countdown);
    jdbi.withExtension(LaunchStatisticsRepository.class, dao -> {
        measurements.forEach(m -> dao.insertStageTimeMeasurement(contextName, MATCHER_PREFIX, countdown, m));
        return null;
    });
    // 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) 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