Package io.temporal.testing
Class TestWorkflowRule
- java.lang.Object
-
- io.temporal.testing.TestWorkflowRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class TestWorkflowRule extends java.lang.Object implements org.junit.rules.TestRule
JUnit4Test 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)
andTestWorkflowRule.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 Modifier and Type Class Description static class
TestWorkflowRule.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
io.temporal.api.workflowservice.v1.WorkflowServiceGrpc.WorkflowServiceBlockingStub
blockingStub()
protected TestEnvironmentOptions
createTestEnvOptions(long initialTimeMillis)
io.temporal.api.history.v1.History
getHistory(io.temporal.api.common.v1.WorkflowExecution execution)
Deprecated.useWorkflowClient.fetchHistory(String, String)
.<T extends io.temporal.common.interceptors.WorkerInterceptor>
TgetInterceptor(java.lang.Class<T> type)
java.lang.String
getTaskQueue()
TestWorkflowEnvironment
getTestEnvironment()
io.temporal.worker.Worker
getWorker()
This worker listens to the default task queue which is obtainable via thegetTaskQueue()
method.io.temporal.client.WorkflowClient
getWorkflowClient()
io.temporal.api.history.v1.History
getWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution)
Deprecated.useWorkflowClient.fetchHistory(String, String)
.io.temporal.serviceclient.WorkflowServiceStubs
getWorkflowServiceStubs()
boolean
isUseExternalService()
static TestWorkflowRule.Builder
newBuilder()
io.temporal.client.WorkflowStub
newUntypedWorkflowStub(java.lang.String workflow)
<T> T
newWorkflowStub(java.lang.Class<T> workflow)
protected void
shutdown()
-
-
-
Method Detail
-
createTestEnvOptions
protected TestEnvironmentOptions createTestEnvOptions(long initialTimeMillis)
-
newBuilder
public static TestWorkflowRule.Builder newBuilder()
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
shutdown
protected void shutdown()
-
isUseExternalService
public boolean isUseExternalService()
- Returns:
- true if the rule is using external temporal service.
-
getTestEnvironment
public TestWorkflowEnvironment getTestEnvironment()
-
getTaskQueue
public java.lang.String getTaskQueue()
- Returns:
- name of the task queue that test worker is polling.
-
getWorkflowClient
public io.temporal.client.WorkflowClient getWorkflowClient()
- Returns:
- client to the Temporal service used to start and query workflows.
-
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(java.lang.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.
-
newWorkflowStub
public <T> T newWorkflowStub(java.lang.Class<T> workflow)
-
newUntypedWorkflowStub
public io.temporal.client.WorkflowStub newUntypedWorkflowStub(java.lang.String workflow)
-
-