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

temporalio / sdk-java / #278

08 Jul 2024 04:42PM UTC coverage: 77.565% (+0.1%) from 77.469%
#278

push

github

web-flow
Revert configurable slot provider (#2134)

* Revert "Resource based tuner (#2110)"

This reverts commit 8a2d5cdcc.

* Revert "Slot supplier interface & fixed-size implementation (#2014)"

This reverts commit d2a06fc6f.

* Fix merge conflict

* Keep Publish Test Report step

* Add tests for worker slots

* Fix white space

* One other whitespace change

117 of 133 new or added lines in 17 files covered. (87.97%)

5 existing lines in 5 files now uncovered.

19088 of 24609 relevant lines covered (77.57%)

0.78 hits per line

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

77.06
/temporal-sdk/src/main/java/io/temporal/internal/worker/SingleWorkerOptions.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.internal.worker;
22

23
import com.uber.m3.tally.NoopScope;
24
import com.uber.m3.tally.Scope;
25
import io.temporal.api.common.v1.WorkerVersionStamp;
26
import io.temporal.common.context.ContextPropagator;
27
import io.temporal.common.converter.DataConverter;
28
import io.temporal.common.converter.GlobalDataConverter;
29
import io.temporal.common.interceptors.WorkerInterceptor;
30
import java.time.Duration;
31
import java.util.List;
32

33
public final class SingleWorkerOptions {
34

35
  public static Builder newBuilder() {
36
    return new Builder();
1✔
37
  }
38

39
  public static Builder newBuilder(SingleWorkerOptions options) {
40
    return new Builder(options);
×
41
  }
42

43
  public static final class Builder {
44

45
    private String identity;
46
    private String binaryChecksum;
47
    private String buildId;
48
    private boolean useBuildIdForVersioning;
49
    private DataConverter dataConverter;
50
    private int taskExecutorThreadPoolSize = 100;
1✔
51
    private PollerOptions pollerOptions;
52
    private Scope metricsScope;
53
    private boolean enableLoggingInReplay;
54
    private List<ContextPropagator> contextPropagators;
55
    private WorkerInterceptor[] workerInterceptors;
56

57
    private Duration stickyQueueScheduleToStartTimeout;
58
    private long defaultDeadlockDetectionTimeout;
59
    private Duration maxHeartbeatThrottleInterval;
60
    private Duration defaultHeartbeatThrottleInterval;
61
    private Duration drainStickyTaskQueueTimeout;
62

63
    private Builder() {}
1✔
64

65
    private Builder(SingleWorkerOptions options) {
×
66
      if (options == null) {
×
67
        return;
×
68
      }
69
      this.identity = options.getIdentity();
×
70
      this.binaryChecksum = options.getBinaryChecksum();
×
71
      this.dataConverter = options.getDataConverter();
×
72
      this.pollerOptions = options.getPollerOptions();
×
NEW
73
      this.taskExecutorThreadPoolSize = options.getTaskExecutorThreadPoolSize();
×
74
      this.metricsScope = options.getMetricsScope();
×
75
      this.enableLoggingInReplay = options.getEnableLoggingInReplay();
×
76
      this.contextPropagators = options.getContextPropagators();
×
77
      this.workerInterceptors = options.getWorkerInterceptors();
×
78
      this.stickyQueueScheduleToStartTimeout = options.getStickyQueueScheduleToStartTimeout();
×
79
      this.defaultDeadlockDetectionTimeout = options.getDefaultDeadlockDetectionTimeout();
×
80
      this.maxHeartbeatThrottleInterval = options.getMaxHeartbeatThrottleInterval();
×
81
      this.defaultHeartbeatThrottleInterval = options.getDefaultHeartbeatThrottleInterval();
×
82
      this.buildId = options.getBuildId();
×
83
      this.useBuildIdForVersioning = options.isUsingBuildIdForVersioning();
×
84
      this.drainStickyTaskQueueTimeout = options.getDrainStickyTaskQueueTimeout();
×
85
    }
×
86

87
    public Builder setIdentity(String identity) {
88
      this.identity = identity;
1✔
89
      return this;
1✔
90
    }
91

92
    @Deprecated
93
    public Builder setBinaryChecksum(String binaryChecksum) {
94
      this.binaryChecksum = binaryChecksum;
×
95
      return this;
×
96
    }
97

98
    public Builder setDataConverter(DataConverter dataConverter) {
99
      this.dataConverter = dataConverter;
1✔
100
      return this;
1✔
101
    }
102

103
    public Builder setTaskExecutorThreadPoolSize(int taskExecutorThreadPoolSize) {
104
      this.taskExecutorThreadPoolSize = taskExecutorThreadPoolSize;
1✔
105
      return this;
1✔
106
    }
107

108
    public Builder setPollerOptions(PollerOptions pollerOptions) {
109
      this.pollerOptions = pollerOptions;
1✔
110
      return this;
1✔
111
    }
112

113
    public Builder setMetricsScope(Scope metricsScope) {
114
      this.metricsScope = metricsScope;
1✔
115
      return this;
1✔
116
    }
117

118
    public Builder setEnableLoggingInReplay(boolean enableLoggingInReplay) {
119
      this.enableLoggingInReplay = enableLoggingInReplay;
1✔
120
      return this;
1✔
121
    }
122

123
    /** Specifies the list of context propagators to use during this workflow. */
124
    public Builder setContextPropagators(List<ContextPropagator> contextPropagators) {
125
      this.contextPropagators = contextPropagators;
1✔
126
      return this;
1✔
127
    }
128

129
    /** Specifies the list of worker interceptors to use during this workflow. */
130
    public Builder setWorkerInterceptors(WorkerInterceptor[] workerInterceptors) {
131
      this.workerInterceptors = workerInterceptors;
1✔
132
      return this;
1✔
133
    }
134

135
    public Builder setStickyQueueScheduleToStartTimeout(
136
        Duration stickyQueueScheduleToStartTimeout) {
137
      this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
138
      return this;
1✔
139
    }
140

141
    public Builder setDefaultDeadlockDetectionTimeout(long defaultDeadlockDetectionTimeout) {
142
      this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
143
      return this;
1✔
144
    }
145

146
    public Builder setMaxHeartbeatThrottleInterval(Duration maxHeartbeatThrottleInterval) {
147
      this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
148
      return this;
1✔
149
    }
150

151
    public Builder setDefaultHeartbeatThrottleInterval(Duration defaultHeartbeatThrottleInterval) {
152
      this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
153
      return this;
1✔
154
    }
155

156
    public Builder setBuildId(String buildId) {
157
      this.buildId = buildId;
1✔
158
      return this;
1✔
159
    }
160

161
    public Builder setUseBuildIdForVersioning(boolean useBuildIdForVersioning) {
162
      this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
163
      return this;
1✔
164
    }
165

166
    public Builder setStickyTaskQueueDrainTimeout(Duration drainStickyTaskQueueTimeout) {
167
      this.drainStickyTaskQueueTimeout = drainStickyTaskQueueTimeout;
1✔
168
      return this;
1✔
169
    }
170

171
    public SingleWorkerOptions build() {
172
      PollerOptions pollerOptions = this.pollerOptions;
1✔
173
      if (pollerOptions == null) {
1✔
174
        pollerOptions = PollerOptions.newBuilder().build();
1✔
175
      }
176

177
      DataConverter dataConverter = this.dataConverter;
1✔
178
      if (dataConverter == null) {
1✔
179
        dataConverter = GlobalDataConverter.get();
1✔
180
      }
181

182
      Scope metricsScope = this.metricsScope;
1✔
183
      if (metricsScope == null) {
1✔
184
        metricsScope = new NoopScope();
1✔
185
      }
186

187
      Duration drainStickyTaskQueueTimeout = this.drainStickyTaskQueueTimeout;
1✔
188
      if (drainStickyTaskQueueTimeout == null) {
1✔
189
        drainStickyTaskQueueTimeout = Duration.ofSeconds(0);
1✔
190
      }
191

192
      return new SingleWorkerOptions(
1✔
193
          this.identity,
194
          this.binaryChecksum,
195
          this.buildId,
196
          this.useBuildIdForVersioning,
197
          dataConverter,
198
          this.taskExecutorThreadPoolSize,
199
          pollerOptions,
200
          metricsScope,
201
          this.enableLoggingInReplay,
202
          this.contextPropagators,
203
          this.workerInterceptors,
204
          this.stickyQueueScheduleToStartTimeout,
205
          this.defaultDeadlockDetectionTimeout,
206
          this.maxHeartbeatThrottleInterval,
207
          this.defaultHeartbeatThrottleInterval,
208
          drainStickyTaskQueueTimeout);
209
    }
210
  }
211

212
  private final String identity;
213
  private final String binaryChecksum;
214
  private final String buildId;
215
  private final boolean useBuildIdForVersioning;
216
  private final DataConverter dataConverter;
217
  private final int taskExecutorThreadPoolSize;
218
  private final PollerOptions pollerOptions;
219
  private final Scope metricsScope;
220
  private final boolean enableLoggingInReplay;
221
  private final List<ContextPropagator> contextPropagators;
222
  private final WorkerInterceptor[] workerInterceptors;
223
  private final Duration stickyQueueScheduleToStartTimeout;
224
  private final long defaultDeadlockDetectionTimeout;
225
  private final Duration maxHeartbeatThrottleInterval;
226
  private final Duration defaultHeartbeatThrottleInterval;
227
  private final Duration drainStickyTaskQueueTimeout;
228

229
  private SingleWorkerOptions(
230
      String identity,
231
      String binaryChecksum,
232
      String buildId,
233
      boolean useBuildIdForVersioning,
234
      DataConverter dataConverter,
235
      int taskExecutorThreadPoolSize,
236
      PollerOptions pollerOptions,
237
      Scope metricsScope,
238
      boolean enableLoggingInReplay,
239
      List<ContextPropagator> contextPropagators,
240
      WorkerInterceptor[] workerInterceptors,
241
      Duration stickyQueueScheduleToStartTimeout,
242
      long defaultDeadlockDetectionTimeout,
243
      Duration maxHeartbeatThrottleInterval,
244
      Duration defaultHeartbeatThrottleInterval,
245
      Duration drainStickyTaskQueueTimeout) {
1✔
246
    this.identity = identity;
1✔
247
    this.binaryChecksum = binaryChecksum;
1✔
248
    this.buildId = buildId;
1✔
249
    this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
250
    this.dataConverter = dataConverter;
1✔
251
    this.taskExecutorThreadPoolSize = taskExecutorThreadPoolSize;
1✔
252
    this.pollerOptions = pollerOptions;
1✔
253
    this.metricsScope = metricsScope;
1✔
254
    this.enableLoggingInReplay = enableLoggingInReplay;
1✔
255
    this.contextPropagators = contextPropagators;
1✔
256
    this.workerInterceptors = workerInterceptors;
1✔
257
    this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
258
    this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
259
    this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
260
    this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
261
    this.drainStickyTaskQueueTimeout = drainStickyTaskQueueTimeout;
1✔
262
  }
1✔
263

264
  public String getIdentity() {
265
    return identity;
1✔
266
  }
267

268
  @Deprecated
269
  public String getBinaryChecksum() {
270
    return binaryChecksum;
×
271
  }
272

273
  public String getBuildId() {
274
    if (buildId == null) {
1✔
275
      return binaryChecksum;
×
276
    }
277
    return buildId;
1✔
278
  }
279

280
  public boolean isUsingBuildIdForVersioning() {
281
    return useBuildIdForVersioning;
1✔
282
  }
283

284
  public Duration getDrainStickyTaskQueueTimeout() {
285
    return drainStickyTaskQueueTimeout;
1✔
286
  }
287

288
  public DataConverter getDataConverter() {
289
    return dataConverter;
1✔
290
  }
291

292
  public int getTaskExecutorThreadPoolSize() {
293
    return taskExecutorThreadPoolSize;
1✔
294
  }
295

296
  public PollerOptions getPollerOptions() {
297
    return pollerOptions;
1✔
298
  }
299

300
  public Scope getMetricsScope() {
301
    return metricsScope;
1✔
302
  }
303

304
  public boolean getEnableLoggingInReplay() {
305
    return enableLoggingInReplay;
1✔
306
  }
307

308
  public List<ContextPropagator> getContextPropagators() {
309
    return contextPropagators;
1✔
310
  }
311

312
  public WorkerInterceptor[] getWorkerInterceptors() {
313
    return workerInterceptors;
1✔
314
  }
315

316
  public Duration getStickyQueueScheduleToStartTimeout() {
317
    return stickyQueueScheduleToStartTimeout;
1✔
318
  }
319

320
  public long getDefaultDeadlockDetectionTimeout() {
321
    return defaultDeadlockDetectionTimeout;
1✔
322
  }
323

324
  public Duration getMaxHeartbeatThrottleInterval() {
325
    return maxHeartbeatThrottleInterval;
1✔
326
  }
327

328
  public Duration getDefaultHeartbeatThrottleInterval() {
329
    return defaultHeartbeatThrottleInterval;
1✔
330
  }
331

332
  public WorkerVersionStamp workerVersionStamp() {
333
    return WorkerVersionStamp.newBuilder()
1✔
334
        .setBuildId(this.getBuildId())
1✔
335
        .setUseVersioning(this.isUsingBuildIdForVersioning())
1✔
336
        .build();
1✔
337
  }
338
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc