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

temporalio / sdk-java / #392

21 Sep 2026 10:15PM UTC coverage: 68.317% (+0.04%) from 68.278%
#392

push

github

web-flow
Add support for setting ActivityID (#3044)

Add support for setting Activity ID

7892 of 13700 branches covered (57.61%)

Branch coverage included in aggregate %.

119 of 176 new or added lines in 11 files covered. (67.61%)

4 existing lines in 2 files now uncovered.

32034 of 44742 relevant lines covered (71.6%)

0.72 hits per line

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

80.95
/temporal-sdk/src/main/java/io/temporal/internal/sync/ActivityInvocationInternal.java
1
package io.temporal.internal.sync;
2

3
import io.temporal.workflow.ActivityInvocationOptions;
4
import io.temporal.workflow.Functions;
5
import io.temporal.workflow.Promise;
6
import java.util.Objects;
7

8
/** Applies options to one typed Activity proxy invocation. */
9
final class ActivityInvocationInternal {
10

11
  private static final ThreadLocal<State> invocation = new ThreadLocal<>();
1 ✔
12

13
  private ActivityInvocationInternal() {}
14

15
  static <R> R invoke(ActivityInvocationOptions options, Functions.Func<R> invocationFunction) {
16
    State state = startInvocation(options, false);
1 ✔
17
    try {
18
      R result = invocationFunction.apply();
1 ✔
19
      state.verifyConsumed();
1 ✔
20
      return result;
1 ✔
21
    } finally {
22
      invocation.remove();
1 ✔
23
    }
24
  }
25

26
  static void invoke(ActivityInvocationOptions options, Functions.Proc invocationFunction) {
27
    State state = startInvocation(options, false);
1 ✔
28
    try {
29
      invocationFunction.apply();
1 ✔
30
      state.verifyConsumed();
1 ✔
31
    } finally {
32
      invocation.remove();
1 ✔
33
    }
34
  }
1 ✔
35

36
  static <R> Promise<R> invokeAsync(
37
      ActivityInvocationOptions options, Functions.Proc invocationFunction) {
38
    State state = startInvocation(options, true);
1 ✔
39
    try {
40
      invocationFunction.apply();
1 ✔
41
      return state.getResult();
1 ✔
42
    } finally {
43
      invocation.remove();
1 ✔
44
    }
45
  }
46

47
  private static State startInvocation(ActivityInvocationOptions options, boolean async) {
48
    if (invocation.get() != null) {
1 !
NEW
49
      throw new IllegalStateException("Already invoking an Activity with invocation options");
×
50
    }
51

52
    State state = new State(Objects.requireNonNull(options, "options"), async);
1 ✔
53
    invocation.set(state);
1 ✔
54
    return state;
1 ✔
55
  }
56

57
  static ActivityInvocationOptions consumeOptions() {
58
    State state = invocation.get();
1 ✔
59
    if (state == null) {
1 ✔
60
      return ActivityInvocationOptions.getDefaultInstance();
1 ✔
61
    }
62
    if (state.consumed) {
1 !
NEW
63
      throw new IllegalStateException("ActivityInvocationOptions can apply to only one invocation");
×
64
    }
65
    state.consumed = true;
1 ✔
66
    return state.options;
1 ✔
67
  }
68

69
  static <R> boolean captureResult(Promise<R> result) {
70
    State state = invocation.get();
1 ✔
71
    if (state == null || !state.async) {
1 ✔
72
      return false;
1 ✔
73
    }
74
    if (state.result != null) {
1 !
NEW
75
      throw new IllegalStateException("ActivityInvocationOptions can apply to only one invocation");
×
76
    }
77
    state.result = Objects.requireNonNull(result, "result");
1 ✔
78
    return true;
1 ✔
79
  }
80

81
  private static final class State {
82
    private final ActivityInvocationOptions options;
83
    private final boolean async;
84
    private boolean consumed;
85
    private Promise<?> result;
86

87
    private State(ActivityInvocationOptions options, boolean async) {
1 ✔
88
      this.options = options;
1 ✔
89
      this.async = async;
1 ✔
90
    }
1 ✔
91

92
    private void verifyConsumed() {
93
      if (!consumed) {
1 !
NEW
94
        throw invalidInvocation();
×
95
      }
96
    }
1 ✔
97

98
    @SuppressWarnings("unchecked")
99
    private <R> Promise<R> getResult() {
100
      if (!consumed || result == null) {
1 !
NEW
101
        throw invalidInvocation();
×
102
      }
103
      return (Promise<R>) result;
1 ✔
104
    }
105

106
    private IllegalArgumentException invalidInvocation() {
NEW
107
      return new IllegalArgumentException(
×
108
          "activityMethod must invoke an Activity stub created through Workflow.newActivityStub "
109
              + "or Workflow.newLocalActivityStub");
110
    }
111
  }
112
}
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