Search in sources :

Example 11 with StageTimeMeasurement

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());
}
Also used : StageResult(com.github.nagyesta.abortmission.core.telemetry.StageResult) IntStream(java.util.stream.IntStream) java.util(java.util) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) StageLaunchStats(com.github.nagyesta.abortmission.core.telemetry.stats.StageLaunchStats) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) RmiStageTimeMeasurement(com.github.nagyesta.abortmission.strongback.rmi.stats.RmiStageTimeMeasurement) Arguments(org.junit.jupiter.params.provider.Arguments) Registry(java.rmi.registry.Registry) Collectors(java.util.stream.Collectors) TestRunTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.TestRunTelemetry) RemoteException(java.rmi.RemoteException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TestInstance(org.junit.jupiter.api.TestInstance) Stream(java.util.stream.Stream) AbstractInMemoryDataSourceIntegrationTest(com.github.nagyesta.abortmission.strongback.rmi.service.AbstractInMemoryDataSourceIntegrationTest) CLASS_ONLY(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement.CLASS_ONLY) Assertions(org.junit.jupiter.api.Assertions) LaunchStatisticsService(com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService) Tag(org.junit.jupiter.api.Tag) Execution(org.junit.jupiter.api.parallel.Execution) RmiServiceProvider(com.github.nagyesta.abortmission.strongback.rmi.server.RmiServiceProvider) MethodSource(org.junit.jupiter.params.provider.MethodSource) StageResult(com.github.nagyesta.abortmission.core.telemetry.StageResult) Registry(java.rmi.registry.Registry) ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) StageLaunchStats(com.github.nagyesta.abortmission.core.telemetry.stats.StageLaunchStats) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) RmiStageTimeMeasurement(com.github.nagyesta.abortmission.strongback.rmi.stats.RmiStageTimeMeasurement) TestRunTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.TestRunTelemetry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with StageTimeMeasurement

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());
}
Also used : StageResult(com.github.nagyesta.abortmission.core.telemetry.StageResult) IntStream(java.util.stream.IntStream) java.util(java.util) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) StageLaunchStats(com.github.nagyesta.abortmission.core.telemetry.stats.StageLaunchStats) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) TestRunTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.TestRunTelemetry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AbstractInMemoryDataSourceIntegrationTest(com.github.nagyesta.abortmission.strongback.h2.server.AbstractInMemoryDataSourceIntegrationTest) Stream(java.util.stream.Stream) CLASS_ONLY(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement.CLASS_ONLY) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) Execution(org.junit.jupiter.api.parallel.Execution) LaunchStatisticsRepository(com.github.nagyesta.abortmission.strongback.h2.repository.LaunchStatisticsRepository) MethodSource(org.junit.jupiter.params.provider.MethodSource) StageResult(com.github.nagyesta.abortmission.core.telemetry.StageResult) ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) StageLaunchStats(com.github.nagyesta.abortmission.core.telemetry.stats.StageLaunchStats) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) TestRunTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.TestRunTelemetry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with StageTimeMeasurement

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);
}
Also used : java.util(java.util) BaseLaunchTelemetryConverter(com.github.nagyesta.abortmission.core.telemetry.converter.BaseLaunchTelemetryConverter) StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) RmiStageTimeMeasurement(com.github.nagyesta.abortmission.strongback.rmi.stats.RmiStageTimeMeasurement) Registry(java.rmi.registry.Registry) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StrongbackException(com.github.nagyesta.abortmission.strongback.base.StrongbackException) RemoteException(java.rmi.RemoteException) CLASS_ONLY(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement.CLASS_ONLY) LaunchStatisticsService(com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService) ClassTelemetryConverter(com.github.nagyesta.abortmission.core.telemetry.converter.ClassTelemetryConverter) RmiServiceProvider(com.github.nagyesta.abortmission.strongback.rmi.server.RmiServiceProvider) LaunchTelemetryDataSource(com.github.nagyesta.abortmission.core.telemetry.stats.LaunchTelemetryDataSource) LaunchStatisticsService(com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService)

Example 14 with StageTimeMeasurement

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
}
Also used : StageTimeMeasurement(com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AbstractInMemoryDataSourceIntegrationTest(com.github.nagyesta.abortmission.strongback.h2.server.AbstractInMemoryDataSourceIntegrationTest)

Example 15 with StageTimeMeasurement

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

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