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