Search in sources :

Example 11 with RootScopeBuilder

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);
}
Also used : TestEnvironmentOptions(com.uber.cadence.testing.TestEnvironmentOptions) IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) WorkflowTestingTest(com.uber.cadence.internal.testing.WorkflowTestingTest) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) Before(org.junit.Before)

Example 12 with RootScopeBuilder

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));
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) TestStatsReporter(io.temporal.common.reporter.TestStatsReporter) Before(org.junit.Before)

Example 13 with RootScopeBuilder

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());
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) NoopScope(com.uber.m3.tally.NoopScope) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) PollWorkflowTaskQueueResponse(io.temporal.api.workflowservice.v1.PollWorkflowTaskQueueResponse) NoopScope(com.uber.m3.tally.NoopScope) Scope(com.uber.m3.tally.Scope) CancellationScope(io.temporal.workflow.CancellationScope) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 14 with RootScopeBuilder

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));
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) TestStatsReporter(io.temporal.common.reporter.TestStatsReporter) Before(org.junit.Before)

Example 15 with RootScopeBuilder

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);
}
Also used : TestEnvironmentOptions(io.temporal.testing.TestEnvironmentOptions) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) Scope(com.uber.m3.tally.Scope) TestStatsReporter(io.temporal.common.reporter.TestStatsReporter)

Aggregations

RootScopeBuilder (com.uber.m3.tally.RootScopeBuilder)17 Scope (com.uber.m3.tally.Scope)14 StatsReporter (com.uber.m3.tally.StatsReporter)11 NoopScope (com.uber.cadence.internal.metrics.NoopScope)9 ImmutableMap (com.uber.m3.util.ImmutableMap)9 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)5 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)4 Test (org.junit.Test)4 TestStatsReporter (io.temporal.common.reporter.TestStatsReporter)3 Before (org.junit.Before)3 HttpServer (com.sun.net.httpserver.HttpServer)2 DeciderCache (com.uber.cadence.internal.replay.DeciderCache)2 TestEnvironmentOptions (com.uber.cadence.testing.TestEnvironmentOptions)2 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)2 WorkflowClient (io.temporal.client.WorkflowClient)2 MicrometerClientStatsReporter (io.temporal.common.reporter.MicrometerClientStatsReporter)2 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)2 WorkflowServiceStubsOptions (io.temporal.serviceclient.WorkflowServiceStubsOptions)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2