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

uber / cadence-java-client / 2641

07 Nov 2024 08:14PM UTC coverage: 80.761% (+0.5%) from 80.243%
2641

Pull #954

buildkite

shijiesheng
add test
Pull Request #954: Fix unhandled exceptions in WorkflowServiceTChannel

6 of 6 new or added lines in 1 file covered. (100.0%)

93 existing lines in 7 files now uncovered.

15662 of 19393 relevant lines covered (80.76%)

0.81 hits per line

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

79.73
/src/main/java/com/uber/cadence/internal/worker/PollerOptions.java
1
/*
2
 *  Modifications Copyright (c) 2017-2020 Uber Technologies Inc.
3
 *  Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
4
 *  Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 *  Licensed under the Apache License, Version 2.0 (the "License"). You may not
7
 *  use this file except in compliance with the License. A copy of the License is
8
 *  located at
9
 *
10
 *  http://aws.amazon.com/apache2.0
11
 *
12
 *  or in the "license" file accompanying this file. This file is distributed on
13
 *  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
 *  express or implied. See the License for the specific language governing
15
 *  permissions and limitations under the License.
16
 */
17

18
package com.uber.cadence.internal.worker;
19

20
import java.time.Duration;
21
import org.slf4j.Logger;
22
import org.slf4j.LoggerFactory;
23

