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

uber / cadence-java-client / 2539

22 Oct 2024 10:48PM UTC coverage: 65.4% (+0.08%) from 65.318%
2539

Pull #923

buildkite

natemort
Refactor Test environment initialization to CadenceTestRule from WorkflowTest.

WorkflowTest is currently 6,000 lines long and has nearly every test related to end to end client behavior. It provides the rather neat behavior that it supports running against both an instance of Cadence running in Docker and against the test version. It's additionally parameterized to run the entire test suite with or without sticky execution enabled.

Due to the complexity in handling both environments, adding yet another test to WorkflowTest has always been the easiest option for developers. To allow for tests to easily be split into other files, extract the core functionality to a Junit test rule that can easily be reused by additional tests.

With the exception of testSignalCrossDomainExternalWorkflow and the replay tests that don't use the test environment, all tests have been left in WorkflowTest to be split out later.
Pull Request #923: Refactor Test Environment and Worker initialization to CadenceTestRule

12755 of 19503 relevant lines covered (65.4%)

0.65 hits per line

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

76.12
/src/main/java/com/uber/cadence/client/WorkflowClientOptions.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.client;
19

20
import com.uber.cadence.QueryRejectCondition;
21
import com.uber.cadence.context.ContextPropagator;
22
import com.uber.cadence.converter.DataConverter;
23
import com.uber.cadence.converter.JsonDataConverter;
24
import com.uber.cadence.internal.metrics.MetricsTag;
25
import com.uber.cadence.internal.metrics.NoopScope;
26
import com.uber.m3.tally.Scope;
27
import com.uber.m3.util.ImmutableMap;
28
import java.lang.management.ManagementFactory;
29
import java.util.Arrays;
30
import java.util.List;
31
import java.util.Objects;
32

