Search in sources :

Example 1 with TestWorkflowService

use of com.uber.cadence.internal.testservice.TestWorkflowService in project cadence-client by uber-java.

the class ReplayDeciderCacheTests method whenHistoryIsFullNewReplayDeciderIsReturned_InitiallyCached.

@Test
public void whenHistoryIsFullNewReplayDeciderIsReturned_InitiallyCached() throws Exception {
    TestWorkflowService service = new TestWorkflowService();
    // Arrange
    DeciderCache replayDeciderCache = new DeciderCache(10, NoopScope.getInstance());
    PollForDecisionTaskResponse decisionTask1 = HistoryUtils.generateDecisionTaskWithInitialHistory("domain", "taskList", "workflowType", service);
    Decider decider = replayDeciderCache.getOrCreate(decisionTask1, () -> createFakeDecider(decisionTask1));
    replayDeciderCache.addToCache(decisionTask1, decider);
    PollForDecisionTaskResponse decisionTask2 = HistoryUtils.generateDecisionTaskWithPartialHistoryFromExistingTask(decisionTask1, "domain", "stickyTaskList", service);
    assertEquals(decider, replayDeciderCache.getOrCreate(decisionTask2, () -> doNotCreateFakeDecider(decisionTask2)));
    // Act
    Decider decider2 = replayDeciderCache.getOrCreate(decisionTask2, () -> createFakeDecider(decisionTask2));
    // Assert
    assertEquals(decider2, replayDeciderCache.getOrCreate(decisionTask2, () -> createFakeDecider(decisionTask2)));
    assertSame(decider2, decider);
    service.close();
}
Also used : TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) Test(org.junit.Test)

Example 2 with TestWorkflowService

use of com.uber.cadence.internal.testservice.TestWorkflowService in project cadence-client by uber-java.

the class ReplayDeciderTaskHandlerTests method ifCacheIsEvictedAndPartialHistoryIsReceivedThenTaskFailedIsReturned.

@Test
public void ifCacheIsEvictedAndPartialHistoryIsReceivedThenTaskFailedIsReturned() throws Throwable {
    // Arrange
    DeciderCache cache = new DeciderCache(10, NoopScope.getInstance());
    StickyExecutionAttributes attributes = new StickyExecutionAttributes();
    attributes.setWorkerTaskList(createStickyTaskList("sticky"));
    DecisionTaskHandler taskHandler = new ReplayDecisionTaskHandler("domain", setUpMockWorkflowFactory(), cache, SingleWorkerOptions.newBuilder().build(), "sticky", Duration.ofSeconds(5), new TestWorkflowService(), null);
    // Act
    DecisionTaskHandler.Result result = taskHandler.handleDecisionTask(HistoryUtils.generateDecisionTaskWithPartialHistory());
    // Assert
    assertEquals(0, cache.size());
    assertNull(result.getTaskCompleted());
    assertNotNull(result.getTaskFailed());
}
Also used : StickyExecutionAttributes(com.uber.cadence.StickyExecutionAttributes) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) DecisionTaskHandler(com.uber.cadence.internal.worker.DecisionTaskHandler) Test(org.junit.Test)

Example 3 with TestWorkflowService

use of com.uber.cadence.internal.testservice.TestWorkflowService in project cadence-client by uber-java.

the class HistoryUtils method generateDecisionTaskWithPartialHistory.

public static PollForDecisionTaskResponse generateDecisionTaskWithPartialHistory(String domain, String tasklistName, String workflowType) throws Exception {
    TestWorkflowService service = new TestWorkflowService();
    service.lockTimeSkipping(CALLER);
    PollForDecisionTaskResponse response = generateDecisionTaskWithInitialHistory(domain, tasklistName, workflowType, service);
    return generateDecisionTaskWithPartialHistoryFromExistingTask(response, domain, HOST_TASK_LIST, service);
}
Also used : TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService)

Example 4 with TestWorkflowService

use of com.uber.cadence.internal.testservice.TestWorkflowService in project cadence-client by uber-java.

the class ReplayDeciderTaskHandlerTests method ifStickyExecutionAttributesAreNotSetThenWorkflowsAreNotCached.

@Test
public void ifStickyExecutionAttributesAreNotSetThenWorkflowsAreNotCached() throws Throwable {
    // Arrange
    DeciderCache cache = new DeciderCache(10, NoopScope.getInstance());
    DecisionTaskHandler taskHandler = new ReplayDecisionTaskHandler("domain", setUpMockWorkflowFactory(), cache, SingleWorkerOptions.newBuilder().build(), null, Duration.ofSeconds(5), new TestWorkflowService(), null);
    // Act
    DecisionTaskHandler.Result result = taskHandler.handleDecisionTask(HistoryUtils.generateDecisionTaskWithInitialHistory());
    // Assert
    assertEquals(0, cache.size());
    assertNotNull(result.getTaskCompleted());
    assertNull(result.getTaskCompleted().getStickyAttributes());
}
Also used : TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) DecisionTaskHandler(com.uber.cadence.internal.worker.DecisionTaskHandler) Test(org.junit.Test)

Example 5 with TestWorkflowService

use of com.uber.cadence.internal.testservice.TestWorkflowService in project cadence-client by uber-java.

the class WorkflowStickynessTest method setUp.

@Before
public void setUp() {
    service = new TestWorkflowService();
    service.lockTimeSkipping(CALLER);
}
Also used : TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) Before(org.junit.Before)

Aggregations

TestWorkflowService (com.uber.cadence.internal.testservice.TestWorkflowService)11 Test (org.junit.Test)8 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)6 Level (ch.qos.logback.classic.Level)3 LoggerContext (ch.qos.logback.classic.LoggerContext)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 ListAppender (ch.qos.logback.core.read.ListAppender)3 TaskList (com.uber.cadence.TaskList)3 DecisionTaskHandler (com.uber.cadence.internal.worker.DecisionTaskHandler)3 IWorkflowService (com.uber.cadence.serviceclient.IWorkflowService)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Consumer (java.util.function.Consumer)3 TestCase (junit.framework.TestCase)3 Matchers.any (org.mockito.Matchers.any)3 Mockito (org.mockito.Mockito)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 StickyExecutionAttributes (com.uber.cadence.StickyExecutionAttributes)2 NoopScope (com.uber.cadence.internal.metrics.NoopScope)1 RootScopeBuilder (com.uber.m3.tally.RootScopeBuilder)1