Search in sources :

Example 6 with Buckets

use of com.uber.m3.tally.Buckets in project sdk-java by temporalio.

the class ReplayAwareScopeTest method testCustomClockForTimer.

@Test
public void testCustomClockForTimer() {
    Scope scope = mock(Scope.class);
    Timer timer = mock(Timer.class);
    Histogram histogram = mock(Histogram.class);
    @SuppressWarnings("deprecation") com.uber.m3.tally.Buckets buckets = ValueBuckets.linear(0, 10, 10);
    when(scope.timer("test-timer")).thenReturn(timer);
    when(scope.histogram("test-histogram", buckets)).thenReturn(histogram);
    TestContext context = new TestContext(false);
    TestClock clock = new TestClock();
    clock.setTime(0);
    Scope replayAwareScope = new ReplayAwareScope(scope, context, clock);
    Stopwatch sw = replayAwareScope.timer("test-timer").start();
    clock.setTime(100);
    sw.stop();
    sw = replayAwareScope.histogram("test-histogram", buckets).start();
    clock.setTime(150);
    sw.stop();
    verify(timer, times(1)).record(Duration.ofMillis(100));
    verify(histogram, times(1)).recordDuration(Duration.ofMillis(50));
}
Also used : Histogram(com.uber.m3.tally.Histogram) Scope(com.uber.m3.tally.Scope) Timer(com.uber.m3.tally.Timer) Stopwatch(com.uber.m3.tally.Stopwatch) Test(org.junit.Test)

Aggregations

Histogram (com.uber.m3.tally.Histogram)6 Scope (com.uber.m3.tally.Scope)6 Timer (com.uber.m3.tally.Timer)6 Test (org.junit.Test)6 Counter (com.uber.m3.tally.Counter)4 Gauge (com.uber.m3.tally.Gauge)4 ReplayAwareScope (com.uber.cadence.internal.metrics.ReplayAwareScope)3 Buckets (com.uber.m3.tally.Buckets)3 ValueBuckets (com.uber.m3.tally.ValueBuckets)3 Stopwatch (com.uber.m3.tally.Stopwatch)2