Search in sources :

Example 1 with MissionHealthCheckMatcher

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

the class RmiBackedStageStatisticsCollectorIntegrationTest method testLogAndIncrementShouldSaveMeasurementWhenCalledWithValidInput.

@ParameterizedTest
@MethodSource("measurementProvider")
void testLogAndIncrementShouldSaveMeasurementWhenCalledWithValidInput(final List<StageTimeMeasurement> measurements) throws RemoteException {
    // given
    final Registry registry = RmiServiceProvider.lookupRegistry(port);
    final boolean countdown = false;
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER_PREFIX);
    final RmiBackedStageStatisticsCollector underTest = new RmiBackedStageStatisticsCollector(contextName, matcher, registry, countdown);
    // when
    measurements.forEach(underTest::logAndIncrement);
    // then
    verify(matcher, atLeast(measurements.size())).getName();
    final List<RmiStageTimeMeasurement> actual = service.fetchMeasurementsFor(contextName, MATCHER_PREFIX, countdown);
    Collections.sort(actual);
    final List<RmiStageTimeMeasurement> expected = measurements.stream().sorted().map(RmiStageTimeMeasurement::new).collect(Collectors.toList());
    Assertions.assertIterableEquals(expected, actual);
}
Also used : 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 2 with MissionHealthCheckMatcher

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

the class RmiBackedStageStatisticsCollectorTest method testDoLogTimeMeasurementShouldThrowStrongbackExceptionWhenCaughtException.

@Test
void testDoLogTimeMeasurementShouldThrowStrongbackExceptionWhenCaughtException() throws Exception {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER);
    final LaunchStatisticsService service = mock(LaunchStatisticsService.class);
    doThrow(new RemoteException()).when(service).insertStageTimeMeasurement(anyString(), anyString(), anyBoolean(), any(RmiStageTimeMeasurement.class));
    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.doLogTimeMeasurement(CONTEXT, matcher, true, ABORTED));
    // then + exception
    final InOrder inOrder = inOrder(registry, service, matcher);
    inOrder.verify(registry).lookup(eq(RmiServerConstants.SERVICE_NAME));
    inOrder.verify(service).insertStageTimeMeasurement(eq(CONTEXT), eq(MATCHER), eq(true), any(RmiStageTimeMeasurement.class));
    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 3 with MissionHealthCheckMatcher

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

the class H2BackedStageStatisticsCollectorIntegrationTest method testLogAndIncrementShouldSaveMeasurementWhenCalledWithValidInput.

@ParameterizedTest
@MethodSource("measurementProvider")
void testLogAndIncrementShouldSaveMeasurementWhenCalledWithValidInput(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);
    // when
    measurements.forEach(underTest::logAndIncrement);
    // then
    verify(matcher, atLeast(measurements.size())).getName();
    final List<StageTimeMeasurement> actual = jdbi.withExtension(LaunchStatisticsRepository.class, dao -> dao.fetchMeasurementsFor(contextName, MATCHER_PREFIX, countdown));
    Collections.sort(actual);
    Collections.sort(measurements);
    Assertions.assertIterableEquals(measurements, 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)

Example 4 with MissionHealthCheckMatcher

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

the class ExternalStageStatisticsCollectorTest method testGetSnapshotShouldCallDoGetSnapshotWhenCalled.

@Test
void testGetSnapshotShouldCallDoGetSnapshotWhenCalled() {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER);
    final ExternalStageStatisticsCollector underTest = spy(new NoOpExternalStageStatisticsCollector(CONTEXT, matcher, true));
    // when
    underTest.getSnapshot();
    // then
    verify(underTest).getSnapshot();
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with MissionHealthCheckMatcher

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

the class ExternalStageStatisticsCollectorTest method testTimeSeriesStreamShouldCallDoFetchAllWhenCalled.

@Test
void testTimeSeriesStreamShouldCallDoFetchAllWhenCalled() {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    when(matcher.getName()).thenReturn(MATCHER);
    final ExternalStageStatisticsCollector underTest = spy(new NoOpExternalStageStatisticsCollector(CONTEXT, matcher, true));
    // when
    underTest.timeSeriesStream();
    // then
    verify(underTest).doFetchAll(eq(CONTEXT), eq(matcher), eq(true));
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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