Search in sources :

Example 6 with DeciderCache

use of com.uber.cadence.internal.replay.DeciderCache in project cadence-client by uber-java.

the class StickyWorkerTest method whenCacheIsEvictedTheWorkerCanRecover.

@Test
public void whenCacheIsEvictedTheWorkerCanRecover() throws Exception {
    // Arrange
    String taskListName = "evictedStickyTest";
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build(), NoopScope.getInstance());
    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);
    // Wait for workflow to start
    Thread.sleep(200);
    DeciderCache cache = factory.getCache();
    assertNotNull(cache);
    assertEquals(1, cache.size());
    cache.invalidateAll();
    assertEquals(0, cache.size());
    workflow.waitForName("World");
    String greeting = workflow.getGreeting();
    // Assert
    assertEquals("Hello World!", greeting);
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) DeciderCache(com.uber.cadence.internal.replay.DeciderCache)

Example 7 with DeciderCache

use of com.uber.cadence.internal.replay.DeciderCache in project cadence-client by uber-java.

the class StickyWorkerTest method workflowsCanBeQueried.

@Test
public void workflowsCanBeQueried() throws Exception {
    // Arrange
    String taskListName = "queryStickyTest";
    TestEnvironmentWrapper wrapper = new TestEnvironmentWrapper(WorkerFactoryOptions.newBuilder().setDisableStickyExecution(false).build(), NoopScope.getInstance());
    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);
    // Wait for workflow to start
    Thread.sleep(200);
    DeciderCache cache = factory.getCache();
    assertNotNull(cache);
    assertEquals(1, cache.size());
    // Assert
    assertEquals(workflow.getProgress(), GreetingSignalWorkflow.Status.WAITING_FOR_NAME);
    workflow.waitForName("World");
    String greeting = workflow.getGreeting();
    assertEquals("Hello World!", greeting);
    assertEquals(workflow.getProgress(), GreetingSignalWorkflow.Status.GREETING_GENERATED);
    wrapper.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) WorkflowOptions(com.uber.cadence.client.WorkflowOptions) DeciderCache(com.uber.cadence.internal.replay.DeciderCache)

Aggregations

DeciderCache (com.uber.cadence.internal.replay.DeciderCache)7 RootScopeBuilder (com.uber.m3.tally.RootScopeBuilder)6 WorkflowOptions (com.uber.cadence.client.WorkflowOptions)5 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)2 NoopScope (com.uber.cadence.internal.metrics.NoopScope)2 Decider (com.uber.cadence.internal.replay.Decider)2 WorkflowTest (com.uber.cadence.workflow.WorkflowTest)2 Scope (com.uber.m3.tally.Scope)2 StatsReporter (com.uber.m3.tally.StatsReporter)2 ImmutableMap (com.uber.m3.util.ImmutableMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 WorkflowQuery (com.uber.cadence.WorkflowQuery)1 WorkflowType (com.uber.cadence.WorkflowType)1 RetryOptions (com.uber.cadence.common.RetryOptions)1 JsonDataConverter (com.uber.cadence.converter.JsonDataConverter)1 MetricsTag (com.uber.cadence.internal.metrics.MetricsTag)1 MetricsType (com.uber.cadence.internal.metrics.MetricsType)1 DecisionContext (com.uber.cadence.internal.replay.DecisionContext)1