@Test public void canHandleMultipleValidMatches() { assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, 1, 2)) .isPresent() .satisfies(optionalLong -> { long value = optionalLong.getAsLong(); assertThat(value).isIn(73L, 75L, 77L, 79L, 81L); }); assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, 0, 2)) .isPresent() .satisfies(optionalLong -> { long value = optionalLong.getAsLong(); assertThat(value).isIn(74L, 76L, 78L, 80L, 82L); }); }
@Test public void doesNotThrowIfMetricsAreAccidentallyRegisteredMultipleTimes() { TimestampTracker.registerTimestampForTracking(mockClock, metricsManager, FAKE_METRIC, () -> 1L); TimestampTracker.registerTimestampForTracking(mockClock, metricsManager, FAKE_METRIC, () -> 2L); // OK // No guarantees on the value, other than that it's one of them assertThat(getGauge(FAKE_METRIC).getValue()).isIn(1L, 2L); }
@Test void size() { put("k", "v"); assertThat(binder.size()).isIn(null, 1L); if (binder.size() != null) { assertThat(registry.get("cache.size") .tag("cache", "mycache") .gauge().value()) .isEqualTo(1); } }
@Test void gets() { put("k", "v"); get("k"); get("does.not.exist"); assertThat(binder.hitCount()).isEqualTo(1); assertThat(registry.get("cache.gets") .tag("result", "hit") .tag("cache", "mycache") .functionCounter().count()) .isEqualTo(1); if (binder.missCount() != null) { // will be 2 for Guava/Caffeine caches where LoadingCache considers a get against a non-existent key a "miss" assertThat(binder.missCount()).isIn(1L, 2L); assertThat(registry.get("cache.gets") .tag("result", "miss") .tag("cache", "mycache") .functionCounter().count()) .isIn(1.0, 2.0); } } }