public VersionedType<T> getVersionedValue() { return delegate.get(); } }
public void update(Integer key, T value) { delegate.update(key, value); }
@Test public void canUpdateForExistingKeys() throws InterruptedException { assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 1L)); supplier.update(2, 100L); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(100L, UNINITIALIZED_VERSION + 2L)); supplier.update(2, 10L); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(10L, UNINITIALIZED_VERSION + 3L)); }
@Before public void setup() { supplier = new AggregatingVersionedSupplier<>( col -> col.stream().max(Comparator.naturalOrder()).orElse(0L), REFRESH_MILLIS); }
@Test public void canUpdateForNewKeys() throws InterruptedException { assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 1L)); supplier.update(1, 1L); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(1L, UNINITIALIZED_VERSION + 2L)); supplier.update(2, 100L); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(100L, UNINITIALIZED_VERSION + 3L)); }
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); }
@Override public T getValue() { return delegate.get().value(); }
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); }
public void update(Integer key, T value) { delegate.update(key, value); }
@Test public void versionUpdatesForGetAfterRefreshMillis() throws InterruptedException { assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 1L)); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 2L)); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 3L)); }
@Test public void versionDoesNotUpdateUntilGetIsCalled() throws InterruptedException { assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 1L)); waitForUpdate(); waitForUpdate(); waitForUpdate(); assertThat(supplier.get()).isEqualTo(VersionedType.of(0L, UNINITIALIZED_VERSION + 2L)); }
public VersionedType<T> getVersionedValue() { return delegate.get(); } }
@Override public T getValue() { return delegate.get().value(); }