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 TestWorkflowExtensionbuild()TestWorkflowExtension.BuilderregisterSearchAttribute(java.lang.String name, io.temporal.api.enums.v1.IndexedValueType type)Add a search attribute to be registered on the Temporal Server.TestWorkflowExtension.BuildersetActivityImplementations(java.lang.Object... activityImplementations)Specify activity implementations to register with the Temporal workerTestWorkflowExtension.BuildersetDoNotStart(boolean doNotStart)When set to true theTestWorkflowEnvironment.start()is not called by the extension before executing the test.TestWorkflowExtension.BuildersetInitialTime(java.time.Instant initialTime)Set the initial time for the workflow virtual clock.TestWorkflowExtension.BuildersetInitialTimeMillis(long initialTimeMillis)Set the initial time for the workflow virtual clock, milliseconds since epoch.TestWorkflowExtension.BuildersetMetricsScope(com.uber.m3.tally.Scope metricsScope)Sets the scope to be used for metrics reporting.TestWorkflowExtension.BuildersetNamespace(java.lang.String namespace)Set Temporal namespace to use for tests, by default,UnitTestis used.TestWorkflowExtension.BuildersetUseTimeskipping(boolean useTimeskipping)Sets TestEnvironmentOptions.setUseTimeskippings.TestWorkflowExtension.BuildersetWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions)OverrideWorkerFactoryOptionsfor test environment.TestWorkflowExtension.BuildersetWorkerOptions(io.temporal.worker.WorkerOptions options)TestWorkflowExtension.BuildersetWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions)OverrideWorkflowClientOptionsfor test environment.TestWorkflowExtension.BuildersetWorkflowTypes(java.lang.Class<?>... workflowTypes)Specify workflow implementation types to register with the Temporal worker.TestWorkflowExtension.BuilderuseExternalService()Switches to external Temporal service implementation with default endpoint of127.0.0.1:7233.TestWorkflowExtension.BuilderuseExternalService(java.lang.String target)Switches to external Temporal service implementation.TestWorkflowExtension.BuilderuseInternalService()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)
OverrideWorkflowClientOptionsfor test environment. If set, takes precedence overnamespace.
-
setWorkerFactoryOptions
public TestWorkflowExtension.Builder setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions)
OverrideWorkerFactoryOptionsfor 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,UnitTestis 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
Scopein 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()
-
-