Class TestWorkflowExtension.Builder
java.lang.Object
io.temporal.testing.TestWorkflowExtension.Builder
- Enclosing class:
TestWorkflowExtension
-
Method Summary
Modifier and TypeMethodDescriptionbuild()registerSearchAttribute(String name, io.temporal.api.enums.v1.IndexedValueType type) Add a search attribute to be registered on the Temporal Server.registerWorkflowImplementationTypes(io.temporal.worker.WorkflowImplementationOptions options, Class<?>... workflowTypes) Specify workflow implementation types to register with the Temporal worker.registerWorkflowImplementationTypes(Class<?>... workflowTypes) Specify workflow implementation types to register with the Temporal worker.setActivityClientOptions(io.temporal.client.ActivityClientOptions activityClientOptions) OverrideActivityClientOptionsfor test environment.setActivityImplementations(Object... activityImplementations) Specify activity implementations to register with the Temporal workersetDoNotSetupNexusEndpoint(boolean doNotSetupNexusEndpoint) When set to true theTestWorkflowEnvironmentwill not automatically create a Nexus Endpoint.setDoNotStart(boolean doNotStart) When set to true theTestWorkflowEnvironment.start()is not called by the extension before executing the test.setInitialTime(Instant initialTime) Set the initial time for the workflow virtual clock.setInitialTimeMillis(long initialTimeMillis) Set the initial time for the workflow virtual clock, milliseconds since epoch.setMetricsScope(com.uber.m3.tally.Scope metricsScope) Sets the scope to be used for metrics reporting.setNamespace(String namespace) Set Temporal namespace to use for tests, by default,UnitTestis used.setNexusServiceImplementation(Object... nexusServiceImplementations) Specify Nexus service implementations to register with the Temporal workerIf any Nexus services are registered with the worker, the extension will automatically create a Nexus Endpoint for the test and the endpoint will be set on the per-service options and default options inWorkflowImplementationOptionsif none are provided.setUseTimeskipping(boolean useTimeskipping) Sets TestEnvironmentOptions.setUseTimeskippings.setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions) OverrideWorkerFactoryOptionsfor test environment.setWorkerOptions(io.temporal.worker.WorkerOptions options) setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions) OverrideWorkflowClientOptionsfor test environment.setWorkflowTypes(Class<?>... workflowTypes) Deprecated.use registerWorkflowImplementationTypes insteadUses an owned local Temporal dev server instead of the in-memory or external service.useDevServer(TemporalDevServerOptions options) Uses an owned local Temporal dev server with the supplied options.Switches to external Temporal service implementation with default endpoint of127.0.0.1:7233.useExternalService(String target) Switches to external Temporal service implementation.Switches to internal in-memory Temporal service implementation (default).
-
Method Details
-
setWorkerOptions
- See Also:
-
setWorkflowClientOptions
public TestWorkflowExtension.Builder setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions) OverrideWorkflowClientOptionsfor test environment. If set, takes precedence overnamespace. -
setActivityClientOptions
public TestWorkflowExtension.Builder setActivityClientOptions(io.temporal.client.ActivityClientOptions activityClientOptions) OverrideActivityClientOptionsfor test environment. -
setWorkerFactoryOptions
public TestWorkflowExtension.Builder setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions) OverrideWorkerFactoryOptionsfor test environment.- See Also:
-
setNamespace
Set Temporal namespace to use for tests, by default,UnitTestis used.- See Also:
-
registerWorkflowImplementationTypes
Specify workflow implementation types to register with the Temporal worker.- See Also:
-
registerWorkflowImplementationTypes
public TestWorkflowExtension.Builder registerWorkflowImplementationTypes(io.temporal.worker.WorkflowImplementationOptions options, Class<?>... workflowTypes) Specify workflow implementation types to register with the Temporal worker.- See Also:
-
setNexusServiceImplementation
public TestWorkflowExtension.Builder setNexusServiceImplementation(Object... nexusServiceImplementations) Specify Nexus service implementations to register with the Temporal workerIf any Nexus services are registered with the worker, the extension will automatically create a Nexus Endpoint for the test and the endpoint will be set on the per-service options and default options inWorkflowImplementationOptionsif none are provided.This can be disabled by setting
setDoNotSetupNexusEndpoint(boolean)to true.- See Also:
-
setWorkflowTypes
Deprecated.use registerWorkflowImplementationTypes insteadSpecify workflow implementation types to register with the Temporal worker.- See Also:
-
setActivityImplementations
Specify activity implementations to register with the Temporal worker- See Also:
-
useExternalService
Switches to external Temporal service implementation with default endpoint of127.0.0.1:7233.- See Also:
-
useExternalService
Switches to external Temporal service implementation.- Parameters:
target- defines the endpoint which will be used for the communication with standalone Temporal service.- See Also:
-
useDevServer
Uses an owned local Temporal dev server instead of the in-memory or external service.The extension closes the server after each test. Dev-server tests do not support time skipping.
-
useDevServer
@Experimental public TestWorkflowExtension.Builder useDevServer(@Nonnull TemporalDevServerOptions options) Uses an owned local Temporal dev server with the supplied options.TestWorkflowExtension.newBuilder() .useDevServer(TemporalDevServerOptions.newBuilder().setUiEnabled(true).build()) .setWorkflowTypes(MyWorkflowImpl.class) .build(); -
useInternalService
Switches to internal in-memory Temporal service implementation (default). -
setDoNotStart
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. -
setDoNotSetupNexusEndpoint
When set to true theTestWorkflowEnvironmentwill not automatically create a Nexus Endpoint. This is useful when you want to manually create a Nexus Endpoint for your test. -
setInitialTimeMillis
Set the initial time for the workflow virtual clock, milliseconds since epoch.Default is current time
-
setInitialTime
Set the initial time for the workflow virtual clock.Default is current time
-
setUseTimeskipping
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(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:
-
setMetricsScope
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
-