Package io.temporal.testing
Class TestWorkflowExtension.Builder
- java.lang.Object
-
- io.temporal.testing.TestWorkflowExtension.Builder
-
- Enclosing class:
- TestWorkflowExtension
public static class TestWorkflowExtension.Builder extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TestWorkflowExtension
build()
TestWorkflowExtension.Builder
registerSearchAttribute(java.lang.String name, io.temporal.api.enums.v1.IndexedValueType type)
Add a search attribute to be registered on the Temporal Server.TestWorkflowExtension.Builder
setActivityImplementations(java.lang.Object... activityImplementations)
Specify activity implementations to register with the Temporal workerTestWorkflowExtension.Builder
setDoNotStart(boolean doNotStart)
When set to true theTestWorkflowEnvironment.start()
is not called by the extension before executing the test.TestWorkflowExtension.Builder
setInitialTime(java.time.Instant initialTime)
Set the initial time for the workflow virtual clock.TestWorkflowExtension.Builder
setInitialTimeMillis(long initialTimeMillis)
Set the initial time for the workflow virtual clock, milliseconds since epoch.TestWorkflowExtension.Builder
setMetricsScope(com.uber.m3.tally.Scope metricsScope)
Sets the scope to be used for metrics reporting.TestWorkflowExtension.Builder
setNamespace(java.lang.String namespace)
Set Temporal namespace to use for tests, by default,UnitTest
is used.TestWorkflowExtension.Builder
setUseTimeskipping(boolean useTimeskipping)
Sets TestEnvironmentOptions.setUseTimeskippings.TestWorkflowExtension.Builder
setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions)
OverrideWorkerFactoryOptions
for test environment.TestWorkflowExtension.Builder
setWorkerOptions(io.temporal.worker.WorkerOptions options)
TestWorkflowExtension.Builder
setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions)
OverrideWorkflowClientOptions
for test environment.TestWorkflowExtension.Builder
setWorkflowTypes(java.lang.Class<?>... workflowTypes)
Specify workflow implementation types to register with the Temporal worker.TestWorkflowExtension.Builder
useExternalService()
Switches to external Temporal service implementation with default endpoint of127.0.0.1:7233
.TestWorkflowExtension.Builder
useExternalService(java.lang.String target)
Switches to external Temporal service implementation.TestWorkflowExtension.Builder
useInternalService()
Switches to internal in-memory Temporal service implementation (default).
-
-
-
Method Detail
-
setWorkerOptions
public TestWorkflowExtension.Builder setWorkerOptions(io.temporal.worker.WorkerOptions options)
-
setWorkflowClientOptions
public TestWorkflowExtension.Builder setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions)
OverrideWorkflowClientOptions
for test environment. If set, takes precedence overnamespace
.
-
setWorkerFactoryOptions
public TestWorkflowExtension.Builder setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions)
OverrideWorkerFactoryOptions
for test environment.- See Also:
TestEnvironmentOptions.Builder.setWorkerFactoryOptions(WorkerFactoryOptions)
,WorkerFactory.newInstance(WorkflowClient, WorkerFactoryOptions)
-
setNamespace
public TestWorkflowExtension.Builder setNamespace(java.lang.String namespace)
Set Temporal namespace to use for tests, by default,UnitTest
is used.- See Also:
WorkflowClientOptions.getNamespace()
-
setWorkflowTypes
public TestWorkflowExtension.Builder setWorkflowTypes(java.lang.Class<?>... workflowTypes)
Specify workflow implementation types to register with the Temporal worker.- See Also:
Worker.registerWorkflowImplementationTypes(Class[])
-
setActivityImplementations
public TestWorkflowExtension.Builder setActivityImplementations(java.lang.Object... activityImplementations)
Specify activity implementations to register with the Temporal worker- See Also:
Worker.registerActivitiesImplementations(Object...)
-
useExternalService
public TestWorkflowExtension.Builder useExternalService()
Switches to external Temporal service implementation with default endpoint of127.0.0.1:7233
.- See Also:
TestEnvironmentOptions.Builder.setUseExternalService(boolean)
,TestEnvironmentOptions.Builder.setTarget(String)
,WorkflowServiceStubsOptions.Builder.setTarget(String)
-
useExternalService
public TestWorkflowExtension.Builder useExternalService(java.lang.String target)
Switches to external Temporal service implementation.- Parameters:
target
- defines the endpoint which will be used for the communication with standalone Temporal service.- See Also:
TestEnvironmentOptions.Builder.setUseExternalService(boolean)
,TestEnvironmentOptions.Builder.setTarget(String)
,WorkflowServiceStubsOptions.Builder.setTarget(String)
-
useInternalService
public TestWorkflowExtension.Builder useInternalService()
Switches to internal in-memory Temporal service implementation (default).
-
setDoNotStart
public TestWorkflowExtension.Builder setDoNotStart(boolean doNotStart)
When set to true theTestWorkflowEnvironment.start()
is not called by the extension before executing the test. This to support tests that register activities and workflows with workers directly instead of using onlyTestWorkflowExtension.Builder
.
-
setInitialTimeMillis
public TestWorkflowExtension.Builder setInitialTimeMillis(long initialTimeMillis)
Set the initial time for the workflow virtual clock, milliseconds since epoch.Default is current time
-
setInitialTime
public TestWorkflowExtension.Builder setInitialTime(java.time.Instant initialTime)
Set the initial time for the workflow virtual clock.Default is current time
-
setUseTimeskipping
public TestWorkflowExtension.Builder setUseTimeskipping(boolean useTimeskipping)
Sets TestEnvironmentOptions.setUseTimeskippings. If true, no actual wall-clock time will pass when a workflow sleeps or sets a timer.Default is true
-
registerSearchAttribute
public TestWorkflowExtension.Builder registerSearchAttribute(java.lang.String name, io.temporal.api.enums.v1.IndexedValueType type)
Add a search attribute to be registered on the Temporal Server.- Parameters:
name
- name of the search attributetype
- search attribute type- Returns:
this
- See Also:
- Add a Custom Search Attribute Using tctl
-
setMetricsScope
public TestWorkflowExtension.Builder setMetricsScope(com.uber.m3.tally.Scope metricsScope)
Sets the scope to be used for metrics reporting. Optional. Default is to not report metrics.Note: Don't mock
Scope
in tests! If you need to verify the metrics behavior, create a real Scope and mock, stub or spy a reporter instance:
StatsReporter reporter = mock(StatsReporter.class); Scope metricsScope = new RootScopeBuilder() .reporter(reporter) .reportEvery(com.uber.m3.util.Duration.ofMillis(10));
- Parameters:
metricsScope
- the scope to be used for metrics reporting.- Returns:
this
-
build
public TestWorkflowExtension build()
-
-