• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #400

06 Oct 2026 02:56AM UTC coverage: 68.324% (+0.007%) from 68.317%
#400

push

github

web-flow
Mark dev server APIs as stable (#3112)

7902 of 13718 branches covered (57.6%)

Branch coverage included in aggregate %.

32093 of 44819 relevant lines covered (71.61%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.67
/temporal-testing/src/main/java/io/temporal/testing/TestWorkflowRule.java
1
package io.temporal.testing;
2

3
import static io.temporal.testing.internal.TestServiceUtils.applyNexusServiceOptions;
4

5
import com.uber.m3.tally.Scope;
6
import io.temporal.api.common.v1.WorkflowExecution;
7
import io.temporal.api.enums.v1.IndexedValueType;
8
import io.temporal.api.history.v1.History;
9
import io.temporal.api.nexus.v1.Endpoint;
10
import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc;
11
import io.temporal.client.ActivityClient;
12
import io.temporal.client.ActivityClientOptions;
13
import io.temporal.client.WorkflowClient;
14
import io.temporal.client.WorkflowClientOptions;
15
import io.temporal.client.WorkflowOptions;
16
import io.temporal.client.WorkflowStub;
17
import io.temporal.common.SearchAttributeKey;
18
import io.temporal.common.interceptors.WorkerInterceptor;
19
import io.temporal.internal.common.env.DebugModeUtils;
20
import io.temporal.internal.docker.RegisterTestNamespace;
21
import io.temporal.serviceclient.WorkflowServiceStubs;
22
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
23
import io.temporal.worker.*;
24
import java.time.Instant;
25
import java.util.HashMap;
26
import java.util.Map;
27
import java.util.UUID;
28
import javax.annotation.Nonnull;
29
import javax.annotation.Nullable;
30
import org.junit.Test;
31
import org.junit.rules.TestRule;
32
import org.junit.rules.TestWatcher;
33
import org.junit.rules.Timeout;
34
import org.junit.runner.Description;
35
import org.junit.runners.model.Statement;
36

37
/**
38
 * JUnit4
39
 *
40
 * <p>Test rule that sets up test environment, simplifying workflow worker creation and shutdown.
41
 * Can be used with both in-memory and standalone temporal service. (see {@link
42
 * Builder#setUseExternalService(boolean)} and {@link Builder#setTarget(String)}})
43
 *
44
 * <p>Example of usage:
45
 *
46
 * <pre><code>
47
 *   public class MyTest {
48
 *
49
 *  {@literal @}Rule
50
 *   public TestWorkflowRule workflowRule =
51
 *       TestWorkflowRule.newBuilder()
52
 *           .setWorkflowTypes(TestWorkflowImpl.class)
53
 *           .setActivityImplementations(new TestActivities())
54
 *           .build();
55
 *
56
 *  {@literal @}Test
57
 *   public void testMyWorkflow() {
58
 *       TestWorkflow workflow = workflowRule.getWorkflowClient().newWorkflowStub(
59
 *                 TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(workflowRule.getTaskQueue()).build());
60
 *       ...
61
 *   }
62
 * </code></pre>
63
 */
64
public class TestWorkflowRule implements TestRule {
65

66
  private final String namespace;
67
  private final boolean useExternalService;
68
  private final boolean useDevServer;
69
  private final boolean doNotStart;
70
  private final boolean doNotSetupNexusEndpoint;
71
  @Nullable private final Timeout globalTimeout;
72

73
  private final Class<?>[] workflowTypes;
74
  private final Object[] activityImplementations;
75
  private final Object[] nexusServiceImplementations;
76
  private final WorkflowServiceStubsOptions serviceStubsOptions;
77
  private final WorkflowClientOptions clientOptions;
78
  private final ActivityClientOptions activityClientOptions;
79
  private final WorkerFactoryOptions workerFactoryOptions;
80
  private final WorkflowImplementationOptions workflowImplementationOptions;
81
  private final WorkerOptions workerOptions;
82
  private final String target;
83
  private final boolean useTimeskipping;
84
  private final Scope metricsScope;
85
  private String uniquePostfix;
86

87
  @Nonnull private final Map<String, IndexedValueType> searchAttributes;
88

89
  private String taskQueue;
90
  private String nexusEndpointName;
91
  private Endpoint nexusEndpoint;
92
  private final TestWorkflowEnvironment testEnvironment;
93
  private final TestWatcher watchman =
1 ✔
94
      new TestWatcher() {
1 ✔
95
        @Override
96
        protected void failed(Throwable e, Description description) {
97
          if (!useExternalService && !useDevServer) {
×
98
            System.err.println(
×
99
                "WORKFLOW EXECUTION HISTORIES:\n" + testEnvironment.getDiagnostics());
×
100
          }
101
        }
×
102
      };
103

104
  private TestWorkflowRule(Builder builder) {
1 ✔
105
    this.doNotStart = builder.doNotStart;
1 ✔
106
    this.doNotSetupNexusEndpoint = builder.doNotSetupNexusEndpoint;
1 ✔
107
    this.useExternalService = builder.useExternalService;
1 ✔
108
    this.useDevServer = builder.useDevServer;
1 ✔
109
    this.namespace =
1 ✔
110
        (builder.namespace == null) ? RegisterTestNamespace.NAMESPACE : builder.namespace;
1 ✔
111
    this.workflowTypes = (builder.workflowTypes == null) ? new Class[0] : builder.workflowTypes;
1 ✔
112
    this.activityImplementations =
1 ✔
113
        (builder.activityImplementations == null) ? new Object[0] : builder.activityImplementations;
1 ✔
114
    this.nexusServiceImplementations =
1 ✔
115
        (builder.nexusServiceImplementations == null)
1 ✔
116
            ? new Object[0]
1 ✔
117
            : builder.nexusServiceImplementations;
1 ✔
118
    this.serviceStubsOptions =
1 ✔
119
        (builder.workflowServiceStubsOptions == null)
1 ✔
120
            ? WorkflowServiceStubsOptions.newBuilder().build()
1 ✔
121
            : builder.workflowServiceStubsOptions;
1 ✔
122
    this.clientOptions =
1 ✔
123
        (builder.workflowClientOptions == null)
1 ✔
124
            ? WorkflowClientOptions.newBuilder().setNamespace(namespace).build()
1 ✔
125
            : builder.workflowClientOptions.toBuilder().setNamespace(namespace).build();
1 ✔
126
    this.activityClientOptions = builder.activityClientOptions;
1 ✔
127
    this.workerOptions =
1 ✔
128
        (builder.workerOptions == null)
1 ✔
129
            ? WorkerOptions.newBuilder().build()
1 ✔
130
            : builder.workerOptions;
1 ✔
131
    this.workerFactoryOptions =
1 ✔
132
        (builder.workerFactoryOptions == null)
1 ✔
133
            ? WorkerFactoryOptions.newBuilder().build()
1 ✔
134
            : builder.workerFactoryOptions;
1 ✔
135
    this.workflowImplementationOptions =
1 ✔
136
        (builder.workflowImplementationOptions == null)
1 ✔
137
            ? WorkflowImplementationOptions.newBuilder().build()
1 ✔
138
            : builder.workflowImplementationOptions;
1 ✔
139
    this.globalTimeout =
1 ✔
140
        !DebugModeUtils.isTemporalDebugModeOn() && builder.testTimeoutSeconds != 0
1 !
141
            ? Timeout.seconds(builder.testTimeoutSeconds)
×
142
            : null;
1 ✔
143

144
    this.target = builder.target;
1 ✔
145
    this.useTimeskipping = builder.useTimeskipping;
1 ✔
146
    this.metricsScope = builder.metricsScope;
1 ✔
147
    this.searchAttributes = builder.searchAttributes;
1 ✔
148

149
    TestEnvironmentOptions testEnvironmentOptions = createTestEnvOptions(builder.initialTimeMillis);
1 ✔
150
    this.testEnvironment =
1 ✔
151
        useDevServer
1 !
152
            ? TestWorkflowEnvironment.startLocal(testEnvironmentOptions, builder.devServerOptions)
×
153
            : TestWorkflowEnvironment.newInstance(testEnvironmentOptions);
1 ✔
154
  }
1 ✔
155

156
  protected TestEnvironmentOptions createTestEnvOptions(long initialTimeMillis) {
157
    return TestEnvironmentOptions.newBuilder()
1 ✔
158
        .setWorkflowServiceStubsOptions(serviceStubsOptions)
1 ✔
159
        .setWorkflowClientOptions(clientOptions)
1 ✔
160
        .setActivityClientOptions(activityClientOptions)
1 ✔
161
        .setWorkerFactoryOptions(workerFactoryOptions)
1 ✔
162
        .setUseExternalService(useExternalService)
1 ✔
163
        .setUseTimeskipping(useTimeskipping)
1 ✔
164
        .setTarget(target)
1 ✔
165
        .setInitialTimeMillis(initialTimeMillis)
1 ✔
166
        .setMetricsScope(metricsScope)
1 ✔
167
        .setSearchAttributes(searchAttributes)
1 ✔
168
        .build();
1 ✔
169
  }
170

171
  public static Builder newBuilder() {
172
    return new Builder();
1 ✔
173
  }
174

175
  public static class Builder {
176

177
    private String namespace;
178
    private String target;
179
    private boolean useExternalService;
180
    private boolean useDevServer;
181
    private TemporalDevServerOptions devServerOptions =
1 ✔
182
        TemporalDevServerOptions.getDefaultInstance();
1 ✔
183
    private boolean doNotStart;
184
    private boolean doNotSetupNexusEndpoint;
185
    private long initialTimeMillis;
186
    // Default to TestEnvironmentOptions isUseTimeskipping
187
    private boolean useTimeskipping =
1 ✔
188
        TestEnvironmentOptions.getDefaultInstance().isUseTimeskipping();
1 ✔
189

190
    private Class<?>[] workflowTypes;
191
    private Object[] activityImplementations;
192
    private Object[] nexusServiceImplementations;
193
    private WorkflowServiceStubsOptions workflowServiceStubsOptions;
194
    private WorkflowClientOptions workflowClientOptions;
195
    private ActivityClientOptions activityClientOptions;
196
    private WorkerFactoryOptions workerFactoryOptions;
197
    private WorkflowImplementationOptions workflowImplementationOptions;
198
    private WorkerOptions workerOptions;
199
    private long testTimeoutSeconds;
200
    @Nonnull private final Map<String, IndexedValueType> searchAttributes = new HashMap<>();
1 ✔
201
    private Scope metricsScope;
202

203
    protected Builder() {}
1 ✔
204

205
    public Builder setWorkerOptions(WorkerOptions options) {
206
      this.workerOptions = options;
1 ✔
207
      return this;
1 ✔
208
    }
209

210
    public void setWorkflowServiceStubsOptions(
211
        WorkflowServiceStubsOptions workflowServiceStubsOptions) {
212
      this.workflowServiceStubsOptions = workflowServiceStubsOptions;
1 ✔
213
    }
1 ✔
214

215
    /**
216
     * Override {@link WorkflowClientOptions} for test environment. If set, takes precedence over
217
     * {@link #setNamespace(String) namespace}.
218
     */
219
    public Builder setWorkflowClientOptions(WorkflowClientOptions workflowClientOptions) {
220
      this.workflowClientOptions = workflowClientOptions;
1 ✔
221
      return this;
1 ✔
222
    }
223

224
    /** Override {@link ActivityClientOptions} for test environment. */
225
    public Builder setActivityClientOptions(ActivityClientOptions activityClientOptions) {
226
      this.activityClientOptions = activityClientOptions;
1 ✔
227
      return this;
1 ✔
228
    }
229

230
    public Builder setWorkerFactoryOptions(WorkerFactoryOptions options) {
231
      this.workerFactoryOptions = options;
1 ✔
232
      return this;
1 ✔
233
    }
234

235
    public Builder setNamespace(String namespace) {
236
      this.namespace = namespace;
1 ✔
237
      return this;
1 ✔
238
    }
239

240
    public Builder setWorkflowTypes(Class<?>... workflowTypes) {
241
      this.workflowTypes = workflowTypes;
1 ✔
242
      return this;
1 ✔
243
    }
244

245
    public Builder setWorkflowTypes(
246
        WorkflowImplementationOptions implementationOptions, Class<?>... workflowTypes) {
247
      this.workflowImplementationOptions = implementationOptions;
1 ✔
248
      this.workflowTypes = workflowTypes;
1 ✔
249
      return this;
1 ✔
250
    }
251

252
    /**
253
     * Specify Nexus service implementations to register with the Temporal worker. If any Nexus
254
     * services are registered with the worker, the rule will automatically create a Nexus Endpoint
255
     * for the test and the endpoint will be set on the per-service options and default options in
256
     * {@link WorkflowImplementationOptions} if none are provided.
257
     *
258
     * <p>This can be disabled by setting {@link #setDoNotSetupNexusEndpoint(boolean)} to true.
259
     *
260
     * @see Worker#registerNexusServiceImplementation(Object...)
261
     */
262
    public Builder setNexusServiceImplementation(Object... nexusServiceImplementations) {
263
      this.nexusServiceImplementations = nexusServiceImplementations;
1 ✔
264
      return this;
1 ✔
265
    }
266

267
    public Builder setActivityImplementations(Object... activityImplementations) {
268
      this.activityImplementations = activityImplementations;
1 ✔
269
      return this;
1 ✔
270
    }
271

272
    /**
273
     * Switches between in-memory and external temporal service implementations.
274
     *
275
     * <p>External-service and dev-server modes are mutually exclusive. Calling this method clears
276
     * any selection made by {@link #useDevServer()} or {@link
277
     * #useDevServer(TemporalDevServerOptions)}; whichever method is called last determines the
278
     * service used by the rule.
279
     *
280
     * @param useExternalService use external service if true.
281
     *     <p>Default is false.
282
     */
283
    public Builder setUseExternalService(boolean useExternalService) {
284
      this.useExternalService = useExternalService;
1 ✔
285
      this.useDevServer = false;
1 ✔
286
      return this;
1 ✔
287
    }
288

289
    /**
290
     * Uses an owned local Temporal dev server instead of the in-memory or external service.
291
     *
292
     * <p>The rule closes the server during normal teardown. Dev-server tests do not support time
293
     * skipping.
294
     *
295
     * <p>Dev-server and external-service modes are mutually exclusive. Calling this method clears
296
     * any selection made by {@link #setUseExternalService(boolean)}; whichever method is called
297
     * last determines the service used by the rule.
298
     */
299
    public Builder useDevServer() {
300
      return useDevServer(TemporalDevServerOptions.getDefaultInstance());
×
301
    }
302

303
    /**
304
     * Uses an owned local Temporal dev server with the supplied options.
305
     *
306
     * <p>Dev-server and external-service modes are mutually exclusive. Calling this method clears
307
     * any selection made by {@link #setUseExternalService(boolean)}; whichever method is called
308
     * last determines the service used by the rule.
309
     *
310
     * <pre>{@code
311
     * TestWorkflowRule.newBuilder()
312
     *     .useDevServer(
313
     *         TemporalDevServerOptions.newBuilder().setDownloadVersion("v1.7.2").build())
314
     *     .setWorkflowTypes(MyWorkflowImpl.class)
315
     *     .build();
316
     * }</pre>
317
     */
318
    public Builder useDevServer(@Nonnull TemporalDevServerOptions options) {
319
      if (options == null) {
×
320
        throw new NullPointerException("options");
×
321
      }
322
      this.useDevServer = true;
×
323
      this.useExternalService = false;
×
324
      this.target = null;
×
325
      this.devServerOptions = options;
×
326
      return this;
×
327
    }
328

329
    /**
330
     * Sets TestEnvironmentOptions.setUseTimeskippings. If true, no actual wall-clock time will pass
331
     * when a workflow sleeps or sets a timer.
332
     *
333
     * <p>Default is true
334
     */
335
    public Builder setUseTimeskipping(boolean useTimeskipping) {
336
      this.useTimeskipping = useTimeskipping;
1 ✔
337
      return this;
1 ✔
338
    }
339

340
    /**
341
     * Optional parameter that defines an endpoint which will be used for the communication with
342
     * standalone temporal service. Has no effect if {@link #setUseExternalService(boolean)} is set
343
     * to false.
344
     *
345
     * <p>Default is to use 127.0.0.1:7233
346
     */
347
    public Builder setTarget(String target) {
348
      this.target = target;
1 ✔
349
      return this;
1 ✔
350
    }
351

352
    /**
353
     * @deprecated Temporal test rule shouldn't be responsible for enforcing test timeouts. Use
354
     *     toolchain of your test framework to enforce timeouts.
355
     */
356
    @Deprecated
357
    public Builder setTestTimeoutSeconds(long testTimeoutSeconds) {
358
      this.testTimeoutSeconds = testTimeoutSeconds;
×
359
      return this;
×
360
    }
361

362
    /**
363
     * Set the initial time for the workflow virtual clock, milliseconds since epoch.
364
     *
365
     * <p>Default is current time
366
     */
367
    public Builder setInitialTimeMillis(long initialTimeMillis) {
368
      this.initialTimeMillis = initialTimeMillis;
1 ✔
369
      return this;
1 ✔
370
    }
371

372
    /**
373
     * Set the initial time for the workflow virtual clock.
374
     *
375
     * <p>Default is current time
376
     */
377
    public Builder setInitialTime(Instant initialTime) {
378
      this.initialTimeMillis = initialTime.toEpochMilli();
×
379
      return this;
×
380
    }
381

382
    /**
383
     * When set to true the {@link TestWorkflowEnvironment#start()} is not called by the rule before
384
     * executing the test. This to support tests that register activities and workflows with workers
385
     * directly instead of using only {@link TestWorkflowRule.Builder}.
386
     */
387
    public Builder setDoNotStart(boolean doNotStart) {
388
      this.doNotStart = doNotStart;
1 ✔
389
      return this;
1 ✔
390
    }
391

392
    /**
393
     * When set to true the {@link TestWorkflowEnvironment} will not automatically create a Nexus
394
     * Endpoint. This is useful when you want to manually create a Nexus Endpoint for your test.
395
     */
396
    public Builder setDoNotSetupNexusEndpoint(boolean doNotSetupNexusEndpoint) {
397
      this.doNotSetupNexusEndpoint = doNotSetupNexusEndpoint;
×
398
      return this;
×
399
    }
400

401
    /**
402
     * Add a search attribute to be registered on the Temporal Server.
403
     *
404
     * @param name name of the search attribute
405
     * @param type search attribute type
406
     * @return {@code this}
407
     * @see <a
408
     *     href="https://docs.temporal.io/self-hosted-guide/visibility#create-custom-search-attributes">
409
     *     How to create custom Search Attributes</a>
410
     */
411
    public Builder registerSearchAttribute(String name, IndexedValueType type) {
412
      this.searchAttributes.put(name, type);
1 ✔
413
      return this;
1 ✔
414
    }
415

416
    /**
417
     * Add a search attribute to be registered on the Temporal Server.
418
     *
419
     * @param key key to register
420
     * @return {@code this}
421
     * @see <a
422
     *     href="https://docs.temporal.io/self-hosted-guide/visibility#create-custom-search-attributes">
423
     *     How to create custom Search Attributes</a>
424
     */
425
    public Builder registerSearchAttribute(SearchAttributeKey<?> key) {
426
      return this.registerSearchAttribute(key.getName(), key.getValueType());
1 ✔
427
    }
428

429
    /**
430
     * Sets the scope to be used for metrics reporting. Optional. Default is to not report metrics.
431
     *
432
     * <p>Note: Don't mock {@link Scope} in tests! If you need to verify the metrics behavior,
433
     * create a real Scope and mock, stub or spy a reporter instance:<br>
434
     *
435
     * <pre>{@code
436
     * StatsReporter reporter = mock(StatsReporter.class);
437
     * Scope metricsScope =
438
     *     new RootScopeBuilder()
439
     *         .reporter(reporter)
440
     *         .reportEvery(com.uber.m3.util.Duration.ofMillis(10));
441
     * }</pre>
442
     *
443
     * @param metricsScope the scope to be used for metrics reporting.
444
     * @return {@code this}
445
     */
446
    public Builder setMetricsScope(Scope metricsScope) {
447
      this.metricsScope = metricsScope;
1 ✔
448
      return this;
1 ✔
449
    }
450

451
    public TestWorkflowRule build() {
452
      return new TestWorkflowRule(this);
1 ✔
453
    }
454
  }
455

456
  @Override
457
  public Statement apply(Statement base, Description description) {
458
    taskQueue = init(description);
1 ✔
459
    Statement testWorkflowStatement =
1 ✔
460
        new Statement() {
1 ✔
461
          @Override
462
          public void evaluate() throws Throwable {
463
            Throwable testFailure = null;
1 ✔
464
            try {
465
              start();
1 ✔
466
              base.evaluate();
1 ✔
467
            } catch (Throwable failure) {
1 ✔
468
              testFailure = failure;
1 ✔
469
              throw failure;
1 ✔
470
            } finally {
471
              try {
472
                shutdown();
1 ✔
473
              } catch (Throwable cleanupFailure) {
×
474
                if (testFailure == null) {
×
475
                  throw cleanupFailure;
×
476
                }
477
                testFailure.addSuppressed(cleanupFailure);
×
478
              }
1 ✔
479
            }
480
          }
1 ✔
481
        };
482

483
    Test annotation = description.getAnnotation(Test.class);
1 ✔
484
    boolean timeoutIsOverriddenOnTestAnnotation = annotation != null && annotation.timeout() > 0;
1 ✔
485

486
    if (globalTimeout != null && !timeoutIsOverriddenOnTestAnnotation) {
1 !
487
      testWorkflowStatement = globalTimeout.apply(testWorkflowStatement, description);
×
488
    }
489

490
    return watchman.apply(testWorkflowStatement, description);
1 ✔
491
  }
492

493
  private String init(Description description) {
494
    uniquePostfix = description.getMethodName() + "-" + UUID.randomUUID();
1 ✔
495
    String taskQueue = "WorkflowTest-" + uniquePostfix;
1 ✔
496
    nexusEndpointName = String.format("WorkflowTestNexusEndpoint-%s", UUID.randomUUID());
1 ✔
497

498
    WorkerOptions workerOptions = this.workerOptions;
1 ✔
499
    Worker worker = testEnvironment.newWorker(taskQueue, workerOptions);
1 ✔
500
    WorkflowImplementationOptions workflowImplementationOptions =
1 ✔
501
        this.workflowImplementationOptions;
502
    if (!doNotSetupNexusEndpoint) {
1 !
503
      workflowImplementationOptions =
1 ✔
504
          applyNexusServiceOptions(
1 ✔
505
              workflowImplementationOptions, nexusServiceImplementations, nexusEndpointName);
506
    }
507
    worker.registerWorkflowImplementationTypes(workflowImplementationOptions, workflowTypes);
1 ✔
508
    worker.registerActivitiesImplementations(activityImplementations);
1 ✔
509
    worker.registerNexusServiceImplementation(nexusServiceImplementations);
1 ✔
510
    return taskQueue;
1 ✔
511
  }
512

513
  private void start() {
514
    if (!doNotSetupNexusEndpoint && nexusServiceImplementations.length > 0) {
1 !
515
      nexusEndpoint = testEnvironment.createNexusEndpoint(nexusEndpointName, taskQueue);
1 ✔
516
    }
517
    if (!doNotStart) {
1 ✔
518
      testEnvironment.start();
1 ✔
519
    }
520
  }
1 ✔
521

522
  protected void shutdown() {
523
    if (nexusEndpoint != null && !testEnvironment.getOperatorServiceStubs().isShutdown()) {
1 ✔
524
      testEnvironment.deleteNexusEndpoint(nexusEndpoint);
1 ✔
525
    }
526
    testEnvironment.close();
1 ✔
527
  }
1 ✔
528

529
  /**
530
   * See {@link Builder#setUseExternalService(boolean)}
531
   *
532
   * @return true if the rule is using external temporal service.
533
   */
534
  public boolean isUseExternalService() {
535
    return useExternalService;
×
536
  }
537

538
  public TestWorkflowEnvironment getTestEnvironment() {
539
    return testEnvironment;
1 ✔
540
  }
541

542
  /**
543
   * @return name of the task queue that test worker is polling.
544
   */
545
  public String getTaskQueue() {
546
    return taskQueue;
1 ✔
547
  }
548

549
  /**
550
   * @return The options used for the worker.
551
   */
552
  public WorkerOptions getWorkerOptions() {
553
    return workerOptions;
1 ✔
554
  }
555

556
  /**
557
   * @return endpoint of the nexus service created for the test.
558
   */
559
  public Endpoint getNexusEndpoint() {
560
    return nexusEndpoint;
1 ✔
561
  }
562

563
  /**
564
   * @return client to the Temporal service used to start and query workflows.
565
   */
566
  public WorkflowClient getWorkflowClient() {
567
    return testEnvironment.getWorkflowClient();
1 ✔
568
  }
569

570
  /**
571
   * @return client to the Temporal service used to start standalone activities.
572
   */
573
  public ActivityClient getActivityClient() {
574
    return testEnvironment.getActivityClient();
1 ✔
575
  }
576

577
  /**
578
   * @return stubs connected to the test server (in-memory or external)
579
   */
580
  public WorkflowServiceStubs getWorkflowServiceStubs() {
581
    return testEnvironment.getWorkflowServiceStubs();
1 ✔
582
  }
583

584
  /**
585
   * @return blockingStub
586
   */
587
  public WorkflowServiceGrpc.WorkflowServiceBlockingStub blockingStub() {
588
    return getWorkflowServiceStubs().blockingStub();
×
589
  }
590

591
  /**
592
   * @return tracer.
593
   */
594
  public <T extends WorkerInterceptor> T getInterceptor(Class<T> type) {
595
    if (workerFactoryOptions.getWorkerInterceptors() != null) {
1 !
596
      for (WorkerInterceptor interceptor : workerFactoryOptions.getWorkerInterceptors()) {
1 ✔
597
        if (type.isInstance(interceptor)) {
1 ✔
598
          return type.cast(interceptor);
1 ✔
599
        }
600
      }
601
    }
602
    return null;
1 ✔
603
  }
604

605
  /**
606
   * @return workflow execution history
607
   * @deprecated use {@link WorkflowClient#fetchHistory(String, String)}. To obtain a WorkflowClient
608
   *     use {@link #getWorkflowClient()}
609
   */
610
  @Deprecated
611
  public History getHistory(@Nonnull WorkflowExecution execution) {
612
    return testEnvironment.getWorkflowExecutionHistory(execution).getHistory();
×
613
  }
614

615
  /**
616
   * @return name of the task queue that test worker is polling.
617
   * @deprecated use {@link WorkflowClient#fetchHistory(String, String)}. To obtain a WorkflowClient
618
   *     use {@link #getWorkflowClient()}
619
   */
620
  @Deprecated
621
  public History getWorkflowExecutionHistory(WorkflowExecution execution) {
622
    return testEnvironment.getWorkflowExecutionHistory(execution).getHistory();
×
623
  }
624

625
  /**
626
   * This worker listens to the default task queue which is obtainable via the {@link
627
   * #getTaskQueue()} method.
628
   *
629
   * @return the default worker created for each test method.
630
   */
631
  public Worker getWorker() {
632
    return testEnvironment.getWorkerFactory().getWorker(getTaskQueue());
1 ✔
633
  }
634

635
  public WorkerFactoryOptions getWorkerFactoryOptions() {
636
    return workerFactoryOptions;
1 ✔
637
  }
638

639
  public <T> T newWorkflowStub(Class<T> workflow) {
640
    return getWorkflowClient()
1 ✔
641
        .newWorkflowStub(workflow, newWorkflowOptionsForTaskQueue(getTaskQueue()));
1 ✔
642
  }
643

644
  public WorkflowStub newUntypedWorkflowStub(String workflow) {
645
    return getWorkflowClient()
1 ✔
646
        .newUntypedWorkflowStub(workflow, newWorkflowOptionsForTaskQueue(getTaskQueue()));
1 ✔
647
  }
648

649
  /**
650
   * @return A unique string containing the test name appended to the task queue used by the test
651
   *     worker. Can be used for other test-specific naming.
652
   */
653
  public String getUniquePostfix() {
654
    return uniquePostfix;
1 ✔
655
  }
656

657
  private static WorkflowOptions newWorkflowOptionsForTaskQueue(String taskQueue) {
658
    return WorkflowOptions.newBuilder().setTaskQueue(taskQueue).build();
1 ✔
659
  }
660
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc