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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations