Method temporal.api.workflowservice.v1.WorkflowService/ListWorkflowExecutions is unimplemented when using SDKTestWorkflowRule

Hi! I’m using SDKTestWorkflowRule for workflow unit testing. I want to query the workflows by using the ListWorkflowExecutionsRequest/ListOpenWorkflowExecutionsResponse. I encounter this exception that says WorkflowService/ListWorkflowExecutions is unimplemented.

I tried using ListOpenWorkflowExecutionsRequest and I’m able to get all running/open workflows. The problem of using ListOpenWorkflowExecutionsRequest is I can’t query specific workflow (setQuery method).

What is the cause of the unimplemented method? Any help is much appreciated. Thanks!

SDKTestWorkflowRule is internal, in your tests you should use TestWorkflowRule for JUnit4 tests and can use TestWorkflowExtension for JUnit5.

See for example tests here and here.

Which version of the Java SDK are you using?

Oh, I see. Reason I came up trying to use SDKTestWorkflowRule because I want to check if an event exists in workflow history (i.e., signal event) by using the assertHistoryEvent(WorkflowExecution execution, EventType eventType) method.

Is there an equivalent of that functionality in the TestWorkflowRule/TestWorkflowExtension?

I’m using version 1.10.0 Java SDK.

You can implement this method yourself (and extend it if needed) pretty easily with TestWorkflowRule, for example:

public void assertHistoryEvent(
      TestWorkflowRule testWorkflowRule, WorkflowExecution execution, EventType eventType) {
    History history =
        testWorkflowRule
            .getTestEnvironment()
            .getWorkflowExecutionHistory(
                WorkflowExecution.newBuilder().setWorkflowId("testId").build())
            .getHistory();
    for (HistoryEvent event : history.getEventsList()) {
      if (eventType == event.getEventType()) {
        return;
      }
    }
    fail("No event of " + eventType + " found in the history");
  }

and can call it from within your tests given workflow id (and runid if you have it):

    assertHistoryEvent(
        testWorkflowRule,
        WorkflowExecution.newBuilder().setWorkflowId("testId").build(),
        EventType.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED);

Opened feature request here to have this added out of box in TestWorkflowRule if possible.

You can also get the JSON history for an execution:

testWorkflowRule.getTestEnvironment().getWorkflowExecutionHistory(myExecution).toJson(true);

and even do some complex checks using jq for example as well if needed.