private static StatisticsManagerFactory defaultStatisticsManagerFactory() { return (name, startTime, statsDisabled) -> { if (statsDisabled) { return new DummyStatisticsRegistry(name, startTime); } else { return new StatisticsRegistry(name, startTime); } }; }
@Override public Statistics createAtomicStatistics(StatisticsType type) { return createAtomicStatistics(type, null, 0); }
@Override public Statistics createStatistics(StatisticsType type) { return createOsStatistics(type, null, 0, 0); }
@Override public boolean statisticsExists(long uniqueId) { return anyStatisticsInstance(withUniqueId(uniqueId)) .isPresent(); }
@Override public Statistics[] findStatisticsByType(StatisticsType type) { return allStatisticsInstances(withStatisticsType(type)) .toArray(Statistics[]::new); }
@Override public Statistics[] findStatisticsByNumericId(long numericId) { return allStatisticsInstances(withNumericId(numericId)) .toArray(Statistics[]::new); }
.thenReturn(atomicStatistics3); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); registry.destroyStatistics(osStatistics2); registry.destroyStatistics(atomicStatistics1); assertThat(registry.getStatsList()) .containsExactlyInAnyOrder( atomicStatistics2,
@Test public void incrementsModificationCountOnEachCreationAndDestruction() { Statistics osStatistics = mock(Statistics.class, "os"); Statistics atomicStatistics = mock(Statistics.class, "atomic"); when(osStatisticsFactory.create(any(), any(), anyLong(), anyLong(), anyInt(), any())) .thenReturn(osStatistics); when(atomicStatisticsFactory.create(any(), any(), anyLong(), anyLong(), any())) .thenReturn(atomicStatistics); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); assertThat(registry.getStatListModCount()) .as("modification count after first modification") .isEqualTo(1); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); assertThat(registry.getStatListModCount()) .as("modification count after second modification") .isEqualTo(2); registry.destroyStatistics(osStatistics); assertThat(registry.getStatListModCount()) .as("modification count after third modification") .isEqualTo(3); registry.destroyStatistics(atomicStatistics); assertThat(registry.getStatListModCount()) .as("modification count after fourth modification") .isEqualTo(4); }
.thenReturn(atomicStatistics3); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); assertThat(registry.getStatsList()) .containsExactlyInAnyOrder( atomicStatistics1,
@Test public void incrementsUniqueIdForEachCreatedStatistics() { registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0L, 1, 0, registry); registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 2, 0, registry); registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 3, 0, registry); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, 0); verify(atomicStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 4, registry); registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 5, 0, registry); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, 0); verify(atomicStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 6, registry); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, 0); verify(atomicStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 7, registry); }
@Override public Statistics[] getStatistics() { return getStatsList().toArray(new Statistics[0]); }
@Test public void remembersItsName() { String theName = "the-name"; StatisticsRegistry registry = new StatisticsRegistry(theName, REGISTRY_START_TIME); assertThat(registry.getName()) .isEqualTo(theName); }
@Test public void remembersItsStartTime() { int theStartTime = 374647; StatisticsRegistry registry = new StatisticsRegistry(REGISTRY_NAME, theStartTime); assertThat(registry.getStartTime()) .isEqualTo(theStartTime); }
@Override public Statistics[] findStatisticsByTextId(String textId) { return allStatisticsInstances(withTextId(textId)) .toArray(Statistics[]::new); }
@Test public void delegatesCreateDoubleGaugeToTypeFactory() { StatisticDescriptor descriptorCreatedByFactory = mock(StatisticDescriptor.class); when(typeFactory.createDoubleGauge(any(), any(), any())) .thenReturn(descriptorCreatedByFactory); StatisticDescriptor result = registry.createDoubleGauge(DESCRIPTOR_NAME, DESCRIPTOR_DESCRIPTION, DESCRIPTOR_UNITS); assertThat(result) .isEqualTo(descriptorCreatedByFactory); }
@Test public void delegatesCreateIntGaugeToTypeFactory() { StatisticDescriptor descriptorCreatedByFactory = mock(StatisticDescriptor.class); when(typeFactory.createIntGauge(any(), any(), any())) .thenReturn(descriptorCreatedByFactory); StatisticDescriptor result = registry.createIntGauge(DESCRIPTOR_NAME, DESCRIPTOR_DESCRIPTION, DESCRIPTOR_UNITS); assertThat(result) .isEqualTo(descriptorCreatedByFactory); }
@Test public void delegatesCreateIntCounterToTypeFactory() { StatisticDescriptor descriptorCreatedByFactory = mock(StatisticDescriptor.class); when(typeFactory.createIntCounter(any(), any(), any())) .thenReturn(descriptorCreatedByFactory); StatisticDescriptor result = registry.createIntCounter(DESCRIPTOR_NAME, DESCRIPTOR_DESCRIPTION, DESCRIPTOR_UNITS); assertThat(result) .isEqualTo(descriptorCreatedByFactory); }
@Test public void delegatesCreateDoubleCounterToTypeFactory() { StatisticDescriptor descriptorCreatedByFactory = mock(StatisticDescriptor.class); when(typeFactory.createDoubleCounter(any(), any(), any())) .thenReturn(descriptorCreatedByFactory); StatisticDescriptor result = registry.createDoubleCounter(DESCRIPTOR_NAME, DESCRIPTOR_DESCRIPTION, DESCRIPTOR_UNITS); assertThat(result) .isEqualTo(descriptorCreatedByFactory); }
private Optional<Statistics> anyStatisticsInstance(Predicate<? super Statistics> predicate) { return allStatisticsInstances(predicate).findAny(); }
@Override public int getStatisticsCount() { return getStatsList().size(); }