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

temporalio / sdk-java / #333

16 Oct 2024 07:28PM UTC coverage: 78.65% (+0.6%) from 78.085%
#333

push

github

web-flow
Fix code coverage (#2275)

22670 of 28824 relevant lines covered (78.65%)

0.79 hits per line

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

31.08
/temporal-testing/src/main/java/io/temporal/internal/sync/DummySyncWorkflowContext.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.sync;
22

23
import com.uber.m3.tally.NoopScope;
24
import com.uber.m3.tally.Scope;
25
import io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes;
26
import io.temporal.api.command.v1.ScheduleNexusOperationCommandAttributes;
27
import io.temporal.api.command.v1.SignalExternalWorkflowExecutionCommandAttributes;
28
import io.temporal.api.common.v1.*;
29
import io.temporal.api.failure.v1.Failure;
30
import io.temporal.api.sdk.v1.UserMetadata;
31
import io.temporal.common.RetryOptions;
32
import io.temporal.common.converter.DefaultDataConverter;
33
import io.temporal.failure.CanceledFailure;
34
import io.temporal.internal.common.SdkFlag;
35
import io.temporal.internal.replay.ReplayWorkflowContext;
36
import io.temporal.internal.statemachines.ExecuteActivityParameters;
37
import io.temporal.internal.statemachines.ExecuteLocalActivityParameters;
38
import io.temporal.internal.statemachines.LocalActivityCallback;
39
import io.temporal.internal.statemachines.StartChildWorkflowExecutionParameters;
40
import io.temporal.workflow.Functions;
41
import java.time.Duration;
42
import java.util.*;
43
import javax.annotation.Nonnull;
44
import javax.annotation.Nullable;
45

46
public class DummySyncWorkflowContext {
×
47
  public static SyncWorkflowContext newDummySyncWorkflowContext() {
48
    SyncWorkflowContext context =
1✔
49
        new SyncWorkflowContext(
50
            "dummy",
51
            WorkflowExecution.newBuilder().setWorkflowId("dummy").setRunId("dummy").build(),
1✔
52
            new SignalDispatcher(DefaultDataConverter.STANDARD_INSTANCE),
53
            new QueryDispatcher(DefaultDataConverter.STANDARD_INSTANCE),
54
            new UpdateDispatcher(DefaultDataConverter.STANDARD_INSTANCE),
55
            null,
56
            DefaultDataConverter.STANDARD_INSTANCE,
57
            null);
58
    context.setReplayContext(new DummyReplayWorkflowContext());
1✔
59
    context.initHeadOutboundCallsInterceptor(context);
1✔
60
    context.initHeadInboundCallsInterceptor(
1✔
61
        new BaseRootWorkflowInboundCallsInterceptor(context) {
1✔
62
          @Override
63
          public WorkflowOutput execute(WorkflowInput input) {
64
            throw new UnsupportedOperationException(
×
65
                "#execute is not implemented or needed for low level DeterministicRunner tests");
66
          }
67
        });
68
    return context;
1✔
69
  }
70

71
  private static final class DummyReplayWorkflowContext implements ReplayWorkflowContext {
1✔
72

73
    private final Timer timer = new Timer();
1✔
74

75
    @Override
76
    public WorkflowExecution getWorkflowExecution() {
77
      throw new UnsupportedOperationException("not implemented");
×
78
    }
79

80
    @Override
81
    public WorkflowExecution getParentWorkflowExecution() {
82
      throw new UnsupportedOperationException("not implemented");
×
83
    }
84

85
    @Override
86
    public WorkflowType getWorkflowType() {
87
      return WorkflowType.newBuilder().setName("dummy-workflow").build();
1✔
88
    }
89

90
    @Override
91
    public boolean isCancelRequested() {
92
      throw new UnsupportedOperationException("not implemented");
×
93
    }
94

95
    @Override
96
    public void setCancelRequested() {
97
      throw new UnsupportedOperationException("not implemented");
×
98
    }
99

100
    @Override
101
    public boolean isWorkflowMethodCompleted() {
102
      throw new UnsupportedOperationException("not implemented");
×
103
    }
104

105
    @Override
106
    public void setWorkflowMethodCompleted() {
107
      throw new UnsupportedOperationException("not implemented");
×
108
    }
109

110
    @Override
111
    public ContinueAsNewWorkflowExecutionCommandAttributes getContinueAsNewOnCompletion() {
112
      throw new UnsupportedOperationException("not implemented");
×
113
    }
114

115
    @Override
116
    public String getTaskQueue() {
117
      return "dummy-task-queue";
1✔
118
    }
119

120
    @Nullable
121
    @Override
122
    public RetryOptions getRetryOptions() {
123
      return null;
×
124
    }
125

126
    @Override
127
    public String getNamespace() {
128
      return "dummy-namespace";
1✔
129
    }
130

131
    @Override
132
    public String getWorkflowId() {
133
      return "dummy-workflow-id";
1✔
134
    }
135

136
    @Nonnull
137
    @Override
138
    public String getRunId() {
139
      return "dummy-run-id";
1✔
140
    }
141

142
    @Nonnull
143
    @Override
144
    public String getFirstExecutionRunId() {
145
      throw new UnsupportedOperationException("not implemented");
×
146
    }
147

148
    @Override
149
    public Optional<String> getContinuedExecutionRunId() {
150
      throw new UnsupportedOperationException("not implemented");
×
151
    }
152

153
    @Nonnull
154
    @Override
155
    public String getOriginalExecutionRunId() {
156
      throw new UnsupportedOperationException("not implemented");
×
157
    }
158

159
    @Override
160
    public Duration getWorkflowRunTimeout() {
161
      throw new UnsupportedOperationException("not implemented");
×
162
    }
163

164
    @Override
165
    public Duration getWorkflowExecutionTimeout() {
166
      return Duration.ZERO;
×
167
    }
168

169
    @Override
170
    public long getRunStartedTimestampMillis() {
171
      return 0;
×
172
    }
173

174
    @Nonnull
175
    @Override
176
    public Duration getWorkflowTaskTimeout() {
177
      throw new UnsupportedOperationException("not implemented");
×
178
    }
179

180
    @Override
181
    public Payload getMemo(String key) {
182
      throw new UnsupportedOperationException("not implemented");
×
183
    }
184

185
    @Override
186
    @Nullable
187
    public SearchAttributes getSearchAttributes() {
188
      throw new UnsupportedOperationException("not implemented");
×
189
    }
190

191
    @Override
192
    public ScheduleActivityTaskOutput scheduleActivityTask(
193
        ExecuteActivityParameters parameters,
194
        Functions.Proc2<Optional<Payloads>, Failure> callback) {
195
      throw new UnsupportedOperationException("not implemented");
×
196
    }
197

198
    @Override
199
    public Functions.Proc scheduleLocalActivityTask(
200
        ExecuteLocalActivityParameters parameters, LocalActivityCallback callback) {
201
      throw new UnsupportedOperationException("not implemented");
×
202
    }
203

204
    @Override
205
    public Functions.Proc1<Exception> startChildWorkflow(
206
        StartChildWorkflowExecutionParameters parameters,
207
        Functions.Proc2<WorkflowExecution, Exception> executionCallback,
208
        Functions.Proc2<Optional<Payloads>, Exception> callback) {
209
      throw new UnsupportedOperationException("not implemented");
×
210
    }
211

212
    @Override
213
    public Functions.Proc1<Exception> startNexusOperation(
214
        ScheduleNexusOperationCommandAttributes attributes,
215
        Functions.Proc2<Optional<String>, Failure> startedCallback,
216
        Functions.Proc2<Optional<Payload>, Failure> completionCallback) {
217
      throw new UnsupportedOperationException("not implemented");
×
218
    }
219

220
    @Override
221
    public Functions.Proc1<Exception> signalExternalWorkflowExecution(
222
        SignalExternalWorkflowExecutionCommandAttributes.Builder attributes,
223
        Functions.Proc2<Void, Failure> callback) {
224
      throw new UnsupportedOperationException("not implemented");
×
225
    }
226

227
    @Override
228
    public void requestCancelExternalWorkflowExecution(
229
        WorkflowExecution execution, Functions.Proc2<Void, RuntimeException> callback) {
230
      throw new UnsupportedOperationException("not implemented");
×
231
    }
232

233
    @Override
234
    public void continueAsNewOnCompletion(
235
        ContinueAsNewWorkflowExecutionCommandAttributes attributes) {
236
      throw new UnsupportedOperationException("not implemented");
×
237
    }
238

239
    @Override
240
    public Throwable getWorkflowTaskFailure() {
241
      throw new UnsupportedOperationException("not implemented");
×
242
    }
243

244
    @Override
245
    public void failWorkflowTask(Throwable failure) {
246
      throw new UnsupportedOperationException("not implemented");
×
247
    }
248

249
    @Override
250
    public long currentTimeMillis() {
251
      return System.currentTimeMillis();
×
252
    }
253

254
    @Override
255
    public Functions.Proc1<RuntimeException> newTimer(
256
        Duration delay, UserMetadata metadata, Functions.Proc1<RuntimeException> callback) {
257
      timer.schedule(
1✔
258
          new TimerTask() {
1✔
259
            @Override
260
            public void run() {
261
              callback.apply(null);
1✔
262
            }
1✔
263
          },
264
          delay.toMillis());
1✔
265
      return (e) -> {
1✔
266
        callback.apply(new CanceledFailure(null));
1✔
267
      };
1✔
268
    }
269

270
    @Override
271
    public void sideEffect(
272
        Functions.Func<Optional<Payloads>> func, Functions.Proc1<Optional<Payloads>> callback) {
273
      callback.apply(func.apply());
×
274
    }
×
275

276
    @Override
277
    public void mutableSideEffect(
278
        String id,
279
        Functions.Func1<Optional<Payloads>, Optional<Payloads>> func,
280
        Functions.Proc1<Optional<Payloads>> callback) {
281
      callback.apply(func.apply(Optional.empty()));
×
282
    }
×
283

284
    @Override
285
    public boolean isReplaying() {
286
      return false;
1✔
287
    }
288

289
    @Override
290
    public boolean getVersion(
291
        String changeId,
292
        int minSupported,
293
        int maxSupported,
294
        Functions.Proc2<Integer, RuntimeException> callback) {
295
      throw new UnsupportedOperationException("not implemented");
×
296
    }
297

298
    @Override
299
    public Random newRandom() {
300
      throw new UnsupportedOperationException("not implemented");
×
301
    }
302

303
    @Override
304
    public Scope getMetricsScope() {
305
      return new NoopScope();
×
306
    }
307

308
    @Override
309
    public boolean getEnableLoggingInReplay() {
310
      return false;
×
311
    }
312

313
    @Override
314
    public UUID randomUUID() {
315
      return UUID.randomUUID();
×
316
    }
317

318
    @Override
319
    public void upsertSearchAttributes(@Nonnull SearchAttributes searchAttributes) {
320
      throw new UnsupportedOperationException("not implemented");
×
321
    }
322

323
    @Override
324
    public void upsertMemo(Memo memo) {
325
      throw new UnsupportedOperationException("not implemented");
×
326
    }
327

328
    @Override
329
    public boolean tryUseSdkFlag(SdkFlag flag) {
330
      return false;
×
331
    }
332

333
    @Override
334
    public Optional<String> getCurrentBuildId() {
335
      return Optional.empty();
×
336
    }
337

338
    @Override
339
    public int getAttempt() {
340
      return 1;
×
341
    }
342

343
    @Override
344
    public String getCronSchedule() {
345
      return "dummy-cron-schedule";
×
346
    }
347

348
    @Nullable
349
    @Override
350
    public Payloads getLastCompletionResult() {
351
      return null;
×
352
    }
353

354
    @Nullable
355
    @Override
356
    public Failure getPreviousRunFailure() {
357
      return null;
×
358
    }
359

360
    @Nullable
361
    @Override
362
    public String getFullReplayDirectQueryName() {
363
      return null;
×
364
    }
365

366
    @Override
367
    public Map<String, Payload> getHeader() {
368
      return null;
×
369
    }
370

371
    @Override
372
    public long getLastWorkflowTaskStartedEventId() {
373
      return 0;
×
374
    }
375

376
    @Override
377
    public long getHistorySize() {
378
      return 0;
×
379
    }
380

381
    @Override
382
    public boolean isContinueAsNewSuggested() {
383
      return false;
×
384
    }
385
  }
386
}
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