Class TestWorkflowExtension.Builder

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

public static class TestWorkflowExtension.Builder extends Object
  • Method Details

    • setWorkerOptions

      public TestWorkflowExtension.Builder setWorkerOptions(io.temporal.worker.WorkerOptions options)
      See Also:
    • setWorkflowClientOptions

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

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

      public TestWorkflowExtension.Builder setWorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions workerFactoryOptions)
      Override WorkerFactoryOptions for test environment.
      See Also:
    • setNamespace

      public TestWorkflowExtension.Builder setNamespace(String namespace)
      Set Temporal namespace to use for tests, by default, UnitTest is used.
      See Also:
      • WorkflowClientOptions.getNamespace()
    • registerWorkflowImplementationTypes

      public TestWorkflowExtension.Builder registerWorkflowImplementationTypes(Class<?>... workflowTypes)
      Specify workflow implementation types to register with the Temporal worker.
      See Also:
      • Worker.registerWorkflowImplementationTypes(Class[])
    • registerWorkflowImplementationTypes

      public TestWorkflowExtension.Builder registerWorkflowImplementationTypes(io.temporal.worker.WorkflowImplementationOptions options, Class<?>... workflowTypes)
      Specify workflow implementation types to register with the Temporal worker.
      See Also:
      • Worker.registerWorkflowImplementationTypes(Class[])
    • 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 in WorkflowImplementationOptions if none are provided.

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

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

      @Deprecated public TestWorkflowExtension.Builder setWorkflowTypes(Class<?>... workflowTypes)
      Deprecated.
      use registerWorkflowImplementationTypes instead
      Specify workflow implementation types to register with the Temporal worker.
      See Also:
      • Worker.registerWorkflowImplementationTypes(Class[])
    • setActivityImplementations

      public TestWorkflowExtension.Builder setActivityImplementations(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 of 127.0.0.1:7233.
      See Also:
    • useExternalService

      public TestWorkflowExtension.Builder useExternalService(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:
    • useDevServer

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

      public TestWorkflowExtension.Builder useInternalService()
      Switches to internal in-memory Temporal service implementation (default).
    • setDoNotStart

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

      public TestWorkflowExtension.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.
    • 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(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(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:
    • 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()