Search in sources :

Example 6 with StageTimeMeasurement

use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement in project abort-mission by nagyesta.

the class ClassTelemetryTest method testConstructorShouldCallConverterWhenCalledWithValidInput.

@Test
void testConstructorShouldCallConverterWhenCalledWithValidInput() {
    // given
    final ClassTelemetryConverter converter = mock(ClassTelemetryConverter.class);
    final Collection<StageTimeMeasurement> measurements = spy(new HashSet<>());
    final Map<String, Set<String>> matcherNames = spy(new HashMap<>());
    final Map<String, List<StageTimeMeasurement>> byMethods = spy(new HashMap<>());
    when(converter.partitionByMethods(same(measurements))).thenReturn(byMethods);
    final StageLaunchStats countdown = new StageLaunchStats(Collections.emptySortedSet(), Collections.emptySet());
    when(converter.processCountdownStats(same(matcherNames), same(byMethods))).thenReturn(countdown);
    final Map<String, StageLaunchStats> methodStats = spy(new HashMap<>());
    when(converter.processLaunchStats(same(matcherNames), same(byMethods))).thenReturn(methodStats);
    when(converter.summarizeDescendantStats(same(countdown), anyCollection())).thenReturn(null);
    // when
    final ClassTelemetry actual = new ClassTelemetry(converter, CLASS, measurements, matcherNames);
    // then
    Assertions.assertNotNull(actual);
    Assertions.assertNull(actual.getStats());
    Assertions.assertSame(countdown, actual.getCountdown());
    Assertions.assertSame(methodStats, actual.getLaunches());
    Assertions.assertSame(CLASS, actual.getClassName());
    final InOrder inOrder = inOrder(converter, methodStats);
    inOrder.verify(converter).partitionByMethods(same(measurements));
    inOrder.verify(converter).processCountdownStats(same(matcherNames), same(byMethods));
    inOrder.verify(converter).processLaunchStats(same(matcherNames), same(byMethods));
    // noinspection ResultOfMethodCallIgnored
    inOrder.verify(methodStats).values();
    inOrder.verify(converter).summarizeDescendantStats(same(countdown), anyCollection());
    inOrder.verifyNoMoreInteractions();
    verifyNoInteractions(byMethods, matcherNames, measurements);
}
Also used : ClassTelemetryConverter(com.github.nagyesta.abortmission.core.telemetry.converter.ClassTelemetryConverter) InOrder(org.mockito.InOrder) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with StageTimeMeasurement

use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement 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 8 with StageTimeMeasurement

use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement 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 9 with StageTimeMeasurement

use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement 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)

Example 10 with StageTimeMeasurement

use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement in project abort-mission by nagyesta.

the class RmiStageTimeMeasurementTest method testConvertToStageTimeMeasurementShouldConvertAllValuableFieldsWhenCalled.

@ParameterizedTest
@MethodSource("measurementProvider")
void testConvertToStageTimeMeasurementShouldConvertAllValuableFieldsWhenCalled(final StageTimeMeasurement expected) {
    // given
    final RmiStageTimeMeasurement underTest = new RmiStageTimeMeasurement(expected);
    // when
    final StageTimeMeasurement actual = underTest.toStageTimeMeasurement();
    // then
    Assertions.assertEquals(expected, actual);
}
Also used : StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

StageTimeMeasurement (com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 MissionHealthCheckMatcher (com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)5 RmiStageTimeMeasurement (com.github.nagyesta.abortmission.strongback.rmi.stats.RmiStageTimeMeasurement)5 Registry (java.rmi.registry.Registry)4 CLASS_ONLY (com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement.CLASS_ONLY)3 ClassTelemetry (com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry)3 LaunchStatisticsService (com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 StageResult (com.github.nagyesta.abortmission.core.telemetry.StageResult)2 ClassTelemetryConverter (com.github.nagyesta.abortmission.core.telemetry.converter.ClassTelemetryConverter)2 StageLaunchStats (com.github.nagyesta.abortmission.core.telemetry.stats.StageLaunchStats)2 TestRunTelemetry (com.github.nagyesta.abortmission.core.telemetry.stats.TestRunTelemetry)2 AbstractInMemoryDataSourceIntegrationTest (com.github.nagyesta.abortmission.strongback.h2.server.AbstractInMemoryDataSourceIntegrationTest)2 RmiServiceProvider (com.github.nagyesta.abortmission.strongback.rmi.server.RmiServiceProvider)2 RemoteException (java.rmi.RemoteException)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2