24
/** Options for component that polls Cadence task lists for tasks. */
25
public final class PollerOptions {
26

27
  private static final Logger log = LoggerFactory.getLogger(PollerOptions.class);
1✔
28

29
  public static Builder newBuilder() {
30
    return new Builder();
1✔
31
  }
32

33
  public static Builder newBuilder(PollerOptions options) {
34
    return new Builder(options);
1✔
35
  }
36

37
  public static PollerOptions getDefaultInstance() {
UNCOV
38
    return DEFAULT_INSTANCE;
×
39
  }
40

41
  private static final PollerOptions DEFAULT_INSTANCE;
42

43
  static {
44
    DEFAULT_INSTANCE = PollerOptions.newBuilder().build();
1✔
45
  }
1✔
46

47
  public static final class Builder {
48

49
    private int maximumPollRateIntervalMilliseconds = 1000;
1✔
50

51
    private double maximumPollRatePerSecond;
52

53
    private double pollBackoffCoefficient = 2;
1✔
54

55
    private Duration pollBackoffInitialInterval = Duration.ofMillis(100);
1✔
56

57
    private Duration pollBackoffMaximumInterval = Duration.ofMinutes(1);
1✔
58

59
    private int pollThreadCount = 1;
1✔
60

61
    private String pollThreadNamePrefix;
62

63
    private Boolean pollOnlyIfExecutorHasCapacity = Boolean.FALSE;
1✔
64

65
    private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
66

67
    private PollerAutoScalerOptions pollerAutoScalerOptions;
68

69
    private Builder() {}
1✔
70

71
    private Builder(PollerOptions o) {
1✔
72
      if (o == null) {
1✔
UNCOV
73
        return;
×
74
      }
75
      this.maximumPollRateIntervalMilliseconds = o.getMaximumPollRateIntervalMilliseconds();
1✔
76
      this.maximumPollRatePerSecond = o.getMaximumPollRatePerSecond();
1✔
77
      this.pollBackoffCoefficient = o.getPollBackoffCoefficient();
1✔
78
      this.pollBackoffInitialInterval = o.getPollBackoffInitialInterval();
1✔
79
      this.pollBackoffMaximumInterval = o.getPollBackoffMaximumInterval();
1✔
80
      this.pollThreadCount = o.getPollThreadCount();
1✔
81
      this.pollThreadNamePrefix = o.getPollThreadNamePrefix();
1✔
82
      this.pollOnlyIfExecutorHasCapacity = o.getPollOnlyIfExecutorHasCapacity();
1✔
83
      this.uncaughtExceptionHandler = o.getUncaughtExceptionHandler();
1✔
84
      this.pollerAutoScalerOptions = o.getPollerAutoScalerOptions();
1✔
85
    }
1✔
86

87
    /** Defines interval for measuring poll rate. Larger the interval more spiky can be the load. */
88
    public Builder setMaximumPollRateIntervalMilliseconds(int maximumPollRateIntervalMilliseconds) {
UNCOV
89
      this.maximumPollRateIntervalMilliseconds = maximumPollRateIntervalMilliseconds;
×
UNCOV
90
      return this;
×
91
    }
92

93
    /**
94
     * Maximum rate of polling. Measured in the interval set through {@link
95
     * #setMaximumPollRateIntervalMilliseconds(int)}.
96
     */
97
    public Builder setMaximumPollRatePerSecond(double maximumPollRatePerSecond) {
UNCOV
98
      this.maximumPollRatePerSecond = maximumPollRatePerSecond;
×
UNCOV
99
      return this;
×
100
    }
101

102
    /** Coefficient to use when calculating exponential delay in case of failures */
103
    public Builder setPollBackoffCoefficient(double pollBackoffCoefficient) {
UNCOV
104
      this.pollBackoffCoefficient = pollBackoffCoefficient;
×
UNCOV
105
      return this;
×
106
    }
107

108
    /**
109
     * Initial delay in case of failure. If backoff coefficient is 1 then it would be the constant
110
     * delay between failing polls.
111
     */
112
    public Builder setPollBackoffInitialInterval(Duration pollBackoffInitialInterval) {
113
      this.pollBackoffInitialInterval = pollBackoffInitialInterval;
1✔
114
      return this;
1✔
115
    }
116

117
    /** Maximum interval between polls in case of failures. */
118
    public Builder setPollBackoffMaximumInterval(Duration pollBackoffMaximumInterval) {
119
      this.pollBackoffMaximumInterval = pollBackoffMaximumInterval;
1✔
120
      return this;
1✔
121
    }
122

123
    /** Number of parallel polling threads. */
124
    public Builder setPollThreadCount(int pollThreadCount) {
125
      this.pollThreadCount = pollThreadCount;
1✔
126
      return this;
1✔
127
    }
128

129
    /** Called to report unexpected exceptions in the poller threads. */
130
    public Builder setUncaughtExceptionHandler(
131
        Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
UNCOV
132
      this.uncaughtExceptionHandler = uncaughtExceptionHandler;
×
UNCOV
133
      return this;
×
134
    }
135

136
    /** Prefix to use when naming poller threads. */
137
    public Builder setPollThreadNamePrefix(String pollThreadNamePrefix) {
138
      this.pollThreadNamePrefix = pollThreadNamePrefix;
1✔
139
      return this;
1✔
140
    }
141

142
    /**
143
     * The poller will check task executor's remaining capacity before polling tasks. This is to
144
     * prevent task to get started but not being able to execute in time.
145
     */
146
    public Builder setPollOnlyIfExecutorHasCapacity(boolean pollOnlyIfExecutorHasCapacity) {
UNCOV
147
      this.pollOnlyIfExecutorHasCapacity = pollOnlyIfExecutorHasCapacity;
×
UNCOV
148
      return this;
×
149
    }
150

151
    public Builder setPollerAutoScalerOptions(PollerAutoScalerOptions pollerAutoScalerOptions) {
UNCOV
152
      this.pollerAutoScalerOptions = pollerAutoScalerOptions;
×
UNCOV
153
      return this;
×
154
    }
155

156
    public PollerOptions build() {
157
      if (uncaughtExceptionHandler == null) {
1✔
158
        uncaughtExceptionHandler = (t, e) -> log.error("uncaught exception", e);
1✔
159
      }
160
      return new PollerOptions(
1✔
161
          maximumPollRateIntervalMilliseconds,
162
          maximumPollRatePerSecond,
163
          pollBackoffCoefficient,
164
          pollBackoffInitialInterval,
165
          pollBackoffMaximumInterval,
166
          pollThreadCount,
167
          uncaughtExceptionHandler,
168
          pollThreadNamePrefix,
169
          pollOnlyIfExecutorHasCapacity,
1✔
170
          pollerAutoScalerOptions);
171
    }
172
  }
173

174
  private final int maximumPollRateIntervalMilliseconds;
175

176
  private final double maximumPollRatePerSecond;
177

178
  private final double pollBackoffCoefficient;
179

180
  private final Duration pollBackoffInitialInterval;
181

182
  private final Duration pollBackoffMaximumInterval;
183

184
  private final int pollThreadCount;
185

186
  private final Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
187

188
  private final String pollThreadNamePrefix;
189

190
  private final Boolean pollOnlyIfExecutorHasCapacity;
191

192
  private final PollerAutoScalerOptions pollerAutoScalerOptions;
193

194
  private PollerOptions(
195
      int maximumPollRateIntervalMilliseconds,
196
      double maximumPollRatePerSecond,
197
      double pollBackoffCoefficient,
198
      Duration pollBackoffInitialInterval,
199
      Duration pollBackoffMaximumInterval,
200
      int pollThreadCount,
201
      Thread.UncaughtExceptionHandler uncaughtExceptionHandler,
202
      String pollThreadNamePrefix,
203
      boolean pollOnlyIfExecutorHasCapacity,
204
      PollerAutoScalerOptions pollerAutoScalerOptions) {
1✔
205
    this.maximumPollRateIntervalMilliseconds = maximumPollRateIntervalMilliseconds;
1✔
206
    this.maximumPollRatePerSecond = maximumPollRatePerSecond;
1✔
207
    this.pollBackoffCoefficient = pollBackoffCoefficient;
1✔
208
    this.pollBackoffInitialInterval = pollBackoffInitialInterval;
1✔
209
    this.pollBackoffMaximumInterval = pollBackoffMaximumInterval;
1✔
210
    this.pollThreadCount = pollThreadCount;
1✔
211
    this.uncaughtExceptionHandler = uncaughtExceptionHandler;
1✔
212
    this.pollThreadNamePrefix = pollThreadNamePrefix;
1✔
213
    this.pollOnlyIfExecutorHasCapacity = pollOnlyIfExecutorHasCapacity;
1✔
214
    this.pollerAutoScalerOptions = pollerAutoScalerOptions;
1✔
215
  }
1✔
216

217
  public int getMaximumPollRateIntervalMilliseconds() {
218
    return maximumPollRateIntervalMilliseconds;
1✔
219
  }
220

221
  public double getMaximumPollRatePerSecond() {
222
    return maximumPollRatePerSecond;
1✔
223
  }
224

225
  public double getPollBackoffCoefficient() {
226
    return pollBackoffCoefficient;
1✔
227
  }
228

229
  public Duration getPollBackoffInitialInterval() {
230
    return pollBackoffInitialInterval;
1✔
231
  }
232

233
  public Duration getPollBackoffMaximumInterval() {
234
    return pollBackoffMaximumInterval;
1✔
235
  }
236

237
  public int getPollThreadCount() {
238
    return pollThreadCount;
1✔
239
  }
240

241
  public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() {
242
    return uncaughtExceptionHandler;
1✔
243
  }
244

245
  public String getPollThreadNamePrefix() {
246
    return pollThreadNamePrefix;
1✔
247
  }
248

249
  public Boolean getPollOnlyIfExecutorHasCapacity() {
250
    return pollOnlyIfExecutorHasCapacity;
1✔
251
  }
252

253
  public PollerAutoScalerOptions getPollerAutoScalerOptions() {
254
    return pollerAutoScalerOptions;
1✔
255
  }
256

257
  @Override
258
  public String toString() {
UNCOV
259
    return "PollerOptions{"
×
260
        + "maximumPollRateIntervalMilliseconds="
261
        + maximumPollRateIntervalMilliseconds
262
        + ", maximumPollRatePerSecond="
263
        + maximumPollRatePerSecond
264
        + ", pollBackoffCoefficient="
265
        + pollBackoffCoefficient
266
        + ", pollBackoffInitialInterval="
267
        + pollBackoffInitialInterval
268
        + ", pollBackoffMaximumInterval="
269
        + pollBackoffMaximumInterval
270
        + ", pollThreadCount="
271
        + pollThreadCount
272
        + ", pollThreadNamePrefix='"
273
        + pollThreadNamePrefix
274
        + ", pollOnlyIfExecutorHasCapacity='"
275
        + pollOnlyIfExecutorHasCapacity
276
        + ", pollerAutoScalerOptions='"
277
        + pollerAutoScalerOptions
278
        + '\''
279
        + '}';
280
  }
281
}
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