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();
}
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();
}
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);
}
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());
}
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();
}
Aggregations