Class TestWorkflowRule.Builder
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()registerSearchAttribute(io.temporal.common.SearchAttributeKey<?> key) Add a search attribute to be registered on the Temporal Server.registerSearchAttribute(String name, io.temporal.api.enums.v1.IndexedValueType type) Add a search attribute to be registered on the Temporal Server.setActivityClientOptions(io.temporal.client.ActivityClientOptions activityClientOptions) OverrideActivityClientOptionsfor test environment.setActivityImplementations(Object... activityImplementations) setDoNotSetupNexusEndpoint(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 rule 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) setNexusServiceImplementation(Object... nexusServiceImplementations) Specify Nexus service implementations to register with the Temporal worker.Optional parameter that defines an endpoint which will be used for the communication with standalone temporal service.setTestTimeoutSeconds(long testTimeoutSeconds) Deprecated.Temporal test rule shouldn't be responsible for enforcing test timeouts.setUseExternalService(boolean useExternalService) Switches between in-memory and external temporal service implementations.setUseTimeskipping(boolean useTimeskipping) Sets TestEnvironmentOptions.setUseTimeskippings.setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions options) setWorkerOptions(io.temporal.worker.WorkerOptions options) setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions) OverrideWorkflowClientOptionsfor test environment.voidsetWorkflowServiceStubsOptions(io.temporal.serviceclient.WorkflowServiceStubsOptions workflowServiceStubsOptions) setWorkflowTypes(io.temporal.worker.WorkflowImplementationOptions implementationOptions, Class<?>... workflowTypes) setWorkflowTypes(Class<?>... workflowTypes) Uses 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.
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
setWorkerOptions
-
setWorkflowServiceStubsOptions
public void setWorkflowServiceStubsOptions(io.temporal.serviceclient.WorkflowServiceStubsOptions workflowServiceStubsOptions) -
setWorkflowClientOptions
public TestWorkflowRule.Builder setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions) OverrideWorkflowClientOptionsfor test environment. If set, takes precedence overnamespace. -
setActivityClientOptions
public TestWorkflowRule.Builder setActivityClientOptions(io.temporal.client.ActivityClientOptions activityClientOptions) OverrideActivityClientOptionsfor test environment. -
setWorkerFactoryOptions
public TestWorkflowRule.Builder setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions options) -
setNamespace
-
setWorkflowTypes
-
setWorkflowTypes
public TestWorkflowRule.Builder setWorkflowTypes(io.temporal.worker.WorkflowImplementationOptions implementationOptions, Class<?>... workflowTypes) -
setNexusServiceImplementation
public TestWorkflowRule.Builder setNexusServiceImplementation(Object... nexusServiceImplementations) Specify Nexus service implementations to register with the Temporal worker. If any Nexus services are registered with the worker, the rule 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:
-
setActivityImplementations
-
setUseExternalService
Switches between in-memory and external temporal service implementations.External-service and dev-server modes are mutually exclusive. Calling this method clears any selection made by
useDevServer()oruseDevServer(TemporalDevServerOptions); whichever method is called last determines the service used by the rule.- Parameters:
useExternalService- use external service if true.Default is false.
-
useDevServer
Uses an owned local Temporal dev server instead of the in-memory or external service.The rule closes the server during normal teardown. Dev-server tests do not support time skipping.
Dev-server and external-service modes are mutually exclusive. Calling this method clears any selection made by
setUseExternalService(boolean); whichever method is called last determines the service used by the rule. -
useDevServer
@Experimental public TestWorkflowRule.Builder useDevServer(@Nonnull TemporalDevServerOptions options) Uses an owned local Temporal dev server with the supplied options.Dev-server and external-service modes are mutually exclusive. Calling this method clears any selection made by
setUseExternalService(boolean); whichever method is called last determines the service used by the rule.TestWorkflowRule.newBuilder() .useDevServer( TemporalDevServerOptions.newBuilder().setDownloadVersion("v1.7.2").build()) .setWorkflowTypes(MyWorkflowImpl.class) .build(); -
setUseTimeskipping
Sets TestEnvironmentOptions.setUseTimeskippings. If true, no actual wall-clock time will pass when a workflow sleeps or sets a timer.Default is true
-
setTarget
Optional parameter that defines an endpoint which will be used for the communication with standalone temporal service. Has no effect ifsetUseExternalService(boolean)is set to false.Default is to use 127.0.0.1:7233
-
setTestTimeoutSeconds
Deprecated.Temporal test rule shouldn't be responsible for enforcing test timeouts. Use toolchain of your test framework to enforce timeouts. -
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
-
setDoNotStart
When set to true theTestWorkflowEnvironment.start()is not called by the rule before executing the test. This to support tests that register activities and workflows with workers directly instead of using onlyTestWorkflowRule.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. -
registerSearchAttribute
public TestWorkflowRule.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:
-
registerSearchAttribute
public TestWorkflowRule.Builder registerSearchAttribute(io.temporal.common.SearchAttributeKey<?> key) Add a search attribute to be registered on the Temporal Server.- Parameters:
key- key to register- 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
-