Class TestWorkflowRule.Builder

java.lang.Object
io.temporal.testing.TestWorkflowRule.Builder
Enclosing class:
TestWorkflowRule

public static class TestWorkflowRule.Builder extends Object
  • Constructor Details

    • Builder

      protected Builder()
  • Method Details

    • setWorkerOptions

      public TestWorkflowRule.Builder setWorkerOptions(io.temporal.worker.WorkerOptions options)
    • setWorkflowServiceStubsOptions

      public void setWorkflowServiceStubsOptions(io.temporal.serviceclient.WorkflowServiceStubsOptions workflowServiceStubsOptions)
    • setWorkflowClientOptions

      public TestWorkflowRule.Builder setWorkflowClientOptions(io.temporal.client.WorkflowClientOptions workflowClientOptions)
      Override WorkflowClientOptions for test environment. If set, takes precedence over namespace.
    • setActivityClientOptions

      public TestWorkflowRule.Builder setActivityClientOptions(io.temporal.client.ActivityClientOptions activityClientOptions)
      Override ActivityClientOptions for test environment.
    • setWorkerFactoryOptions

      public TestWorkflowRule.Builder setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions options)
    • setNamespace

      public TestWorkflowRule.Builder setNamespace(String namespace)
    • setWorkflowTypes

      public TestWorkflowRule.Builder setWorkflowTypes(Class<?>... workflowTypes)
    • 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 in WorkflowImplementationOptions if none are provided.

      This can be disabled by setting setDoNotSetupNexusEndpoint(boolean) to true.

      See Also:
      • Worker.registerNexusServiceImplementation(Object...)
    • setActivityImplementations

      public TestWorkflowRule.Builder setActivityImplementations(Object... activityImplementations)
    • setUseExternalService

      public TestWorkflowRule.Builder setUseExternalService(boolean useExternalService)
      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() or useDevServer(TemporalDevServerOptions); whichever method is called last determines the service used by the rule.

      Parameters:
      useExternalService - use external service if true.

      Default is false.

    • useDevServer

      @Experimental public TestWorkflowRule.Builder 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

      public TestWorkflowRule.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

    • setTarget

      public TestWorkflowRule.Builder setTarget(String target)
      Optional parameter that defines an endpoint which will be used for the communication with standalone temporal service. Has no effect if setUseExternalService(boolean) is set to false.

      Default is to use 127.0.0.1:7233

    • setTestTimeoutSeconds

      @Deprecated public TestWorkflowRule.Builder setTestTimeoutSeconds(long testTimeoutSeconds)
      Deprecated.
      Temporal test rule shouldn't be responsible for enforcing test timeouts. Use toolchain of your test framework to enforce timeouts.
    • setInitialTimeMillis

      public TestWorkflowRule.Builder setInitialTimeMillis(long initialTimeMillis)
      Set the initial time for the workflow virtual clock, milliseconds since epoch.

      Default is current time

    • setInitialTime

      public TestWorkflowRule.Builder setInitialTime(Instant initialTime)
      Set the initial time for the workflow virtual clock.

      Default is current time

    • setDoNotStart

      public TestWorkflowRule.Builder setDoNotStart(boolean doNotStart)
      When set to true the TestWorkflowEnvironment.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 only TestWorkflowRule.Builder.
    • setDoNotSetupNexusEndpoint

      public TestWorkflowRule.Builder setDoNotSetupNexusEndpoint(boolean doNotSetupNexusEndpoint)
      When set to true the TestWorkflowEnvironment will 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 attribute
      type - 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

      public TestWorkflowRule.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 TestWorkflowRule build()