Client Connection to Temporal Test Server

Hi guys,

I need some help with the testing of Temporal.

What I want to test is the following: I want to start a test workflow, which waits for the change of an unblock condition in order to proceed. The signal for the change works within a test function as expected. But I want to have an integration test. That means that the command for the signal is called out of a Kafka listener, where a new workflow client stub is created in order to send the signal. My problem is, that the workflow client is a Spring Boot Bean, which is connected to the Temporal Service via the address: 127.0.0.1:7233.

The question is: How can I make the workflow client connect to the test server, so I can signal into the test workflow after an API call?

Is that even possible? Or maybe I can configure the testWorkflowExtension in a way that the workflow client can connect to the test server?

BW Maik

You can tell TestWorkflowExtension to use an external Temporal service, for example:

@RegisterExtension
public static final TestWorkflowExtension testWorkflowExtension =
    TestWorkflowExtension.newBuilder()
       // ...
      .useExternalService("127.0.0.1:7233")
      // ...
      .build();

Note if this is set test service will not perform automatic time skipping.

My problem is, that the workflow client is a Spring Boot Bean

Check out the Spring Boot integration that was recently added to the Java SDK. Also demo here.

Ahhh thank you… the new config in the application file is nice. But what is, if Temporal is not available and a worker is started? Currently, I’ve implemented a retry mechanism for the worker start, when the application is started and Temporal is not available. And what if the Application is deployed to a new environment with a new instance of Temporal with no defined default namespace? Does the following line leads in that case to a creation of a default name space?

namespace: default # you can specify a custom namespace that you are using

One more question, Tihomir. The external Service means, that this won’t work in a pipeline because there is no Temporal Service available. So is it possible to have an internal Test Server with the address “127.0.0.1:7233”, which is started automatically when the test environment starts and can be reached by the client bean?

But what is, if Temporal is not available and a worker is started?

If I understand the question correctly, Java SDK (since version 1.11) provides a number of ways to create your WorkflowServiceStubs:
WorkflowServiceStubs#newServiceStubs (does not perform service health check)
WorkflowServiceStubs#newConnectedServiceStubs (if you need to perform health check when client is created)
WorkflowServiceStubsOptions.Builder#setHealthCheckTimeout (if you need to set a specific health check timeout)

And what if the Application is deployed to a new environment with a new instance of Temporal with no defined default namespace?

One thing you could do is check if needed namespace(s) are provisioned, you could use DescribeNamespace api to check if it exists and if not via sdk create it via RegisterNamespace api if you wanted. Just note there is a up to 10s delay period from when a new namespace is registered until you can start workflow executions on it.

Does the following line leads in that case to a creation of a default name space?

No there is not dynamic namespace creation depending on your client config, you have to set that up before or add it yourself as part of your service startup code.

IMO you could just use the SDK test environment for your use case.
As to signaling your executions in test you could set up delayed callback via
testEnv.registerDelayedCallback(...);
to simulate a signal that is sent at any time after workflow execution started. Test workflow environment has automatic time skipping so you could test sending a signal a year after the workflow execution started and your test would run in milliseconds.

For integration tests and using external service, you would have to set up a test cluster and make sure its up before your tests run. One option tho could be to use temporalite and stand it up (with some test configuration) during your integration tests.

IMO you could just use the SDK test environment for your use case.
As to signaling your executions in test you could set up delayed callback via
testEnv.registerDelayedCallback(...);
to simulate a signal that is sent at any time after workflow execution started. Test workflow environment has automatic time skipping so you could test sending a signal a year after the workflow execution started and your test would run in milliseconds.>

Temporalite seems to be a good solution for my use case. Is there a Java version or java examples of temporalite?

BW Maik

Do you mean if you could start temporalite within a Java process? You could try using ProcessBuilder or Runtime.exec to start temporalite binary, or here is small sample if you wanted to build image and deploy it on docker.

In the linked video Hacking Temporal to run on SQLite! [Intro to Temporalite, Jacob LeGrone, Datadog] - YouTube is a Go Libary used to start and configure the server within a test suite. And I was wondering if this exists for Java? As I mentioned I need a solution for our CI pipeline.

Hi tihomir,

is there a java version of the library, where the temporallite server can be created and configured within the test suite? see link Hacking Temporal to run on SQLite! [Intro to Temporalite, Jacob LeGrone, Datadog] - YouTube