use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement in project abort-mission by nagyesta.
the class RmiBackedLaunchTelemetryDataSourceIntegrationTest method testFetchClassStatisticsShouldFetchStatisticsGroupedByClassWhenCalled.
@ParameterizedTest
@MethodSource("noCollisionInsertDataProvider")
void testFetchClassStatisticsShouldFetchStatisticsGroupedByClassWhenCalled(final Map<String, List<StageTimeMeasurement>> input) throws RemoteException {
// given
final Registry registry = RmiServiceProvider.lookupRegistry(port);
insertAll(input);
final RmiBackedLaunchTelemetryDataSource underTest = new RmiBackedLaunchTelemetryDataSource(registry);
// when
final SortedMap<String, ClassTelemetry> actual = underTest.fetchClassStatistics();
// then
final Map<String, StageLaunchStats> actualLaunchStatsMap = toLaunches(actual);
final Set<String> actualMethods = new TreeSet<>(actualLaunchStatsMap.keySet());
final List<StageTimeMeasurement> allMeasurements = fetchAllMeasurements();
final List<String> expectedMethods = mapToMethodNames(allMeasurements);
Assertions.assertIterableEquals(expectedMethods, actualMethods);
expectedMethods.forEach(method -> {
final StageLaunchStats actualLaunch = actualLaunchStatsMap.get(method);
final List<TestRunTelemetry> expectedMeasurements = allMeasurements.stream().filter(s -> s.getTestCaseId().equals(method)).map(TestRunTelemetry::new).sorted().collect(Collectors.toList());
Assertions.assertIterableEquals(expectedMeasurements, actualLaunch.getTimeMeasurements());
final Map<StageResult, Integer> actualResultCount = actualLaunch.getStats().getResultCount();
final Map<StageResult, Integer> expectedResultCount = countResults(expectedMeasurements);
Assertions.assertIterableEquals(expectedResultCount.entrySet(), actualResultCount.entrySet());
});
final StageLaunchStats actualCountdown = toCountdown(actual);
final List<TestRunTelemetry> expectedCountdowns = allMeasurements.stream().filter(s -> s.getTestCaseId().equals(CLASS_ONLY)).map(TestRunTelemetry::new).sorted().collect(Collectors.toList());
Assertions.assertIterableEquals(expectedCountdowns, actualCountdown.getTimeMeasurements());
final Map<StageResult, Integer> actualResultCount = actualCountdown.getStats().getResultCount();
final Map<StageResult, Integer> expectedResultCount = countResults(expectedCountdowns);
Assertions.assertIterableEquals(expectedResultCount.entrySet(), actualResultCount.entrySet());
}
use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement in project abort-mission by nagyesta.
the class H2BackedLaunchTelemetryDataSourceIntegrationTest method testFetchClassStatisticsShouldFetchStatisticsGroupedByClassWhenCalled.
@ParameterizedTest
@MethodSource("noCollisionInsertDataProvider")
void testFetchClassStatisticsShouldFetchStatisticsGroupedByClassWhenCalled(final Map<String, List<StageTimeMeasurement>> input) {
// given
jdbi.withExtension(LaunchStatisticsRepository.class, insertAllCallback(input));
final H2BackedLaunchTelemetryDataSource underTest = new H2BackedLaunchTelemetryDataSource(dataSource);
// when
final SortedMap<String, ClassTelemetry> actual = underTest.fetchClassStatistics();
// then
final Map<String, StageLaunchStats> actualLaunchStatsMap = toLaunches(actual);
final Set<String> actualMethods = new TreeSet<>(actualLaunchStatsMap.keySet());
final List<StageTimeMeasurement> allMeasurements = fetchAllMeasurements();
final List<String> expectedMethods = mapToMethodNames(allMeasurements);
Assertions.assertIterableEquals(expectedMethods, actualMethods);
expectedMethods.forEach(method -> {
final StageLaunchStats actualLaunch = actualLaunchStatsMap.get(method);
final List<TestRunTelemetry> expectedMeasurements = allMeasurements.stream().filter(s -> s.getTestCaseId().equals(method)).map(TestRunTelemetry::new).sorted().collect(Collectors.toList());
Assertions.assertIterableEquals(expectedMeasurements, actualLaunch.getTimeMeasurements());
final Map<StageResult, Integer> actualResultCount = actualLaunch.getStats().getResultCount();
final Map<StageResult, Integer> expectedResultCount = countResults(expectedMeasurements);
Assertions.assertIterableEquals(expectedResultCount.entrySet(), actualResultCount.entrySet());
});
final StageLaunchStats actualCountdown = toCountdown(actual);
final List<TestRunTelemetry> expectedCountdowns = allMeasurements.stream().filter(s -> s.getTestCaseId().equals(CLASS_ONLY)).map(TestRunTelemetry::new).sorted().collect(Collectors.toList());
Assertions.assertIterableEquals(expectedCountdowns, actualCountdown.getTimeMeasurements());
final Map<StageResult, Integer> actualResultCount = actualCountdown.getStats().getResultCount();
final Map<StageResult, Integer> expectedResultCount = countResults(expectedCountdowns);
Assertions.assertIterableEquals(expectedResultCount.entrySet(), actualResultCount.entrySet());
}
use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement in project abort-mission by nagyesta.
the class RmiBackedLaunchTelemetryDataSource method doFetchStatistics.
private SortedMap<String, ClassTelemetry> doFetchStatistics() throws RemoteException {
final LaunchStatisticsService service = RmiServiceProvider.service(registry);
final List<String> matcherName = service.fetchAllMatcherNames();
final Map<String, List<StageTimeMeasurement>> measurementsPerMatcher = matcherName.stream().collect(Collectors.toMap(Function.identity(), name -> fetchByMatcherName(service, name)));
return processFetchedRecords(measurementsPerMatcher);
}
use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement in project abort-mission by nagyesta.
the class LaunchStatisticsRepositoryIntegrationTest method testInsertStageTimeMeasurementShouldThrowExceptionWhenCollisionFound.
@Test
void testInsertStageTimeMeasurementShouldThrowExceptionWhenCollisionFound() {
// given
final StageTimeMeasurement measurement = generateMeasurement(1);
jdbi.withExtension(LaunchStatisticsRepository.class, insertSingleMeasurementCallback(MATCHER_PREFIX, measurement));
// when
Assertions.assertThrows(UnableToExecuteStatementException.class, () -> jdbi.withExtension(LaunchStatisticsRepository.class, insertSingleMeasurementCallback(MATCHER_PREFIX, measurement)));
// then exception
}
use of com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement 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);
}
Aggregations