Search in sources :

Example 1 with IWorkflowService

use of com.uber.cadence.serviceclient.IWorkflowService in project cadence-client by uber-java.

the class ActivityTestingTest method testCancellationOnNextHeartbeat.

@Test
public void testCancellationOnNextHeartbeat() throws InterruptedException, TException {
    testEnvironment.registerActivitiesImplementations(new CancellationOnNextHeartbeatActivityImpl());
    IWorkflowService workflowService = mock(IWorkflowService.class);
    RecordActivityTaskHeartbeatResponse resp = new RecordActivityTaskHeartbeatResponse();
    resp.setCancelRequested(true);
    when(workflowService.RecordActivityTaskHeartbeat(any())).thenReturn(new RecordActivityTaskHeartbeatResponse()).thenReturn(resp);
    testEnvironment.setWorkflowService(workflowService);
    InterruptibleTestActivity activity = testEnvironment.newActivityStub(InterruptibleTestActivity.class);
    activity.activity1();
}
Also used : IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) Test(org.junit.Test)

Example 2 with IWorkflowService

use of com.uber.cadence.serviceclient.IWorkflowService in project cadence-client by uber-java.

the class TestActivityEnvironmentInternal method setWorkflowService.

@Override
public void setWorkflowService(IWorkflowService workflowService) {
    IWorkflowService service = new WorkflowServiceWrapper(workflowService);
    this.workflowService = service;
    this.activityTaskHandler.setWorkflowService(service);
}
Also used : IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService)

Example 3 with IWorkflowService

use of com.uber.cadence.serviceclient.IWorkflowService in project cadence-client by uber-java.

the class ActivityTestingTest method testHeartbeatCancellation.

@Test
public void testHeartbeatCancellation() throws InterruptedException, TException {
    testEnvironment.registerActivitiesImplementations(new HeartbeatCancellationActivityImpl());
    IWorkflowService workflowService = mock(IWorkflowService.class);
    RecordActivityTaskHeartbeatResponse resp = new RecordActivityTaskHeartbeatResponse();
    resp.setCancelRequested(true);
    when(workflowService.RecordActivityTaskHeartbeat(any())).thenReturn(resp);
    testEnvironment.setWorkflowService(workflowService);
    InterruptibleTestActivity activity = testEnvironment.newActivityStub(InterruptibleTestActivity.class);
    activity.activity1();
}
Also used : IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) Test(org.junit.Test)

Example 4 with IWorkflowService

use of com.uber.cadence.serviceclient.IWorkflowService in project cadence-client by uber-java.

the class ActivityTestingTest method testHeartbeatIntermittentError.

@Test
public void testHeartbeatIntermittentError() throws TException, InterruptedException {
    testEnvironment.registerActivitiesImplementations(new SimpleHeartbeatActivityImpl());
    IWorkflowService workflowService = mock(IWorkflowService.class);
    when(workflowService.RecordActivityTaskHeartbeat(any())).thenThrow(new TException("intermittent error")).thenThrow(new TException("intermittent error")).thenReturn(new RecordActivityTaskHeartbeatResponse());
    testEnvironment.setWorkflowService(workflowService);
    AtomicInteger count = new AtomicInteger();
    testEnvironment.setActivityHeartbeatListener(Void.class, i -> count.incrementAndGet());
    InterruptibleTestActivity activity = testEnvironment.newActivityStub(InterruptibleTestActivity.class);
    activity.activity1();
    assertEquals(3, count.get());
}
Also used : TException(org.apache.thrift.TException) IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) Test(org.junit.Test)

Example 5 with IWorkflowService

use of com.uber.cadence.serviceclient.IWorkflowService in project cadence-client by uber-java.

the class PollDecisionTaskDispatcherTests method aWarningIsLoggedAndDecisionTaskIsFailedWhenNoHandlerIsRegisteredForTheTaskList.

@Test
public void aWarningIsLoggedAndDecisionTaskIsFailedWhenNoHandlerIsRegisteredForTheTaskList() throws Exception {
    // Arrange
    ListAppender<ILoggingEvent> appender = new ListAppender<>();
    appender.setContext(context);
    appender.start();
    logger.addAppender(appender);
    AtomicBoolean handled = new AtomicBoolean(false);
    Consumer<PollForDecisionTaskResponse> handler = r -> handled.set(true);
    IWorkflowService mockService = mock(IWorkflowService.class);
    PollDecisionTaskDispatcher dispatcher = new PollDecisionTaskDispatcher(mockService);
    dispatcher.subscribe("tasklist1", handler);
    // Act
    PollForDecisionTaskResponse response = CreatePollForDecisionTaskResponse("I Don't Exist TaskList");
    dispatcher.process(response);
    // Assert
    verify(mockService, times(1)).RespondDecisionTaskFailed(any());
    assertFalse(handled.get());
    assertEquals(1, appender.list.size());
    ILoggingEvent event = appender.list.get(0);
    assertEquals(Level.WARN, event.getLevel());
    assertEquals(String.format("No handler is subscribed for the PollForDecisionTaskResponse.WorkflowExecutionTaskList %s", "I Don't Exist TaskList"), event.getFormattedMessage());
}
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) IWorkflowService(com.uber.cadence.serviceclient.IWorkflowService) ListAppender(ch.qos.logback.core.read.ListAppender) PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Aggregations

IWorkflowService (com.uber.cadence.serviceclient.IWorkflowService)6 Test (org.junit.Test)4 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)3 TException (org.apache.thrift.TException)2 Level (ch.qos.logback.classic.Level)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 ListAppender (ch.qos.logback.core.read.ListAppender)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 TaskList (com.uber.cadence.TaskList)1 TestWorkflowService (com.uber.cadence.internal.testservice.TestWorkflowService)1 WorkflowServiceTChannel (com.uber.cadence.serviceclient.WorkflowServiceTChannel)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 TestCase (junit.framework.TestCase)1 Matchers.any (org.mockito.Matchers.any)1 Mockito (org.mockito.Mockito)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1