use of com.uber.m3.tally.Timer in project cadence-client by uber-java.
the class MetricsTest method testWorkflowMetrics.
@Test
public void testWorkflowMetrics() throws InterruptedException {
setUp(com.uber.m3.util.Duration.ofMillis(10));
Worker worker = testEnvironment.newWorker(taskList);
worker.registerWorkflowImplementationTypes(TestMetricsInWorkflow.class, TestMetricsInChildWorkflow.class);
worker.registerActivitiesImplementations(new TestActivityImpl());
testEnvironment.start();
WorkflowClient workflowClient = testEnvironment.newWorkflowClient();
WorkflowOptions options = new WorkflowOptions.Builder().setExecutionStartToCloseTimeout(Duration.ofSeconds(1000)).setTaskList(taskList).build();
TestWorkflow workflow = workflowClient.newWorkflowStub(TestWorkflow.class, options);
workflow.execute();
Thread.sleep(200);
Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, WorkflowTest.DOMAIN).put(MetricsTag.TASK_LIST, taskList).build();
verify(reporter, times(1)).reportCounter("test-started", tags, 1);
verify(reporter, times(1)).reportCounter("test-done", tags, 1);
verify(reporter, times(1)).reportCounter("test-child-started", tags, 1);
verify(reporter, times(1)).reportCounter("test-child-done", tags, 1);
ArgumentCaptor<com.uber.m3.util.Duration> sleepDurationCaptor = ArgumentCaptor.forClass(com.uber.m3.util.Duration.class);
verify(reporter, times(1)).reportTimer(eq("test-timer"), any(), sleepDurationCaptor.capture());
com.uber.m3.util.Duration sleepDuration = sleepDurationCaptor.getValue();
assertTrue(sleepDuration.toString(), sleepDuration.compareTo(com.uber.m3.util.Duration.ofSeconds(3)) >= 0);
assertTrue(sleepDuration.toString(), sleepDuration.compareTo(com.uber.m3.util.Duration.ofMillis(3100)) < 0);
Map<String, String> activityCompletionTags = new ImmutableMap.Builder<String, String>(3).put(MetricsTag.DOMAIN, WorkflowTest.DOMAIN).put(MetricsTag.TASK_LIST, taskList).put(MetricsTag.ACTIVITY_TYPE, "TestActivity::runActivity").put(MetricsTag.WORKFLOW_TYPE, "TestWorkflow::execute").build();
verify(reporter, times(1)).reportCounter("cadence-activity-task-completed", activityCompletionTags, 1);
testEnvironment.close();
}
use of com.uber.m3.tally.Timer in project cadence-client by uber-java.
the class NoopScope method getInstance.
public static synchronized Scope getInstance() {
if (noopScope == null) {
noopCounter = delta -> {
};
noopGauge = value -> {
};
noopTimer = new Timer() {
@Override
public void record(Duration interval) {
}
@Override
public Stopwatch start() {
return new Stopwatch(0, stopwatchStart -> {
});
}
};
noopHistogram = new Histogram() {
@Override
public void recordValue(double value) {
}
@Override
public void recordDuration(Duration value) {
}
@Override
public Stopwatch start() {
return new Stopwatch(0, stopwatchStart -> {
});
}
};
noopScope = new NoopScope();
}
return noopScope;
}
use of com.uber.m3.tally.Timer in project sdk-java by temporalio.
the class ReplayAwareScopeTest method testReplayAwareScopeNotReplaying.
@Test
public void testReplayAwareScopeNotReplaying() {
Scope scope = mock(Scope.class);
Counter counter = mock(Counter.class);
Gauge gauge = mock(Gauge.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.counter("test-counter")).thenReturn(counter);
when(scope.gauge("test-gauge")).thenReturn(gauge);
when(scope.timer("test-timer")).thenReturn(timer);
when(scope.histogram("test-histogram", buckets)).thenReturn(histogram);
TestContext context = new TestContext(false);
Scope replayAwareScope = new ReplayAwareScope(scope, context, System::currentTimeMillis);
replayAwareScope.counter("test-counter").inc(1);
replayAwareScope.gauge("test-gauge").update(100.0);
replayAwareScope.timer("test-timer").record(Duration.ofMillis(100));
replayAwareScope.histogram("test-histogram", buckets).recordValue(10);
replayAwareScope.histogram("test-histogram", buckets).recordDuration(Duration.ofHours(1));
verify(counter, times(1)).inc(1);
verify(gauge, times(1)).update(100.0);
verify(timer, times(1)).record(Duration.ofMillis(100));
verify(histogram, times(1)).recordValue(10);
verify(histogram, times(1)).recordDuration(Duration.ofHours(1));
}
use of com.uber.m3.tally.Timer 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));
}
Aggregations