I have a workflow that has 4 activities basically. 2 Of them are local where as the other 2 are remote micro services.
So if I have to write Junits for the activity implementation in the micro services, how do I do it?
My remote activity implementation is as below:
public Class CalculationActivityImpl implements CalculationActivity {
String determineParameters(Long runId, String filePath) {
... do some stuff
ActivityInfo activityInfo = Activity.getExecutionContext().getInfo();
WorkflowStub runWorkflow = workflowClient.newUntypedWorkflowStub(
activityInfo.getWorkflowId(),
Optional.of(activityInfo.getRunId()), Optional.of(activityInfo.getWorkflowType()));
runWorkflow.signal("signalCalculationDone");
}
return "done";
}
So here am using UntypedWorkflowStub to signal workflow. I went through multiple samples in sdk-java but hardly I could find references on how to unit test remotely hosted activities.
For now I could only come up with this by referring to TestActivityEnvironment Javadocs.
@Test
public void testCalculation() {
TestActivityEnvironment testActivityEnv = TestActivityEnvironment.newInstance();
testActivityEnv.registerActivitiesImplementations(new CalculationActivityImpl());
CalculationActivity activity = testActivityEnv.newActivityStub(CalculationActivity.class);
String output = activity.determineParameters(1L, "/CalculationResults");
assertEquals("done", output);
}
But this is failing with ERROR TestActivityEnvironmentInternal: Timeout trying execute activity task task_token: “test-task-token”. Apparently, it’s getting timed out. Without workflow context, is it really possible to unit test activities?
Any references or pointers would be much appreciated.