Class TestWorkflowRule
java.lang.Object
io.temporal.testing.TestWorkflowRule
- All Implemented Interfaces:
org.junit.rules.TestRule
JUnit4
Test rule that sets up test environment, simplifying workflow worker creation and shutdown.
Can be used with both in-memory and standalone temporal service. (see TestWorkflowRule.Builder.setUseExternalService(boolean) and TestWorkflowRule.Builder.setTarget(String)})
Example of usage:
public class MyTest {
@Rule
public TestWorkflowRule workflowRule =
TestWorkflowRule.newBuilder()
.setWorkflowTypes(TestWorkflowImpl.class)
.setActivityImplementations(new TestActivities())
.build();
@Test
public void testMyWorkflow() {
TestWorkflow workflow = workflowRule.getWorkflowClient().newWorkflowStub(
TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(workflowRule.getTaskQueue()).build());
...
}
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runner.Description description) io.temporal.api.workflowservice.v1.WorkflowServiceGrpc.WorkflowServiceBlockingStubprotected TestEnvironmentOptionscreateTestEnvOptions(long initialTimeMillis) io.temporal.client.ActivityClientio.temporal.api.history.v1.HistorygetHistory(io.temporal.api.common.v1.WorkflowExecution execution) Deprecated.<T extends io.temporal.common.interceptors.WorkerInterceptor>
TgetInterceptor(Class<T> type) io.temporal.api.nexus.v1.Endpointio.temporal.worker.WorkerThis worker listens to the default task queue which is obtainable via thegetTaskQueue()method.io.temporal.worker.WorkerFactoryOptionsio.temporal.worker.WorkerOptionsio.temporal.client.WorkflowClientio.temporal.api.history.v1.HistorygetWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution) Deprecated.useWorkflowClient.fetchHistory(String, String).io.temporal.serviceclient.WorkflowServiceStubsbooleanstatic TestWorkflowRule.Builderio.temporal.client.WorkflowStubnewUntypedWorkflowStub(String workflow) <T> TnewWorkflowStub(Class<T> workflow) protected voidshutdown()
-
Method Details
-
createTestEnvOptions
-
newBuilder
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) - Specified by:
applyin interfaceorg.junit.rules.TestRule
-
shutdown
protected void shutdown() -
isUseExternalService
public boolean isUseExternalService()- Returns:
- true if the rule is using external temporal service.
-
getTestEnvironment
-
getTaskQueue
- Returns:
- name of the task queue that test worker is polling.
-
getWorkerOptions
public io.temporal.worker.WorkerOptions getWorkerOptions()- Returns:
- The options used for the worker.
-
getNexusEndpoint
public io.temporal.api.nexus.v1.Endpoint getNexusEndpoint()- Returns:
- endpoint of the nexus service created for the test.
-
getWorkflowClient
public io.temporal.client.WorkflowClient getWorkflowClient()- Returns:
- client to the Temporal service used to start and query workflows.
-
getActivityClient
public io.temporal.client.ActivityClient getActivityClient()- Returns:
- client to the Temporal service used to start standalone activities.
-
getWorkflowServiceStubs
public io.temporal.serviceclient.WorkflowServiceStubs getWorkflowServiceStubs()- Returns:
- stubs connected to the test server (in-memory or external)
-
blockingStub
public io.temporal.api.workflowservice.v1.WorkflowServiceGrpc.WorkflowServiceBlockingStub blockingStub()- Returns:
- blockingStub
-
getInterceptor
public <T extends io.temporal.common.interceptors.WorkerInterceptor> T getInterceptor(Class<T> type) - Returns:
- tracer.
-
getHistory
@Deprecated public io.temporal.api.history.v1.History getHistory(@Nonnull io.temporal.api.common.v1.WorkflowExecution execution) Deprecated.useWorkflowClient.fetchHistory(String, String). To obtain a WorkflowClient usegetWorkflowClient()- Returns:
- workflow execution history
-
getWorkflowExecutionHistory
@Deprecated public io.temporal.api.history.v1.History getWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution) Deprecated.useWorkflowClient.fetchHistory(String, String). To obtain a WorkflowClient usegetWorkflowClient()- Returns:
- name of the task queue that test worker is polling.
-
getWorker
public io.temporal.worker.Worker getWorker()This worker listens to the default task queue which is obtainable via thegetTaskQueue()method.- Returns:
- the default worker created for each test method.
-
getWorkerFactoryOptions
public io.temporal.worker.WorkerFactoryOptions getWorkerFactoryOptions() -
newWorkflowStub
-
newUntypedWorkflowStub
-
getUniquePostfix
- Returns:
- A unique string containing the test name appended to the task queue used by the test worker. Can be used for other test-specific naming.
-
WorkflowClient.fetchHistory(String, String).