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

temporalio / sdk-java / #431

18 Nov 2026 09:28PM UTC coverage: 71.813% (+0.01%) from 71.8%
#431

push

github

web-flow
Include inherited fields in service stub options toString (#3152)

* Include inherited fields in service stub options toString

WorkflowServiceStubsOptions.toString rendered only the five fields
declared on the subclass, silently dropping every field inherited from
ServiceStubsOptions. Target, TLS settings, timeouts, and headers were
absent from the output, which is exactly the connection information
wanted when diagnosing a client from logs.

OperatorServiceStubsOptions and CloudServiceStubsOptions had no
toString at all and fell back to Object.toString, logging as an
unreadable identity hash.

Extract the field rendering on ServiceStubsOptions into a
package-private toStringFields helper and have each subclass inline it
alongside its own fields. The helper is package-private because all
four classes live in io.temporal.serviceclient, so this adds no public
API surface.

Also include apiKeyProvided, which already participates in equals and
hashCode but was omitted from toString. The API key itself is held by a
metadata provider and is still never rendered.

Fixes #2148.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Render header names instead of header values in toString

Metadata.toString renders header values in the clear. The previous
commit propagated the inherited headers field into
WorkflowServiceStubsOptions, OperatorServiceStubsOptions, and
CloudServiceStubsOptions, which would have newly exposed any credential
supplied through setHeaders, such as a static Authorization header.

Render the header names only. This keeps the diagnostic signal that
matters when reading the output, whether a header is configured and
which ones, without printing what they contain.

Also add a regression test for the missing separator before
congestionInitialInterval in RpcRetryOptions.toString.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Add changelog entry for service stub options toString

Co-Authored-By: Claude Opus 5.5 <noreply@anthro... (continued)

8779 of 14371 branches covered (61.09%)

Branch coverage included in aggregate %.

5 of 6 new or added lines in 4 files covered. (83.33%)

892 existing lines in 36 files now uncovered.

34625 of 46069 relevant lines covered (75.16%)

0.75 hits per line

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

91.55
/temporal-sdk/src/main/java/io/temporal/internal/statemachines/MutableSideEffectStateMachine.java
1
package io.temporal.internal.statemachines;
2

3
import com.google.common.annotations.VisibleForTesting;
4
import com.google.common.base.Strings;
5
import io.temporal.api.command.v1.RecordMarkerCommandAttributes;
6
import io.temporal.api.common.v1.Payloads;
7
import io.temporal.api.enums.v1.CommandType;
8
import io.temporal.api.enums.v1.EventType;
9
import io.temporal.api.history.v1.HistoryEvent;
10
import io.temporal.api.history.v1.MarkerRecordedEventAttributes;
11
import io.temporal.api.sdk.v1.EventGroupMarker;
12
import io.temporal.api.sdk.v1.UserMetadata;
13
import io.temporal.common.converter.DefaultDataConverter;
14
import io.temporal.common.converter.StdConverterBackwardsCompatAdapter;
15
import io.temporal.workflow.Functions;
16
import java.util.HashMap;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Objects;
20
import java.util.Optional;
21

22
final class MutableSideEffectStateMachine {
23

24
  static final String MARKER_DATA_KEY = "data";
25
  static final String MARKER_SKIP_COUNT_KEY = "skipCount";
26
  static final String MARKER_ID_KEY = "id";
27
  static final String MUTABLE_SIDE_EFFECT_MARKER_NAME = "MutableSideEffect";
28

29
  private final String id;
30
  private UserMetadata metadata;
31
  private final Functions.Func<Boolean> replaying;
32
  private final Functions.Proc1<CancellableCommand> commandSink;
33

34
  private Optional<Payloads> result = Optional.empty();
1 ✔
35

36
  private int currentSkipCount;
37

38
  private int skipCountFromMarker = Integer.MAX_VALUE;
1 ✔
39

40
  enum ExplicitEvent {
1 ✔
41
    CHECK_EXECUTION_STATE,
1 ✔
42
    SCHEDULE,
1 ✔
43
    NON_MATCHING_EVENT
1 ✔
44
  }
45

46
  enum State {
1 ✔
47
    CREATED,
1 ✔
48
    REPLAYING,
1 ✔
49
    EXECUTING,
1 ✔
50
    MARKER_COMMAND_CREATED,
1 ✔
51
    SKIPPED,
1 ✔
52
    CACHED_RESULT_NOTIFIED,
1 ✔
53
    RESULT_NOTIFIED,
1 ✔
54
    SKIPPED_NOTIFIED,
1 ✔
55
    RESULT_NOTIFIED_REPLAYING,
1 ✔
56
    MARKER_COMMAND_CREATED_REPLAYING,
1 ✔
57
    MARKER_COMMAND_RECORDED,
1 ✔
58
  }
59

60
  public static final StateMachineDefinition<State, ExplicitEvent, InvocationStateMachine>
61
      STATE_MACHINE_DEFINITION =
1 ✔
62
          StateMachineDefinition.<State, ExplicitEvent, InvocationStateMachine>newInstance(
1 ✔
63
                  "MutableSideEffect",
64
                  State.CREATED,
65
                  State.MARKER_COMMAND_RECORDED,
66
                  State.SKIPPED_NOTIFIED)
67
              .add(
1 ✔
68
                  State.CREATED,
69
                  ExplicitEvent.CHECK_EXECUTION_STATE,
70
                  new State[] {State.REPLAYING, State.EXECUTING},
71
                  InvocationStateMachine::getExecutionState)
72
              .add(
1 ✔
73
                  State.EXECUTING,
74
                  ExplicitEvent.SCHEDULE,
75
                  new State[] {State.MARKER_COMMAND_CREATED, State.SKIPPED},
76
                  InvocationStateMachine::createMarker)
77
              .add(
1 ✔
78
                  State.REPLAYING,
79
                  ExplicitEvent.SCHEDULE,
80
                  State.MARKER_COMMAND_CREATED_REPLAYING,
81
                  InvocationStateMachine::createFakeCommand)
82
              .add(
1 ✔
83
                  State.MARKER_COMMAND_CREATED,
84
                  CommandType.COMMAND_TYPE_RECORD_MARKER,
85
                  State.RESULT_NOTIFIED,
86
                  InvocationStateMachine::notifyCachedResult)
87
              .add(
1 ✔
88
                  State.SKIPPED,
89
                  CommandType.COMMAND_TYPE_RECORD_MARKER,
90
                  State.SKIPPED_NOTIFIED,
91
                  InvocationStateMachine::cancelCommandNotifyCachedResult)
92
              .add(
1 ✔
93
                  State.RESULT_NOTIFIED,
94
                  EventType.EVENT_TYPE_MARKER_RECORDED,
95
                  State.MARKER_COMMAND_RECORDED)
96
              .add(
1 ✔
97
                  State.MARKER_COMMAND_CREATED_REPLAYING,
98
                  CommandType.COMMAND_TYPE_RECORD_MARKER,
99
                  State.RESULT_NOTIFIED_REPLAYING)
100
              .add(
1 ✔
101
                  State.RESULT_NOTIFIED_REPLAYING,
102
                  ExplicitEvent.NON_MATCHING_EVENT,
103
                  State.SKIPPED_NOTIFIED,
104
                  InvocationStateMachine::cancelCommandNotifyCachedResult)
105
              .add(
1 ✔
106
                  State.RESULT_NOTIFIED_REPLAYING,
107
                  EventType.EVENT_TYPE_MARKER_RECORDED,
108
                  new State[] {State.MARKER_COMMAND_RECORDED, State.SKIPPED_NOTIFIED},
109
                  InvocationStateMachine::notifyFromEvent);
110

111
  /** Represents a single invocation of mutableSideEffect. */
112
  @VisibleForTesting
113
  class InvocationStateMachine
114
      extends EntityStateMachineInitialCommand<State, ExplicitEvent, InvocationStateMachine> {
115

116
    private final Functions.Proc1<Optional<Payloads>> resultCallback;
117
    private final Functions.Func1<Optional<Payloads>, Optional<Payloads>> func;
118
    private final List<EventGroupMarker> eventGroupMarkers;
119

120
    InvocationStateMachine(
121
        Functions.Func1<Optional<Payloads>, Optional<Payloads>> func,
122
        List<EventGroupMarker> eventGroupMarkers,
123
        Functions.Proc1<Optional<Payloads>> callback,
124
        Functions.Proc1<StateMachine> stateMachineSink) {
1 ✔
125
      super(
1 ✔
126
          STATE_MACHINE_DEFINITION,
127
          MutableSideEffectStateMachine.this.commandSink,
1 ✔
128
          stateMachineSink);
129
      this.func = Objects.requireNonNull(func);
1 ✔
130
      this.eventGroupMarkers = Objects.requireNonNull(eventGroupMarkers);
1 ✔
131
      this.resultCallback = Objects.requireNonNull(callback);
1 ✔
132
    }
1 ✔
133

134
    State getExecutionState() {
135
      return replaying.apply() ? State.REPLAYING : State.EXECUTING;
1 ✔
136
    }
137

138
    void notifySkippedReplaying() {
139
      if (getState() == State.RESULT_NOTIFIED_REPLAYING) {
1 ✔
140
        // No marker event accounts for this skip. Count it before the callback can make another
141
        // call.
142
        currentSkipCount++;
1 ✔
143
        explicitEvent(ExplicitEvent.NON_MATCHING_EVENT);
1 ✔
144
      }
145
    }
1 ✔
146

147
    @Override
148
    public WorkflowStateMachines.HandleEventStatus handleEvent(
149
        HistoryEvent event, boolean hasNextEvent) {
150
      if (event.getEventType() != EventType.EVENT_TYPE_MARKER_RECORDED
1 ✔
151
          || !event
152
              .getMarkerRecordedEventAttributes()
1 ✔
153
              .getMarkerName()
1 ✔
154
              .equals(MUTABLE_SIDE_EFFECT_MARKER_NAME)) {
1 !
155
        explicitEvent(ExplicitEvent.NON_MATCHING_EVENT);
1 ✔
156
        return WorkflowStateMachines.HandleEventStatus.NON_MATCHING_EVENT;
1 ✔
157
      }
158
      Map<String, Payloads> detailsMap = event.getMarkerRecordedEventAttributes().getDetailsMap();
1 ✔
159
      Optional<Payloads> idPayloads = Optional.ofNullable(detailsMap.get(MARKER_ID_KEY));
1 ✔
160
      String expectedId =
1 ✔
161
          StdConverterBackwardsCompatAdapter.fromPayloads(
1 ✔
162
              0, idPayloads, String.class, String.class);
163
      if (Strings.isNullOrEmpty(expectedId)) {
1 !
164
        throw new IllegalStateException(
×
165
            "Marker details map missing required key: " + MARKER_ID_KEY);
166
      }
167
      if (!id.equals(expectedId)) {
1 !
UNCOV
168
        explicitEvent(ExplicitEvent.NON_MATCHING_EVENT);
×
UNCOV
169
        return WorkflowStateMachines.HandleEventStatus.NON_MATCHING_EVENT;
×
170
      }
171
      return super.handleEvent(event, hasNextEvent);
1 ✔
172
    }
173

174
    State createMarker() {
175
      Optional<Payloads> updated = func.apply(result);
1 ✔
176
      if (!updated.isPresent()) {
1 ✔
177
        currentSkipCount++;
1 ✔
178
        addCommand(StateMachineCommandUtils.RECORD_MARKER_FAKE_COMMAND);
1 ✔
179
        return State.SKIPPED;
1 ✔
180
      } else {
181
        result = updated;
1 ✔
182
        Map<String, Payloads> details = new HashMap<>();
1 ✔
183
        details.put(MARKER_ID_KEY, DefaultDataConverter.STANDARD_INSTANCE.toPayloads(id).get());
1 ✔
184
        details.put(MARKER_DATA_KEY, updated.get());
1 ✔
185
        details.put(
1 ✔
186
            MARKER_SKIP_COUNT_KEY,
187
            DefaultDataConverter.STANDARD_INSTANCE.toPayloads(currentSkipCount).get());
1 ✔
188
        RecordMarkerCommandAttributes markerAttributes =
189
            RecordMarkerCommandAttributes.newBuilder()
1 ✔
190
                .setMarkerName(MUTABLE_SIDE_EFFECT_MARKER_NAME)
1 ✔
191
                .putAllDetails(details)
1 ✔
192
                .build();
1 ✔
193
        addCommand(
1 ✔
194
            StateMachineCommandUtils.createRecordMarker(
1 ✔
195
                markerAttributes, metadata, eventGroupMarkers));
1 ✔
196
        metadata = null; // only used once
1 ✔
197
        currentSkipCount = 0;
1 ✔
198
        return State.MARKER_COMMAND_CREATED;
1 ✔
199
      }
200
    }
201

202
    void createFakeCommand() {
203
      addCommand(StateMachineCommandUtils.RECORD_MARKER_FAKE_COMMAND);
1 ✔
204
    }
1 ✔
205

206
    /**
207
     * Returns MARKER_COMMAND_RECORDED only if the currentEvent:
208
     *
209
     * <ul>
210
     *   <li>Is a Marker
211
     *   <li>Has MutableSideEffect marker name
212
     *   <li>Its skip count matches. Not matching access count means that current event is for a
213
     *       some following mutableSideEffect invocation.
214
     * </ul>
215
     */
216
    State notifyFromEvent() {
217
      State r = notifyFromEventImpl();
1 ✔
218
      notifyCachedResult();
1 ✔
219
      return r;
1 ✔
220
    }
221

222
    State notifyFromEventImpl() {
223
      MarkerRecordedEventAttributes attributes = currentEvent.getMarkerRecordedEventAttributes();
1 ✔
224
      Map<String, Payloads> detailsMap = attributes.getDetailsMap();
1 ✔
225
      Optional<Payloads> skipCountPayloads =
1 ✔
226
          Optional.ofNullable(detailsMap.get(MARKER_SKIP_COUNT_KEY));
1 ✔
227
      if (!skipCountPayloads.isPresent()) {
1 !
228
        throw new IllegalStateException(
×
229
            "Marker details detailsMap missing required key: " + MARKER_SKIP_COUNT_KEY);
230
      }
231
      Optional<Payloads> oid = Optional.ofNullable(detailsMap.get(MARKER_ID_KEY));
1 ✔
232
      String idFromMarker =
1 ✔
233
          StdConverterBackwardsCompatAdapter.fromPayloads(0, oid, String.class, String.class);
1 ✔
234
      if (!id.equals(idFromMarker)) {
1 !
UNCOV
235
        throw new IllegalArgumentException("Ids doesnt match: " + id + "<>" + idFromMarker);
×
236
      }
237
      skipCountFromMarker =
1 ✔
238
          StdConverterBackwardsCompatAdapter.fromPayloads(
1 ✔
239
              0, skipCountPayloads, Integer.class, Integer.class);
240
      if (++currentSkipCount < skipCountFromMarker) {
1 ✔
241
        skipCountFromMarker = Integer.MAX_VALUE;
1 ✔
242
        return State.SKIPPED_NOTIFIED;
1 ✔
243
      }
244
      if (!attributes.getMarkerName().equals(MUTABLE_SIDE_EFFECT_MARKER_NAME)) {
1 !
UNCOV
245
        throw new IllegalStateException(
×
246
            "Expected " + MUTABLE_SIDE_EFFECT_MARKER_NAME + ", received: " + attributes);
247
      }
248
      currentSkipCount = 0;
1 ✔
249
      result = Optional.ofNullable(detailsMap.get(MARKER_DATA_KEY));
1 ✔
250
      return State.MARKER_COMMAND_RECORDED;
1 ✔
251
    }
252

253
    void notifyCachedResult() {
254
      resultCallback.apply(result);
1 ✔
255
    }
1 ✔
256

257
    void cancelCommandNotifyCachedResult() {
258
      cancelCommand();
1 ✔
259
      notifyCachedResult();
1 ✔
260
    }
1 ✔
261
  }
262

263
  /** Creates new MutableSideEffectStateMachine */
264
  public static MutableSideEffectStateMachine newInstance(
265
      String id,
266
      UserMetadata metadata,
267
      Functions.Func<Boolean> replaying,
268
      Functions.Proc1<CancellableCommand> commandSink,
269
      Functions.Proc1<StateMachine> stateMachineSink) {
270
    return new MutableSideEffectStateMachine(
1 ✔
271
        id, metadata, replaying, commandSink, stateMachineSink);
272
  }
273

274
  private MutableSideEffectStateMachine(
275
      String id,
276
      UserMetadata metadata,
277
      Functions.Func<Boolean> replaying,
278
      Functions.Proc1<CancellableCommand> commandSink,
279
      Functions.Proc1<StateMachine> stateMachineSink) {
1 ✔
280
    this.id = Objects.requireNonNull(id);
1 ✔
281
    this.metadata = metadata;
1 ✔
282
    this.replaying = Objects.requireNonNull(replaying);
1 ✔
283
    this.commandSink = Objects.requireNonNull(commandSink);
1 ✔
284
  }
1 ✔
285

286
  public InvocationStateMachine mutableSideEffect(
287
      Functions.Func1<Optional<Payloads>, Optional<Payloads>> func,
288
      List<EventGroupMarker> eventGroupMarkers,
289
      Functions.Proc1<Optional<Payloads>> callback,
290
      Functions.Proc1<StateMachine> stateMachineSink) {
291
    InvocationStateMachine ism =
1 ✔
292
        new InvocationStateMachine(func, eventGroupMarkers, callback, stateMachineSink);
293
    ism.explicitEvent(ExplicitEvent.CHECK_EXECUTION_STATE);
1 ✔
294
    ism.explicitEvent(ExplicitEvent.SCHEDULE);
1 ✔
295
    return ism;
1 ✔
296
  }
297
}
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