use of com.uber.m3.tally.RootScopeBuilder in project cadence-client by uber-java.
the class ReplayWorkflowActivityTest method init.
@Before
public void init() {
mockServiceClient = mock(IWorkflowService.class);
metricsScope = new RootScopeBuilder().reportEvery(Duration.ofMillis(1000));
TestEnvironmentOptions testOptions = new TestEnvironmentOptions.Builder().setDataConverter(JsonDataConverter.getInstance()).build();
activity = new ReplayWorkflowActivityImpl(mockServiceClient, metricsScope, "test", testOptions);
activity.registerWorkflowImplementationTypes(WorkflowTestingTest.EmptyWorkflowImpl.class);
domain = UUID.randomUUID().toString();
execution = new WorkflowExecution("wid", "rid");
reset();
testEnv = TestActivityEnvironment.newInstance();
testEnv.registerActivitiesImplementations(activity);
activityStub = testEnv.newActivityStub(ReplayWorkflowActivity.class);
}
use of com.uber.m3.tally.RootScopeBuilder in project sdk-java by temporalio.
the class ReplayWorkflowRunTaskHandlerCacheTests method setUp.
@Before
public void setUp() {
reporter = new TestStatsReporter();
metricsScope = new RootScopeBuilder().reporter(reporter).reportEvery(Duration.ofMillis(10));
}
use of com.uber.m3.tally.RootScopeBuilder in project sdk-java by temporalio.
the class DeterministicRunnerTest method workflowThreadsWillEvictCacheWhenMaxThreadCountIsHit.
@Test
public void workflowThreadsWillEvictCacheWhenMaxThreadCountIsHit() throws Throwable {
// Arrange
// Arrange
Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.NAMESPACE, "namespace").put(MetricsTag.TASK_QUEUE, "stickyTaskQueue").build();
StatsReporter reporter = mock(StatsReporter.class);
Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300)).tagged(tags);
ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 3, 1, TimeUnit.SECONDS, new SynchronousQueue<>());
AtomicReference<String> status = new AtomicReference<>();
WorkflowExecutorCache cache = new WorkflowExecutorCache(3, scope);
ReplayWorkflowContext replayWorkflowContext = mock(ReplayWorkflowContext.class);
when(replayWorkflowContext.getMetricsScope()).thenReturn(scope);
when(replayWorkflowContext.getWorkflowExecution()).thenReturn(WorkflowExecution.newBuilder().setWorkflowId("id1").setRunId("run1").build());
when(replayWorkflowContext.getNamespace()).thenReturn("namespace");
when(replayWorkflowContext.getWorkflowType()).thenReturn(WorkflowType.getDefaultInstance());
DeterministicRunnerImpl d = new DeterministicRunnerImpl(threadPool, new SyncWorkflowContext(replayWorkflowContext, DataConverter.getDefaultInstance(), null, null, null), () -> {
Promise<Void> thread = Async.procedure(() -> {
status.set("started");
WorkflowThread.await("doing something", () -> false);
status.set("done");
});
thread.get();
}, cache);
WorkflowRunTaskHandler workflowRunTaskHandler = new DeterministicRunnerTestWorkflowRunTaskHandler(d);
PollWorkflowTaskQueueResponse response = HistoryUtils.generateWorkflowTaskWithInitialHistory();
cache.getOrCreate(response, new com.uber.m3.tally.NoopScope(), () -> workflowRunTaskHandler);
cache.addToCache(response.getWorkflowExecution(), workflowRunTaskHandler);
d.runUntilAllBlocked(DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT_MS);
assertEquals(2, threadPool.getActiveCount());
assertEquals(1, cache.size());
DeterministicRunnerImpl d2 = new DeterministicRunnerImpl(threadPool, new SyncWorkflowContext(replayWorkflowContext, DataConverter.getDefaultInstance(), null, null, null), () -> {
Promise<Void> thread = Async.procedure(() -> {
status.set("started");
WorkflowThread.await("doing something else", () -> false);
status.set("done");
});
thread.get();
}, cache);
// Act: This should kick out threads consumed by 'd'
d2.runUntilAllBlocked(DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT_MS);
// Assert: Cache is evicted and only threads consumed by d2 remain.
assertEquals(2, threadPool.getActiveCount());
// cache was evicted
assertEquals(0, cache.size());
// Wait for reporter
Thread.sleep(600);
verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_THREAD_FORCED_EVICTION), eq(tags), anyLong());
}
use of com.uber.m3.tally.RootScopeBuilder in project sdk-java by temporalio.
the class StickyWorkerTest method setUp.
// TODO(maxim): refactor all of this ugliness into a service based implementation of
// TestWorkflowEnvironment
@Before
public void setUp() {
reporter = new TestStatsReporter();
metricsScope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofSeconds(10));
}
use of com.uber.m3.tally.RootScopeBuilder in project sdk-java by temporalio.
the class MetricsTest method setUp.
public void setUp(WorkerFactoryOptions workerFactoryOptions) {
Scope metricsScope;
reporter = new TestStatsReporter();
metricsScope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(10));
TestEnvironmentOptions testOptions = TestEnvironmentOptions.newBuilder().setMetricsScope(metricsScope).setWorkflowClientOptions(WorkflowClientOptions.newBuilder().setNamespace(NAMESPACE).build()).setWorkerFactoryOptions(workerFactoryOptions).build();
testEnvironment = TestWorkflowEnvironment.newInstance(testOptions);
}
Aggregations