Search in sources :

Example 6 with TestWorkflowService

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

the class PollDecisionTaskDispatcherTests method handlersGetOverwrittenWhenRegisteredForTheSameTaskList.

@Test
public void handlersGetOverwrittenWhenRegisteredForTheSameTaskList() {
    // Arrange
    AtomicBoolean handled = new AtomicBoolean(false);
    AtomicBoolean handled2 = new AtomicBoolean(false);
    Consumer<PollForDecisionTaskResponse> handler = r -> handled.set(true);
    Consumer<PollForDecisionTaskResponse> handler2 = r -> handled2.set(true);
    PollDecisionTaskDispatcher dispatcher = new PollDecisionTaskDispatcher(new TestWorkflowService());
    dispatcher.subscribe("tasklist1", handler);
    dispatcher.subscribe("tasklist1", handler2);
    // Act
    PollForDecisionTaskResponse response = CreatePollForDecisionTaskResponse("tasklist1");
    dispatcher.process(response);
    // Assert
    assertTrue(handled2.get());
    assertFalse(handled.get());
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Logger(org.slf4j.Logger) TaskList(com.uber.cadence.TaskList) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) LoggerContext(ch.qos.logback.classic.LoggerContext) Matchers.any(org.mockito.Matchers.any) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Level(ch.qos.logback.classic.Level) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) TestCase(junit.framework.TestCase) IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) ListAppender(ch.qos.logback.core.read.ListAppender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) Test(org.junit.Test)

Example 7 with TestWorkflowService

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

the class PollDecisionTaskDispatcherTests method pollDecisionTasksAreDispatchedToTheCorrectHandler.

@Test
public void pollDecisionTasksAreDispatchedToTheCorrectHandler() {
    // Arrange
    AtomicBoolean handled = new AtomicBoolean(false);
    AtomicBoolean handled2 = new AtomicBoolean(false);
    Consumer<PollForDecisionTaskResponse> handler = r -> handled.set(true);
    Consumer<PollForDecisionTaskResponse> handler2 = r -> handled2.set(true);
    PollDecisionTaskDispatcher dispatcher = new PollDecisionTaskDispatcher(new TestWorkflowService());
    dispatcher.subscribe("tasklist1", handler);
    dispatcher.subscribe("tasklist2", handler2);
    // Act
    PollForDecisionTaskResponse response = CreatePollForDecisionTaskResponse("tasklist1");
    dispatcher.process(response);
    // Assert
    assertTrue(handled.get());
    assertFalse(handled2.get());
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Logger(org.slf4j.Logger) TaskList(com.uber.cadence.TaskList) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) LoggerContext(ch.qos.logback.classic.LoggerContext) Matchers.any(org.mockito.Matchers.any) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Level(ch.qos.logback.classic.Level) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) TestCase(junit.framework.TestCase) IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) ListAppender(ch.qos.logback.core.read.ListAppender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) Test(org.junit.Test)

Example 8 with TestWorkflowService

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

the class PollDecisionTaskDispatcherTests method pollDecisionTasksAreDispatchedBasedOnTaskListName.

@Test
public void pollDecisionTasksAreDispatchedBasedOnTaskListName() {
    // Arrange
    AtomicBoolean handled = new AtomicBoolean(false);
    Consumer<PollForDecisionTaskResponse> handler = r -> handled.set(true);
    PollDecisionTaskDispatcher dispatcher = new PollDecisionTaskDispatcher(new TestWorkflowService());
    dispatcher.subscribe("tasklist1", handler);
    // Act
    PollForDecisionTaskResponse response = CreatePollForDecisionTaskResponse("tasklist1");
    dispatcher.process(response);
    // Assert
    assertTrue(handled.get());
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Logger(org.slf4j.Logger) TaskList(com.uber.cadence.TaskList) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) LoggerContext(ch.qos.logback.classic.LoggerContext) Matchers.any(org.mockito.Matchers.any) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Level(ch.qos.logback.classic.Level) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) TestCase(junit.framework.TestCase) IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) ListAppender(ch.qos.logback.core.read.ListAppender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) Test(org.junit.Test)

Example 9 with TestWorkflowService

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

the class HistoryUtils method generateDecisionTaskWithInitialHistory.

public static PollForDecisionTaskResponse generateDecisionTaskWithInitialHistory() throws Exception {
    TestWorkflowService service = new TestWorkflowService();
    service.lockTimeSkipping(CALLER);
    return generateDecisionTaskWithInitialHistory(DOMAIN, TASK_LIST, WORKFLOW_TYPE, new TestWorkflowService());
}
Also used : TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService)

Example 10 with TestWorkflowService

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

the class ReplayDeciderCacheTests method whenHistoryIsPartialCachedEntryIsReturned.

@Test(timeout = 2000)
public void whenHistoryIsPartialCachedEntryIsReturned() throws Exception {
    // Arrange
    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(500)).tagged(tags);
    DeciderCache replayDeciderCache = new DeciderCache(10, scope);
    TestWorkflowService service = new TestWorkflowService();
    service.lockTimeSkipping("test");
    PollForDecisionTaskResponse decisionTask = HistoryUtils.generateDecisionTaskWithInitialHistory("domain", "taskList", "workflowType", service);
    Decider decider = replayDeciderCache.getOrCreate(decisionTask, () -> createFakeDecider(decisionTask));
    replayDeciderCache.addToCache(decisionTask, decider);
    // Act
    PollForDecisionTaskResponse decisionTask2 = HistoryUtils.generateDecisionTaskWithPartialHistoryFromExistingTask(decisionTask, "domain", "stickyTaskList", service);
    Decider decider2 = replayDeciderCache.getOrCreate(decisionTask2, () -> doNotCreateFakeDecider(decisionTask2));
    // Assert
    // Wait for reporter
    Thread.sleep(500);
    verify(reporter, times(1)).reportCounter(MetricsType.STICKY_CACHE_HIT, tags, 1);
    assertEquals(decider, decider2);
    service.close();
}
Also used : RootScopeBuilder(com.uber.m3.tally.RootScopeBuilder) Scope(com.uber.m3.tally.Scope) NoopScope(com.uber.cadence.internal.metrics.NoopScope) TestWorkflowService(com.uber.cadence.internal.testservice.TestWorkflowService) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) StatsReporter(com.uber.m3.tally.StatsReporter) ImmutableMap(com.uber.m3.util.ImmutableMap) Test(org.junit.Test)

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