Search in sources :

Example 1 with RootScopeBuilder

use of com.uber.m3.tally.RootScopeBuilder in project cadence-client by uber-java.

the class StickyWorkerTest method workflowCacheEvictionDueToThreads.

@Test
public void workflowCacheEvictionDueToThreads() {
    // Arrange
    String taskListName = "workflowCacheEvictionDueToThreads";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).setMaxWorkflowThreadCount(10).setStickyCacheSize(100).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName, WorkerOptions.newBuilder().setMaxConcurrentWorkflowExecutionSize(5).build());
    worker.registerWorkflowImplementationTypes(ActivitiesWorkflowImpl.class);
    worker.registerActivitiesImplementations(new ActivitiesImpl());
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(1)).build();
    int count = 100;
    ActivitiesWorkflow[] workflows = new ActivitiesWorkflow[count];
    WorkflowParams w = new WorkflowParams();
    w.CadenceSleep = Duration.ofSeconds(1);
    w.ChainSequence = 2;
    w.ConcurrentCount = 1;
    w.PayloadSizeBytes = 10;
    w.TaskListName = taskListName;
    for (int i = 0; i < count; i++) {
        ActivitiesWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(ActivitiesWorkflow.class, workflowOptions);
        workflows[i] = workflow;
        WorkflowClient.start(workflow::execute, w);
    }
    for (int i = 0; i < count; i++) {
        workflows[i].execute(w);
    }
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

Example 2 with RootScopeBuilder

use of com.uber.m3.tally.RootScopeBuilder in project cadence-client by uber-java.

the class StickyWorkerTest method whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows.

@Test
public void whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows() throws Exception {
    // Arrange
    String taskListName = "cachedStickyTest_ChildWorkflows";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName);
    worker.registerWorkflowImplementationTypes(GreetingParentWorkflowImpl.class, GreetingChildImpl.class);
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(30)).build();
    GreetingParentWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(GreetingParentWorkflow.class, workflowOptions);
    // Act
    Assert.assertEquals("Hello World!", workflow.getGreeting("World"));
    // Wait for reporter
    Thread.sleep(600);
    // Verify the workflow succeeded without having to recover from a failure
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, DOMAIN).put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG).build();
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
    verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

Example 3 with RootScopeBuilder

use of com.uber.m3.tally.RootScopeBuilder in project cadence-client by uber-java.

the class MetricsTest method setUp.

public void setUp(com.uber.m3.util.Duration reportingFrequecy) {
    reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(reportingFrequecy);
    WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setDomain(WorkflowTest.DOMAIN).setMetricsScope(scope).build();
    TestEnvironmentOptions testOptions = new TestEnvironmentOptions.Builder().setWorkflowClientOptions(clientOptions).build();
    testEnvironment = TestWorkflowEnvironment.newInstance(testOptions);
}
Also used : TestEnvironmentOptions(com.uber.cadence.testing.TestEnvironmentOptions) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) WorkflowClientOptions(com.uber.cadence.client.WorkflowClientOptions) Scope(com.uber.m3.tally.Scope) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) StatsReporter(com.uber.m3.tally.StatsReporter)

Example 4 with RootScopeBuilder

use of com.uber.m3.tally.RootScopeBuilder in project cadence-client by uber-java.

the class ReplayDeciderCacheTests method evictAnyWillInvalidateAnEntryRandomlyFromTheCache.

@Test
public void evictAnyWillInvalidateAnEntryRandomlyFromTheCache() throws Exception {
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, "domain").put(MetricsTag.TASK_LIST, "stickyTaskList").build();
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(Duration.ofMillis(100)).tagged(tags);
    // Arrange
    DeciderCache replayDeciderCache = new DeciderCache(50, scope);
    PollForDecisionTaskResponse decisionTask1 = HistoryUtils.generateDecisionTaskWithInitialHistory();
    PollForDecisionTaskResponse decisionTask2 = HistoryUtils.generateDecisionTaskWithInitialHistory();
    PollForDecisionTaskResponse decisionTask3 = HistoryUtils.generateDecisionTaskWithInitialHistory();
    // Act
    Decider decider = replayDeciderCache.getOrCreate(decisionTask1, () -> createFakeDecider(decisionTask1));
    replayDeciderCache.addToCache(decisionTask1, decider);
    decider = replayDeciderCache.getOrCreate(decisionTask2, () -> createFakeDecider(decisionTask2));
    replayDeciderCache.addToCache(decisionTask2, decider);
    decider = replayDeciderCache.getOrCreate(decisionTask3, () -> createFakeDecider(decisionTask3));
    replayDeciderCache.addToCache(decisionTask3, decider);
    assertEquals(3, replayDeciderCache.size());
    replayDeciderCache.evictAnyNotInProcessing(decisionTask3.workflowExecution.runId);
    // Assert
    assertEquals(2, replayDeciderCache.size());
    // Wait for reporter
    Thread.sleep(600);
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_TOTAL_FORCED_EVICTION), eq(tags), anyInt());
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Test(org.junit.Test)

Example 5 with RootScopeBuilder

use of com.uber.m3.tally.RootScopeBuilder in project cadence-client by uber-java.

the class StickyWorkerTest method whenStickyIsEnabledThenTheWorkflowIsCachedSignals.

@Test
public void whenStickyIsEnabledThenTheWorkflowIsCachedSignals() throws Exception {
    // Arrange
    String taskListName = "cachedStickyTest_Signal";
    StatsReporter reporter = mock(StatsReporter.class);
    Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(com.uber.m3.util.Duration.ofMillis(300));
    WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build();
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(factoryOptions, scope);
    WorkerFactory factory = wrapper.getWorkerFactory();
    Worker worker = factory.newWorker(taskListName);
    worker.registerWorkflowImplementationTypes(GreetingSignalWorkflowImpl.class);
    factory.start();
    WorkflowOptions workflowOptions = new WorkflowOptions.Builder().setTaskList(taskListName).setExecutionStartToCloseTimeout(Duration.ofDays(30)).setTaskStartToCloseTimeout(Duration.ofSeconds(30)).build();
    GreetingSignalWorkflow workflow = wrapper.getWorkflowClient().newWorkflowStub(GreetingSignalWorkflow.class, workflowOptions);
    // Act
    WorkflowClient.start(workflow::getGreeting);
    Thread.sleep(300);
    workflow.waitForName("World");
    String greeting = workflow.getGreeting();
    assertEquals("Hello World!", greeting);
    // Assert
    DeciderCache cache = factory.getCache();
    assertNotNull(cache);
    assertEquals(1, cache.size());
    // Verify the workflow succeeded without having to recover from a failure
    Map<String, String> tags = new ImmutableMap.Builder<String, String>(2).put(MetricsTag.DOMAIN, DOMAIN).put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG).build();
    Thread.sleep(600);
    verify(reporter, atLeastOnce()).reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
    verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
    // Finish Workflow
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) DeciderCache(com.uber.cadence.internal.replay.DeciderCache) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) WorkflowOptions(com.uber.cadence.client.WorkflowOptions)

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