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

temporalio / sdk-java / #172

pending completion
#172

push

github-actions

web-flow
Update CODEOWNERS (#1773)

## What was changed
Update CODEOWNERS so that Security can own the Semgrep rules files and paths.

## Why?
We are adding Semgrep for static analysis to this repository, and only the security team should be able to approve exclusions from the policy.

## Checklist

How was this tested:
We ran this scanner on internal repos with this CODEOWNERS file and it worked as expected.

18029 of 22084 relevant lines covered (81.64%)

0.82 hits per line

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

87.3
/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.UpdateOptions;
26
import io.temporal.client.WorkflowOptions;
27
import io.temporal.client.WorkflowStub;
28
import io.temporal.common.interceptors.WorkflowClientInterceptorBase;
29
import io.temporal.serviceclient.TestServiceStubs;
30
import java.lang.reflect.Type;
31
import java.util.Optional;
32
import java.util.concurrent.CompletableFuture;
33
import java.util.concurrent.ExecutionException;
34
import java.util.concurrent.TimeUnit;
35
import java.util.concurrent.TimeoutException;
36
import javax.annotation.Nullable;
37

38
class TimeLockingInterceptor extends WorkflowClientInterceptorBase {
39

40
  private final IdempotentTimeLocker locker;
41

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

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

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

60
  static class TimeLockingWorkflowStub implements WorkflowStub {
61

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

241
    @Override
242
    public <R> UpdateHandle<R> startUpdate(
243
        String updateName, Class<R> resultClass, Object... args) {
244
      return next.startUpdate(updateName, resultClass, args);
1✔
245
    }
246

247
    @Override
248
    public <R> UpdateHandle<R> startUpdate(UpdateOptions<R> options, Object... args) {
249
      return next.startUpdate(options, args);
1✔
250
    }
251

252
    @Override
253
    public <R> UpdateHandle<R> getUpdateHandle(String updateId, Class<R> resultClass) {
254
      return next.getUpdateHandle(updateId, resultClass);
1✔
255
    }
256

257
    @Override
258
    public <R> UpdateHandle<R> getUpdateHandle(
259
        String updateId, Class<R> resultClass, Type resultType) {
260
      return next.getUpdateHandle(updateId, resultClass, resultType);
×
261
    }
262
  }
263
}
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