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

temporalio / sdk-java / #169

pending completion
#169

push

github-actions

web-flow
Remove use of deprecated API (#1758)

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

17345 of 21558 relevant lines covered (80.46%)

0.8 hits per line

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

82.26
/temporal-testing/src/main/java/io/temporal/testing/TimeLockingInterceptor.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.testing;
22

23
import io.temporal.api.common.v1.WorkflowExecution;
24
import io.temporal.client.UpdateHandle;
25
import io.temporal.client.WorkflowOptions;
26
import io.temporal.client.WorkflowStub;
27
import io.temporal.common.interceptors.WorkflowClientInterceptorBase;
28
import io.temporal.serviceclient.TestServiceStubs;
29
import java.lang.reflect.Type;
30
import java.util.Optional;
31
import java.util.concurrent.CompletableFuture;
32
import java.util.concurrent.ExecutionException;
33
import java.util.concurrent.TimeUnit;
34
import java.util.concurrent.TimeoutException;
35
import javax.annotation.Nullable;
36

37
class TimeLockingInterceptor extends WorkflowClientInterceptorBase {
38

39
  private final IdempotentTimeLocker locker;
40

41
  TimeLockingInterceptor(TestServiceStubs testServiceStubs) {
1✔
42
    this.locker = new IdempotentTimeLocker(testServiceStubs);
1✔
43
  }
1✔
44

45
  @Deprecated
46
  @Override
47
  public WorkflowStub newUntypedWorkflowStub(
48
      String workflowType, WorkflowOptions options, WorkflowStub next) {
49
    return new TimeLockingWorkflowStub(locker, next);
1✔
50
  }
51

52
  @Deprecated
53
  @Override
54
  public WorkflowStub newUntypedWorkflowStub(
55
      WorkflowExecution execution, Optional<String> workflowType, WorkflowStub next) {
56
    return new TimeLockingWorkflowStub(locker, next);
1✔
57
  }
58

59
  static class TimeLockingWorkflowStub implements WorkflowStub {
60

61
    private final IdempotentTimeLocker locker;
62
    private final WorkflowStub next;
63

64
    TimeLockingWorkflowStub(IdempotentTimeLocker locker, WorkflowStub next) {
1✔
65
      this.locker = locker;
1✔
66
      this.next = next;
1✔
67
    }
1✔
68

69
    @Override
70
    public void signal(String signalName, Object... args) {
71
      next.signal(signalName, args);
1✔
72
    }
1✔
73

74
    @Override
75
    public WorkflowExecution start(Object... args) {
76
      return next.start(args);
1✔
77
    }
78

79
    @Override
80
    public WorkflowExecution signalWithStart(
81
        String signalName, Object[] signalArgs, Object[] startArgs) {
82
      return next.signalWithStart(signalName, signalArgs, startArgs);
1✔
83
    }
84

85
    @Override
86
    public Optional<String> getWorkflowType() {
87
      return next.getWorkflowType();
1✔
88
    }
89

90
    @Override
91
    public WorkflowExecution getExecution() {
92
      return next.getExecution();
1✔
93
    }
94

95
    @Override
96
    public <R> R getResult(Class<R> resultClass, Type resultType) {
97
      locker.unlockTimeSkipping();
1✔
98
      try {
99
        return next.getResult(resultClass, resultType);
1✔
100
      } finally {
101
        locker.lockTimeSkipping();
1✔
102
      }
103
    }
104

105
    @Override
106
    public <R> R getResult(Class<R> resultClass) {
107
      locker.unlockTimeSkipping();
1✔
108
      try {
109
        return next.getResult(resultClass);
1✔
110
      } finally {
111
        locker.lockTimeSkipping();
1✔
112
      }
113
    }
114

115
    @Override
116
    public <R> CompletableFuture<R> getResultAsync(Class<R> resultClass, Type resultType) {
117
      return new TimeLockingWorkflowStub.TimeLockingFuture<>(
1✔
118
          next.getResultAsync(resultClass, resultType));
1✔
119
    }
120

121
    @Override
122
    public <R> CompletableFuture<R> getResultAsync(Class<R> resultClass) {
123
      return new TimeLockingWorkflowStub.TimeLockingFuture<>(next.getResultAsync(resultClass));
1✔
124
    }
125

126
    @Override
127
    public <R> R getResult(long timeout, TimeUnit unit, Class<R> resultClass, Type resultType)
128
        throws TimeoutException {
129
      locker.unlockTimeSkipping();
×
130
      try {
131
        return next.getResult(timeout, unit, resultClass, resultType);
×
132
      } finally {
133
        locker.lockTimeSkipping();
×
134
      }
135
    }
136

137
    @Override
138
    public <R> R getResult(long timeout, TimeUnit unit, Class<R> resultClass)
139
        throws TimeoutException {
140
      locker.unlockTimeSkipping();
1✔
141
      try {
142
        return next.getResult(timeout, unit, resultClass);
×
143
      } finally {
144
        locker.lockTimeSkipping();
1✔
145
      }
146
    }
147

148
    @Override
149
    public <R> CompletableFuture<R> getResultAsync(
150
        long timeout, TimeUnit unit, Class<R> resultClass, Type resultType) {
151
      return new TimeLockingWorkflowStub.TimeLockingFuture<>(
×
152
          next.getResultAsync(timeout, unit, resultClass, resultType));
×
153
    }
154

155
    @Override
156
    public <R> CompletableFuture<R> getResultAsync(
157
        long timeout, TimeUnit unit, Class<R> resultClass) {
158
      return new TimeLockingWorkflowStub.TimeLockingFuture<>(
1✔
159
          next.getResultAsync(timeout, unit, resultClass));
1✔
160
    }
161

162
    @Override
163
    public <R> R query(String queryType, Class<R> resultClass, Object... args) {
164
      return next.query(queryType, resultClass, args);
1✔
165
    }
166

167
    @Override
168
    public <R> R query(String queryType, Class<R> resultClass, Type resultType, Object... args) {
169
      return next.query(queryType, resultClass, resultType, args);
1✔
170
    }
171

172
    @Override
173
    public void cancel() {
174
      next.cancel();
1✔
175
    }
1✔
176

177
    @Override
178
    public void terminate(@Nullable String reason, Object... details) {
179
      next.terminate(reason, details);
1✔
180
    }
1✔
181

182
    @Override
183
    public Optional<WorkflowOptions> getOptions() {
184
      return next.getOptions();
1✔
185
    }
186

187
    /** Unlocks time skipping before blocking calls and locks back after completion. */
188
    private class TimeLockingFuture<R> extends CompletableFuture<R> {
189

190
      public TimeLockingFuture(CompletableFuture<R> resultAsync) {
1✔
191
        @SuppressWarnings({"FutureReturnValueIgnored", "unused"})
192
        CompletableFuture<R> ignored =
1✔
193
            resultAsync.whenComplete(
1✔
194
                (r, e) -> {
195
                  if (e == null) {
1✔
196
                    this.complete(r);
1✔
197
                  } else {
198
                    this.completeExceptionally(e);
1✔
199
                  }
200
                });
1✔
201
      }
1✔
202

203
      @Override
204
      public R get() throws InterruptedException, ExecutionException {
205
        locker.unlockTimeSkipping();
1✔
206
        try {
207
          return super.get();
1✔
208
        } finally {
209
          locker.lockTimeSkipping();
1✔
210
        }
211
      }
212

213
      @Override
214
      public R get(long timeout, TimeUnit unit)
215
          throws InterruptedException, ExecutionException, TimeoutException {
216
        locker.unlockTimeSkipping();
1✔
217
        try {
218
          return super.get(timeout, unit);
×
219
        } finally {
220
          locker.lockTimeSkipping();
1✔
221
        }
222
      }
223

224
      @Override
225
      public R join() {
226
        locker.unlockTimeSkipping();
1✔
227
        try {
228
          return super.join();
1✔
229
        } finally {
230
          locker.lockTimeSkipping();
1✔
231
        }
232
      }
233
    }
234

235
    @Override
236
    public <R> R update(String updateName, Class<R> resultClass, Object... args) {
237
      return next.update(updateName, resultClass, args);
×
238
    }
239

240
    @Override
241
    public <R> R update(
242
        String updateName,
243
        String updateId,
244
        String firstExecutionRunId,
245
        Class<R> resultClass,
246
        Type resultType,
247
        Object... args) {
248
      return next.update(updateName, updateId, firstExecutionRunId, resultClass, resultType, args);
×
249
    }
250

251
    @Override
252
    public <R> UpdateHandle<R> startUpdate(
253
        String updateName, Class<R> resultClass, Object... args) {
254
      return next.startUpdate(updateName, resultClass, args);
×
255
    }
256

257
    @Override
258
    public <R> UpdateHandle<R> startUpdate(
259
        String updateName,
260
        String updateId,
261
        String firstExecutionRunId,
262
        Class<R> resultClass,
263
        Type resultType,
264
        Object... args) {
265
      return next.startUpdate(
×
266
          updateName, updateId, firstExecutionRunId, resultClass, resultType, args);
267
    }
268
  }
269
}
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

© 2026 Coveralls, Inc