33
/** Options for WorkflowClient configuration. */
34
public final class WorkflowClientOptions {
35
  private static final String DEFAULT_DOMAIN = "default";
36
  private static final WorkflowClientOptions DEFAULT_INSTANCE;
37
  private static final WorkflowClientInterceptor[] EMPTY_INTERCEPTOR_ARRAY =
1✔
38
      new WorkflowClientInterceptor[0];
39
  private static final List<ContextPropagator> EMPTY_CONTEXT_PROPAGATORS = Arrays.asList();
1✔
40

41
  static {
42
    DEFAULT_INSTANCE = new Builder().build();
1✔
43
  }
1✔
44

45
  public static WorkflowClientOptions defaultInstance() {
46
    return DEFAULT_INSTANCE;
1✔
47
  }
48

49
  public static Builder newBuilder() {
50
    return new Builder();
1✔
51
  }
52

53
  public static Builder newBuilder(WorkflowClientOptions options) {
54
    return new Builder(options);
1✔
55
  }
56

57
  public static final class Builder {
58
    private String domain = DEFAULT_DOMAIN;
1✔
59
    private DataConverter dataConverter = JsonDataConverter.getInstance();
1✔
60
    private WorkflowClientInterceptor[] interceptors = EMPTY_INTERCEPTOR_ARRAY;
1✔
61
    private Scope metricsScope = NoopScope.getInstance();
1✔
62
    private String identity = ManagementFactory.getRuntimeMXBean().getName();
1✔
63
    private List<ContextPropagator> contextPropagators = EMPTY_CONTEXT_PROPAGATORS;
1✔
64
    private QueryRejectCondition queryRejectCondition;
65

66
    private Builder() {}
1✔
67

68
    private Builder(WorkflowClientOptions options) {
1✔
69
      domain = options.getDomain();
1✔
70
      dataConverter = options.getDataConverter();
1✔
71
      interceptors = options.getInterceptors();
1✔
72
      metricsScope = options.getMetricsScope();
1✔
73
      identity = options.getIdentity();
1✔
74
      contextPropagators = options.getContextPropagators();
1✔
75
      queryRejectCondition = options.getQueryRejectCondition();
1✔
76
    }
1✔
77

78
    public Builder setDomain(String domain) {
79
      this.domain = domain;
1✔
80
      return this;
1✔
81
    }
82

83
    /**
84
     * Used to override default (JSON) data converter implementation.
85
     *
86
     * @param dataConverter data converter to serialize and deserialize arguments and return values.
87
     *     Not null.
88
     */
89
    public Builder setDataConverter(DataConverter dataConverter) {
90
      this.dataConverter = Objects.requireNonNull(dataConverter);
1✔
91
      return this;
1✔
92
    }
93

94
    /**
95
     * Interceptor used to intercept workflow client calls.
96
     *
97
     * @param interceptors not null
98
     */
99
    public Builder setInterceptors(WorkflowClientInterceptor... interceptors) {
100
      this.interceptors = Objects.requireNonNull(interceptors);
1✔
101
      return this;
1✔
102
    }
103

104
    /**
105
     * Sets the scope to be used for the workflow client for metrics reporting.
106
     *
107
     * @param metricsScope the scope to be used. Not null.
108
     */
109
    public Builder setMetricsScope(Scope metricsScope) {
110
      this.metricsScope = Objects.requireNonNull(metricsScope);
1✔
111
      return this;
1✔
112
    }
113

114
    /**
115
     * Override human readable identity of the worker. Identity is used to identify a worker and is
116
     * recorded in the workflow history events. For example when a worker gets an activity task the
117
     * correspondent ActivityTaskStarted event contains the worker identity as a field. Default is
118
     * whatever <code>(ManagementFactory.getRuntimeMXBean().getName()</code> returns.
119
     */
120
    public Builder setIdentity(String identity) {
121
      this.identity = Objects.requireNonNull(identity);
×
122
      return this;
×
123
    }
124

125
    public Builder setContextPropagators(List<ContextPropagator> contextPropagators) {
126
      this.contextPropagators = contextPropagators;
1✔
127
      return this;
1✔
128
    }
129

130
    /**
131
     * QueryRejectCondition is an optional field used to reject queries based on workflow state.
132
     * QueryRejectConditionNotOpen will reject queries to workflows that are not open.
133
     * QueryRejectConditionNotCompletedCleanly will reject queries to workflows that are not
134
     * completed successfully. (e.g. terminated, canceled timeout etc...)
135
     *
136
     * <p>Default is null, which means that queries will not be rejected based on workflow state.
137
     */
138
    public Builder setQueryRejectCondition(QueryRejectCondition queryRejectCondition) {
139
      this.queryRejectCondition = queryRejectCondition;
×
140
      return this;
×
141
    }
142

143
    public WorkflowClientOptions build() {
144
      metricsScope = metricsScope.tagged(ImmutableMap.of(MetricsTag.DOMAIN, domain));
1✔
145
      return new WorkflowClientOptions(
1✔
146
          domain,
147
          dataConverter,
148
          interceptors,
149
          metricsScope,
150
          identity,
151
          contextPropagators,
152
          queryRejectCondition);
153
    }
154
  }
155

156
  private final String domain;
157
  private final DataConverter dataConverter;
158
  private final WorkflowClientInterceptor[] interceptors;
159
  private final Scope metricsScope;
160
  private final String identity;
161
  private final List<ContextPropagator> contextPropagators;
162
  private final QueryRejectCondition queryRejectCondition;
163

164
  private WorkflowClientOptions(
165
      String domain,
166
      DataConverter dataConverter,
167
      WorkflowClientInterceptor[] interceptors,
168
      Scope metricsScope,
169
      String identity,
170
      List<ContextPropagator> contextPropagators,
171
      QueryRejectCondition queryRejectCondition) {
1✔
172
    this.domain = domain;
1✔
173
    this.dataConverter = dataConverter;
1✔
174
    this.interceptors = interceptors;
1✔
175
    this.metricsScope = metricsScope;
1✔
176
    this.identity = identity;
1✔
177
    this.contextPropagators = contextPropagators;
1✔
178
    this.queryRejectCondition = queryRejectCondition;
1✔
179
  }
1✔
180

181
  public String getDomain() {
182
    return domain;
1✔
183
  }
184

185
  public DataConverter getDataConverter() {
186
    return dataConverter;
1✔
187
  }
188

189
  public WorkflowClientInterceptor[] getInterceptors() {
190
    return interceptors;
1✔
191
  }
192

193
  public Scope getMetricsScope() {
194
    return metricsScope;
1✔
195
  }
196

197
  public String getIdentity() {
198
    return identity;
1✔
199
  }
200

201
  public List<ContextPropagator> getContextPropagators() {
202
    return contextPropagators;
1✔
203
  }
204

205
  public QueryRejectCondition getQueryRejectCondition() {
206
    return queryRejectCondition;
1✔
207
  }
208

209
  @Override
210
  public String toString() {
211
    return "WorkflowClientOptions{"
×
212
        + "domain='"
213
        + domain
214
        + '\''
215
        + ", dataConverter="
216
        + dataConverter
217
        + ", interceptors="
218
        + Arrays.toString(interceptors)
×
219
        + ", identity='"
220
        + identity
221
        + '\''
222
        + ", contextPropagators="
223
        + contextPropagators
224
        + ", queryRejectCondition="
225
        + queryRejectCondition
226
        + '}';
227
  }
228

229
  @Override
230
  public boolean equals(Object o) {
231
    if (this == o) return true;
×
232
    if (o == null || getClass() != o.getClass()) return false;
×
233
    WorkflowClientOptions that = (WorkflowClientOptions) o;
×
234
    return com.google.common.base.Objects.equal(domain, that.domain)
×
235
        && com.google.common.base.Objects.equal(dataConverter, that.dataConverter)
×
236
        && Arrays.equals(interceptors, that.interceptors)
×
237
        && com.google.common.base.Objects.equal(identity, that.identity)
×
238
        && com.google.common.base.Objects.equal(contextPropagators, that.contextPropagators)
×
239
        && queryRejectCondition == that.queryRejectCondition;
240
  }
241

242
  @Override
243
  public int hashCode() {
244
    return com.google.common.base.Objects.hashCode(
×
245
        domain,
246
        dataConverter,
247
        Arrays.hashCode(interceptors),
×
248
        identity,
249
        contextPropagators,
250
        queryRejectCondition);
251
  }
252
}
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