@Before public void setup() { counter = 0; supplierCounter = 0; mockVersionedSupplier = Mockito.mock(Supplier.class); testSupplier = new CachedComposedSupplier<>(this::countingFunction, mockVersionedSupplier); }
@Test public void recomputesIfSupplierHasNotUpdatedForTooLong() throws InterruptedException { AtomicLong clockCounter = new AtomicLong(); testSupplier = new CachedComposedSupplier<>(this::countingFunction, this::constantNumber, 5, () -> clockCounter.get()); for (int i = 0; i < 25; i++) { clockCounter.incrementAndGet(); testSupplier.get(); } assertThat(counter).isEqualTo(5); }
private MetricsForStrategy(MetricsManager manager, String strategy, Function<Long, Long> tsToMillis, Clock wallClock, long recomputeMillis) { Map<String, String> tag = ImmutableMap.of(AtlasDbMetricNames.TAG_STRATEGY, strategy); this.manager = manager; enqueuedWrites = registerAccumulating(AtlasDbMetricNames.ENQUEUED_WRITES, tag); entriesRead = registerAccumulating(AtlasDbMetricNames.ENTRIES_READ, tag); tombstonesPut = registerAccumulating(AtlasDbMetricNames.TOMBSTONES_PUT, tag); abortedWritesDeleted = registerAccumulating(AtlasDbMetricNames.ABORTED_WRITES_DELETED, tag); sweepTimestamp = register(AtlasDbMetricNames.SWEEP_TS, new CurrentValueMetric<>(), tag); AggregatingVersionedSupplier<Long> lastSweptTsSupplier = new AggregatingVersionedSupplier<>( TargetedSweepMetrics::minimum, recomputeMillis); lastSweptTs = register(AtlasDbMetricNames.LAST_SWEPT_TS, new AggregatingVersionedMetric<>(lastSweptTsSupplier), tag); Supplier<Long> millisSinceLastSweptTs = new CachedComposedSupplier<>( sweptTs -> estimateMillisSinceTs(sweptTs, wallClock, tsToMillis), lastSweptTs::getVersionedValue, recomputeMillis, wallClock); register(AtlasDbMetricNames.LAG_MILLIS, millisSinceLastSweptTs::get, tag); }
private MetricsForStrategy(MetricsManager manager, String strategy, Function<Long, Long> tsToMillis, Clock wallClock, long recomputeMillis) { Map<String, String> tag = ImmutableMap.of(AtlasDbMetricNames.TAG_STRATEGY, strategy); this.manager = manager; enqueuedWrites = registerAccumulating(AtlasDbMetricNames.ENQUEUED_WRITES, tag); entriesRead = registerAccumulating(AtlasDbMetricNames.ENTRIES_READ, tag); tombstonesPut = registerAccumulating(AtlasDbMetricNames.TOMBSTONES_PUT, tag); abortedWritesDeleted = registerAccumulating(AtlasDbMetricNames.ABORTED_WRITES_DELETED, tag); sweepTimestamp = register(AtlasDbMetricNames.SWEEP_TS, new CurrentValueMetric<>(), tag); AggregatingVersionedSupplier<Long> lastSweptTsSupplier = new AggregatingVersionedSupplier<>( TargetedSweepMetrics::minimum, recomputeMillis); lastSweptTs = register(AtlasDbMetricNames.LAST_SWEPT_TS, new AggregatingVersionedMetric<>(lastSweptTsSupplier), tag); Supplier<Long> millisSinceLastSweptTs = new CachedComposedSupplier<>( sweptTs -> estimateMillisSinceTs(sweptTs, wallClock, tsToMillis), lastSweptTs::getVersionedValue, recomputeMillis, wallClock); register(AtlasDbMetricNames.LAG_MILLIS, millisSinceLastSweptTs::get, tag); }