I want to write a testcase for my workflow method that relies on three other signal methods for completion.
public interface Workflow {
public static final String QUEUE_NAME = "Food_Order";
@WorkflowMethod
String workflowMethod();
@SignalMethod
void signalMethod1();
@SignalMethod
void signalMethod2();
@SignalMethod
void signalMethod3();
}
WorkFlow implementation →
@Override
public String workflowMethod() {
activity.startSomething();
logger.info("***** waiting for first signal method to be called *****");
Workflow.await(() -> firstSignalArrived);
logger.info("***** waiting for second signal method to be called *****");
Workflow.await(() -> secondSignalArrived);
logger.info("*****waiting for third signal method to be called *****");
Workflow.await(() -> thirdSignalArrived);
return "completed";
}
@Override
public void signalMethod1() {
activity.doSomething();
this. firstSignalArrived =true;
}
// similar implementations for other signal methods
Now, I tried to write a test case something like this:
@Rule
public TestWorkflowRule testWorkflowRule = TestWorkflowRule.newBuilder()
.setWorkflowTypes(WorkflowImpl.class)
.build();
@Test
public void testWorkflowWithActivities(){
Workflow workflow = testWorkflowRule
.getWorkflowClient()
.newWorkflowStub(WorkflowImpl.class,
WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build());
testWorkflowRule.getTestEnvironment().registerDelayedCallback(Duration.ofSeconds(2),() -> workflow. signalMethod1());
testWorkflowRule.getTestEnvironment().registerDelayedCallback(Duration.ofSeconds(2),() -> workflow. signalMethod2());
testWorkflowRule.getTestEnvironment().registerDelayedCallback(Duration.ofSeconds(2),() -> workflow. signalMethod3());
testWorkflowRule.getTestEnvironment().start();
// workflow.workflowMethod() should return "completed" and testcase should pass.
Assert.assertNotNull(workflow.workflowMethod());
}
But it is indefinitely waiting on the workflowMethod()
. I’m not sure if I have done registerDelayedCallback
correctly. If not, how to register multiple callbacks to TestWorkflowRule
so that it will get signalled in order
with specified delay
?