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

uber / cadence-java-client / 2632

07 Nov 2024 12:17AM UTC coverage: 78.326% (-1.5%) from 79.78%
2632

Pull #951

buildkite

fimanishi
Add tests for PollerOptions.java
Pull Request #951: Add tests for PollerOptions.java

15185 of 19387 relevant lines covered (78.33%)

0.78 hits per line

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

72.66
/src/main/java/com/uber/cadence/internal/testservice/TestWorkflowService.java
1
/*
2
 *  Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
 *
4
 *  Modifications copyright (C) 2017 Uber Technologies, Inc.
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.testservice;
19

20
import com.uber.cadence.BadRequestError;
21
import com.uber.cadence.ClientVersionNotSupportedError;
22
import com.uber.cadence.ClusterInfo;
23
import com.uber.cadence.CountWorkflowExecutionsRequest;
24
import com.uber.cadence.CountWorkflowExecutionsResponse;
25
import com.uber.cadence.DeprecateDomainRequest;
26
import com.uber.cadence.DescribeDomainRequest;
27
import com.uber.cadence.DescribeDomainResponse;
28
import com.uber.cadence.DescribeTaskListRequest;
29
import com.uber.cadence.DescribeTaskListResponse;
30
import com.uber.cadence.DescribeWorkflowExecutionRequest;
31
import com.uber.cadence.DescribeWorkflowExecutionResponse;
32
import com.uber.cadence.DomainAlreadyExistsError;
33
import com.uber.cadence.DomainNotActiveError;
34
import com.uber.cadence.EntityNotExistsError;
35
import com.uber.cadence.GetSearchAttributesResponse;
36
import com.uber.cadence.GetTaskListsByDomainRequest;
37
import com.uber.cadence.GetTaskListsByDomainResponse;
38
import com.uber.cadence.GetWorkflowExecutionHistoryRequest;
39
import com.uber.cadence.GetWorkflowExecutionHistoryResponse;
40
import com.uber.cadence.InternalServiceError;
41
import com.uber.cadence.LimitExceededError;
42
import com.uber.cadence.ListArchivedWorkflowExecutionsRequest;
43
import com.uber.cadence.ListArchivedWorkflowExecutionsResponse;
44
import com.uber.cadence.ListClosedWorkflowExecutionsRequest;
45
import com.uber.cadence.ListClosedWorkflowExecutionsResponse;
46
import com.uber.cadence.ListDomainsRequest;
47
import com.uber.cadence.ListDomainsResponse;
48
import com.uber.cadence.ListOpenWorkflowExecutionsRequest;
49
import com.uber.cadence.ListOpenWorkflowExecutionsResponse;
50
import com.uber.cadence.ListTaskListPartitionsRequest;
51
import com.uber.cadence.ListTaskListPartitionsResponse;
52
import com.uber.cadence.ListWorkflowExecutionsRequest;
53
import com.uber.cadence.ListWorkflowExecutionsResponse;
54
import com.uber.cadence.PollForActivityTaskRequest;
55
import com.uber.cadence.PollForActivityTaskResponse;
56
import com.uber.cadence.PollForDecisionTaskRequest;
57
import com.uber.cadence.PollForDecisionTaskResponse;
58
import com.uber.cadence.QueryFailedError;
59
import com.uber.cadence.QueryWorkflowRequest;
60
import com.uber.cadence.QueryWorkflowResponse;
61
import com.uber.cadence.RecordActivityTaskHeartbeatByIDRequest;
62
import com.uber.cadence.RecordActivityTaskHeartbeatRequest;
63
import com.uber.cadence.RecordActivityTaskHeartbeatResponse;
64
import com.uber.cadence.RefreshWorkflowTasksRequest;
65
import com.uber.cadence.RegisterDomainRequest;
66
import com.uber.cadence.RequestCancelWorkflowExecutionRequest;
67
import com.uber.cadence.ResetStickyTaskListRequest;
68
import com.uber.cadence.ResetStickyTaskListResponse;
69
import com.uber.cadence.ResetWorkflowExecutionRequest;
70
import com.uber.cadence.ResetWorkflowExecutionResponse;
71
import com.uber.cadence.RespondActivityTaskCanceledByIDRequest;
72
import com.uber.cadence.RespondActivityTaskCanceledRequest;
73
import com.uber.cadence.RespondActivityTaskCompletedByIDRequest;
74
import com.uber.cadence.RespondActivityTaskCompletedRequest;
75
import com.uber.cadence.RespondActivityTaskFailedByIDRequest;
76
import com.uber.cadence.RespondActivityTaskFailedRequest;
77
import com.uber.cadence.RespondDecisionTaskCompletedRequest;
78
import com.uber.cadence.RespondDecisionTaskCompletedResponse;
79
import com.uber.cadence.RespondDecisionTaskFailedRequest;
80
import com.uber.cadence.RespondQueryTaskCompletedRequest;
81
import com.uber.cadence.RestartWorkflowExecutionRequest;
82
import com.uber.cadence.RestartWorkflowExecutionResponse;
83
import com.uber.cadence.RetryPolicy;
84
import com.uber.cadence.ServiceBusyError;
85
import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes;
86
import com.uber.cadence.SignalExternalWorkflowExecutionFailedCause;
87
import com.uber.cadence.SignalWithStartWorkflowExecutionAsyncRequest;
88
import com.uber.cadence.SignalWithStartWorkflowExecutionAsyncResponse;
89
import com.uber.cadence.SignalWithStartWorkflowExecutionRequest;
90
import com.uber.cadence.SignalWorkflowExecutionRequest;
91
import com.uber.cadence.StartWorkflowExecutionAsyncRequest;
92
import com.uber.cadence.StartWorkflowExecutionAsyncResponse;
93
import com.uber.cadence.StartWorkflowExecutionRequest;
94
import com.uber.cadence.StartWorkflowExecutionResponse;
95
import com.uber.cadence.TerminateWorkflowExecutionRequest;
96
import com.uber.cadence.UpdateDomainRequest;
97
import com.uber.cadence.UpdateDomainResponse;
98
import com.uber.cadence.WorkflowExecution;
99
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
100
import com.uber.cadence.WorkflowExecutionAlreadyStartedError;
101
import com.uber.cadence.WorkflowExecutionCloseStatus;
102
import com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes;
103
import com.uber.cadence.WorkflowExecutionFilter;
104
import com.uber.cadence.WorkflowExecutionInfo;
105
import com.uber.cadence.WorkflowIdReusePolicy;
106
import com.uber.cadence.internal.testservice.TestWorkflowMutableStateImpl.QueryId;
107
import com.uber.cadence.internal.testservice.TestWorkflowStore.WorkflowState;
108
import com.uber.cadence.serviceclient.ClientOptions;
109
import com.uber.cadence.serviceclient.IWorkflowService;
110
import java.time.Duration;
111
import java.util.HashMap;
112
import java.util.List;
113
import java.util.Map;
114
import java.util.Optional;
115
import java.util.OptionalLong;
116
import java.util.concurrent.CompletableFuture;
117
import java.util.concurrent.ExecutionException;
118
import java.util.concurrent.ForkJoinPool;
119
import java.util.concurrent.TimeUnit;
120
import java.util.concurrent.locks.Lock;
121
import java.util.concurrent.locks.ReentrantLock;
122
import org.apache.thrift.TException;
123
import org.apache.thrift.async.AsyncMethodCallback;
124
import org.slf4j.Logger;
125
import org.slf4j.LoggerFactory;
126

127
/**
128
 * In memory implementation of the Cadence service. To be used for testing purposes only. Do not use
129
 * directly. Instead use {@link com.uber.cadence.testing.TestWorkflowEnvironment}.
130
 */
131
public final class TestWorkflowService implements IWorkflowService {
1✔
132

133
  private static final Logger log = LoggerFactory.getLogger(TestWorkflowService.class);
1✔
134

135
  private final Lock lock = new ReentrantLock();
1✔
136

137
  private final TestWorkflowStore store = new TestWorkflowStoreImpl();
1✔
138

139
  private final Map<ExecutionId, TestWorkflowMutableState> executions = new HashMap<>();
1✔
140

141
  // key->WorkflowId
142
  private final Map<WorkflowId, TestWorkflowMutableState> executionsByWorkflowId = new HashMap<>();
1✔
143

144
  private final ForkJoinPool forkJoinPool = new ForkJoinPool(4);
1✔
145

146
  @Override
147
  public void close() {
148
    store.close();
1✔
149
  }
1✔
150

151
  @Override
152
  public ClientOptions getOptions() {
153
    return ClientOptions.defaultInstance();
1✔
154
  }
155

156
  private TestWorkflowMutableState getMutableState(ExecutionId executionId)
157
      throws InternalServiceError, EntityNotExistsError {
158
    return getMutableState(executionId, true);
1✔
159
  }
160

161
  private TestWorkflowMutableState getMutableState(ExecutionId executionId, boolean failNotExists)
162
      throws InternalServiceError, EntityNotExistsError {
163
    lock.lock();
1✔
164
    try {
165
      if (executionId.getExecution().getRunId() == null) {
1✔
166
        return getMutableState(executionId.getWorkflowId(), failNotExists);
1✔
167
      }
168
      TestWorkflowMutableState mutableState = executions.get(executionId);
1✔
169
      if (mutableState == null && failNotExists) {
1✔
170
        throw new InternalServiceError("Execution not found in mutable state: " + executionId);
1✔
171
      }
172
      return mutableState;
1✔
173
    } finally {
174
      lock.unlock();
1✔
175
    }
176
  }
177

178
  private TestWorkflowMutableState getMutableState(WorkflowId workflowId)
179
      throws EntityNotExistsError {
180
    return getMutableState(workflowId, true);
1✔
181
  }
182

183
  private TestWorkflowMutableState getMutableState(WorkflowId workflowId, boolean failNotExists)
184
      throws EntityNotExistsError {
185
    lock.lock();
1✔
186
    try {
187
      TestWorkflowMutableState mutableState = executionsByWorkflowId.get(workflowId);
1✔
188
      if (mutableState == null && failNotExists) {
1✔
189
        throw new EntityNotExistsError("Execution not found in mutable state: " + workflowId);
1✔
190
      }
191
      return mutableState;
1✔
192
    } finally {
193
      lock.unlock();
1✔
194
    }
195
  }
196

197
  @Override
198
  public void RegisterDomain(RegisterDomainRequest registerRequest)
199
      throws BadRequestError, InternalServiceError, DomainAlreadyExistsError, TException {
200
    throw new UnsupportedOperationException("not implemented");
×
201
  }
202

203
  @Override
204
  public DescribeDomainResponse DescribeDomain(DescribeDomainRequest describeRequest)
205
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
206
    throw new UnsupportedOperationException("not implemented");
×
207
  }
208

209
  @Override
210
  public ListDomainsResponse ListDomains(ListDomainsRequest listRequest)
211
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
212
          TException {
213
    throw new UnsupportedOperationException("not implemented");
×
214
  }
215

216
  @Override
217
  public UpdateDomainResponse UpdateDomain(UpdateDomainRequest updateRequest)
218
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
219
    throw new UnsupportedOperationException("not implemented");
×
220
  }
221

222
  @Override
223
  public void DeprecateDomain(DeprecateDomainRequest deprecateRequest)
224
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
225
    throw new UnsupportedOperationException("not implemented");
×
226
  }
227

228
  @Override
229
  public RestartWorkflowExecutionResponse RestartWorkflowExecution(
230
      RestartWorkflowExecutionRequest restartRequest)
231
      throws BadRequestError, ServiceBusyError, DomainNotActiveError, LimitExceededError,
232
          EntityNotExistsError, ClientVersionNotSupportedError, TException {
233
    throw new UnsupportedOperationException("not implemented");
×
234
  }
235

236
  @Override
237
  public GetTaskListsByDomainResponse GetTaskListsByDomain(GetTaskListsByDomainRequest request)
238
      throws BadRequestError, EntityNotExistsError, LimitExceededError, ServiceBusyError,
239
          ClientVersionNotSupportedError, TException {
240
    throw new UnsupportedOperationException("not implemented");
×
241
  }
242

243
  @Override
244
  public StartWorkflowExecutionResponse StartWorkflowExecution(
245
      StartWorkflowExecutionRequest startRequest) throws TException {
246
    return startWorkflowExecutionImpl(
1✔
247
        startRequest, 0, Optional.empty(), OptionalLong.empty(), Optional.empty());
1✔
248
  }
249

250
  @Override
251
  public StartWorkflowExecutionAsyncResponse StartWorkflowExecutionAsync(
252
      StartWorkflowExecutionAsyncRequest startRequest)
253
      throws BadRequestError, WorkflowExecutionAlreadyStartedError, ServiceBusyError,
254
          DomainNotActiveError, LimitExceededError, EntityNotExistsError,
255
          ClientVersionNotSupportedError, TException {
256
    // Just run it
257
    StartWorkflowExecution(startRequest.getRequest());
1✔
258
    return new StartWorkflowExecutionAsyncResponse();
1✔
259
  }
260

261
  StartWorkflowExecutionResponse startWorkflowExecutionImpl(
262
      StartWorkflowExecutionRequest startRequest,
263
      int backoffStartIntervalInSeconds,
264
      Optional<TestWorkflowMutableState> parent,
265
      OptionalLong parentChildInitiatedEventId,
266
      Optional<SignalWorkflowExecutionRequest> signalWithStartSignal)
267
      throws BadRequestError, WorkflowExecutionAlreadyStartedError, InternalServiceError {
268
    String requestWorkflowId = requireNotNull("WorkflowId", startRequest.getWorkflowId());
1✔
269
    String domain = requireNotNull("Domain", startRequest.getDomain());
1✔
270
    WorkflowId workflowId = new WorkflowId(domain, requestWorkflowId);
1✔
271
    TestWorkflowMutableState existing;
272
    lock.lock();
1✔
273
    try {
274
      existing = executionsByWorkflowId.get(workflowId);
1✔
275
      if (existing != null) {
1✔
276
        Optional<WorkflowExecutionCloseStatus> statusOptional = existing.getCloseStatus();
1✔
277
        WorkflowIdReusePolicy policy =
278
            startRequest.isSetWorkflowIdReusePolicy()
1✔
279
                ? startRequest.getWorkflowIdReusePolicy()
1✔
280
                : WorkflowIdReusePolicy.AllowDuplicateFailedOnly;
1✔
281
        if (!statusOptional.isPresent() || policy == WorkflowIdReusePolicy.RejectDuplicate) {
1✔
282
          return throwDuplicatedWorkflow(startRequest, existing);
×
283
        }
284
        WorkflowExecutionCloseStatus status = statusOptional.get();
1✔
285
        if (policy == WorkflowIdReusePolicy.AllowDuplicateFailedOnly
1✔
286
            && (status == WorkflowExecutionCloseStatus.COMPLETED
287
                || status == WorkflowExecutionCloseStatus.CONTINUED_AS_NEW)) {
288
          return throwDuplicatedWorkflow(startRequest, existing);
×
289
        }
290
      }
291
      RetryPolicy retryPolicy = startRequest.getRetryPolicy();
1✔
292
      Optional<RetryState> retryState = newRetryStateLocked(retryPolicy);
1✔
293
      return startWorkflowExecutionNoRunningCheckLocked(
1✔
294
          startRequest,
295
          Optional.empty(),
1✔
296
          retryState,
297
          backoffStartIntervalInSeconds,
298
          null,
299
          parent,
300
          parentChildInitiatedEventId,
301
          signalWithStartSignal,
302
          workflowId);
303
    } finally {
304
      lock.unlock();
1✔
305
    }
306
  }
307

308
  private Optional<RetryState> newRetryStateLocked(RetryPolicy retryPolicy) throws BadRequestError {
309
    if (retryPolicy == null) {
1✔
310
      return Optional.empty();
1✔
311
    }
312
    long expirationInterval =
1✔
313
        TimeUnit.SECONDS.toMillis(retryPolicy.getExpirationIntervalInSeconds());
1✔
314
    long expirationTime = store.currentTimeMillis() + expirationInterval;
1✔
315
    return Optional.of(new RetryState(retryPolicy, expirationTime));
1✔
316
  }
317

318
  private StartWorkflowExecutionResponse throwDuplicatedWorkflow(
319
      StartWorkflowExecutionRequest startRequest, TestWorkflowMutableState existing)
320
      throws WorkflowExecutionAlreadyStartedError {
321
    WorkflowExecutionAlreadyStartedError error = new WorkflowExecutionAlreadyStartedError();
1✔
322
    WorkflowExecution execution = existing.getExecutionId().getExecution();
1✔
323
    error.setMessage(
1✔
324
        String.format(
1✔
325
            "WorkflowId: %s, " + "RunId: %s", execution.getWorkflowId(), execution.getRunId()));
1✔
326
    error.setRunId(execution.getRunId());
1✔
327
    error.setStartRequestId(startRequest.getRequestId());
1✔
328
    throw error;
1✔
329
  }
330

331
  private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheckLocked(
332
      StartWorkflowExecutionRequest startRequest,
333
      Optional<String> continuedExecutionRunId,
334
      Optional<RetryState> retryState,
335
      int backoffStartIntervalInSeconds,
336
      byte[] lastCompletionResult,
337
      Optional<TestWorkflowMutableState> parent,
338
      OptionalLong parentChildInitiatedEventId,
339
      Optional<SignalWorkflowExecutionRequest> signalWithStartSignal,
340
      WorkflowId workflowId)
341
      throws InternalServiceError, BadRequestError {
342
    String domain = startRequest.getDomain();
1✔
343
    TestWorkflowMutableState mutableState =
1✔
344
        new TestWorkflowMutableStateImpl(
345
            startRequest,
346
            retryState,
347
            backoffStartIntervalInSeconds,
348
            lastCompletionResult,
349
            parent,
350
            parentChildInitiatedEventId,
351
            continuedExecutionRunId,
352
            this,
353
            store);
354
    WorkflowExecution execution = mutableState.getExecutionId().getExecution();
1✔
355
    ExecutionId executionId = new ExecutionId(domain, execution);
1✔
356
    executionsByWorkflowId.put(workflowId, mutableState);
1✔
357
    executions.put(executionId, mutableState);
1✔
358
    mutableState.startWorkflow(continuedExecutionRunId.isPresent(), signalWithStartSignal);
1✔
359
    return new StartWorkflowExecutionResponse().setRunId(execution.getRunId());
1✔
360
  }
361

362
  @Override
363
  public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistory(
364
      GetWorkflowExecutionHistoryRequest getRequest)
365
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
366
          TException {
367
    ExecutionId executionId = new ExecutionId(getRequest.getDomain(), getRequest.getExecution());
1✔
368
    TestWorkflowMutableState mutableState = getMutableState(executionId);
1✔
369

370
    return store.getWorkflowExecutionHistory(mutableState.getExecutionId(), getRequest);
1✔
371
  }
372

373
  @Override
374
  public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistoryWithTimeout(
375
      GetWorkflowExecutionHistoryRequest getRequest, Long timeoutInMillis)
376
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
377
          TException {
378

379
    return GetWorkflowExecutionHistory(getRequest);
1✔
380
  }
381

382
  @Override
383
  public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskRequest pollRequest)
384
      throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
385
    PollForDecisionTaskResponse task;
386
    try {
387
      task = store.pollForDecisionTask(pollRequest);
1✔
388
    } catch (InterruptedException e) {
1✔
389
      return new PollForDecisionTaskResponse();
1✔
390
    }
1✔
391
    ExecutionId executionId = new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
1✔
392
    TestWorkflowMutableState mutableState = getMutableState(executionId);
1✔
393
    try {
394
      mutableState.startDecisionTask(task, pollRequest);
1✔
395
      // The task always has the original tasklist is was created on as part of the response. This
396
      // may different
397
      // then the task list it was scheduled on as in the case of sticky execution.
398
      task.setWorkflowExecutionTaskList(mutableState.getStartRequest().taskList);
1✔
399
      return task;
1✔
400
    } catch (EntityNotExistsError e) {
×
401
      if (log.isDebugEnabled()) {
×
402
        log.debug("Skipping outdated decision task for " + executionId, e);
×
403
      }
404
      // skip the task
405
    }
406
    task.setWorkflowExecutionTaskList(mutableState.getStartRequest().taskList);
×
407
    return task;
×
408
  }
409

410
  @Override
411
  public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(
412
      RespondDecisionTaskCompletedRequest request)
413
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
414
    DecisionTaskToken taskToken = DecisionTaskToken.fromBytes(request.getTaskToken());
1✔
415
    TestWorkflowMutableState mutableState = getMutableState(taskToken.getExecutionId());
1✔
416
    mutableState.completeDecisionTask(taskToken.getHistorySize(), request);
1✔
417
    return new RespondDecisionTaskCompletedResponse();
1✔
418
  }
419

420
  @Override
421
  public void RespondDecisionTaskFailed(RespondDecisionTaskFailedRequest failedRequest)
422
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
423
    DecisionTaskToken taskToken = DecisionTaskToken.fromBytes(failedRequest.getTaskToken());
1✔
424
    TestWorkflowMutableState mutableState = getMutableState(taskToken.getExecutionId());
1✔
425
    mutableState.failDecisionTask(failedRequest);
1✔
426
  }
1✔
427

428
  @Override
429
  public PollForActivityTaskResponse PollForActivityTask(PollForActivityTaskRequest pollRequest)
430
      throws BadRequestError, InternalServiceError, ServiceBusyError, TException {
431
    PollForActivityTaskResponse task;
432
    while (true) {
433
      try {
434
        task = store.pollForActivityTask(pollRequest);
1✔
435
      } catch (InterruptedException e) {
1✔
436
        return new PollForActivityTaskResponse();
1✔
437
      }
1✔
438
      ExecutionId executionId =
1✔
439
          new ExecutionId(pollRequest.getDomain(), task.getWorkflowExecution());
1✔
440
      TestWorkflowMutableState mutableState = getMutableState(executionId);
1✔
441
      try {
442
        mutableState.startActivityTask(task, pollRequest);
1✔
443
        return task;
1✔
444
      } catch (EntityNotExistsError e) {
×
445
        if (log.isDebugEnabled()) {
×
446
          log.debug("Skipping outdated activity task for " + executionId, e);
×
447
        }
448
      }
449
    }
×
450
  }
451

452
  @Override
453
  public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeat(
454
      RecordActivityTaskHeartbeatRequest heartbeatRequest)
455
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
456
    ActivityId activityId = ActivityId.fromBytes(heartbeatRequest.getTaskToken());
1✔
457
    TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId());
1✔
458
    return mutableState.heartbeatActivityTask(activityId.getId(), heartbeatRequest.getDetails());
1✔
459
  }
460

461
  @Override
462
  public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeatByID(
463
      RecordActivityTaskHeartbeatByIDRequest heartbeatRequest)
464
      throws BadRequestError, InternalServiceError, EntityNotExistsError, DomainNotActiveError,
465
          LimitExceededError, ServiceBusyError, TException {
466
    ExecutionId execution =
×
467
        new ExecutionId(
468
            heartbeatRequest.getDomain(),
×
469
            heartbeatRequest.getWorkflowID(),
×
470
            heartbeatRequest.getRunID());
×
471
    TestWorkflowMutableState mutableState = getMutableState(execution);
×
472
    return mutableState.heartbeatActivityTask(
×
473
        heartbeatRequest.getActivityID(), heartbeatRequest.getDetails());
×
474
  }
475

476
  @Override
477
  public void RespondActivityTaskCompleted(RespondActivityTaskCompletedRequest completeRequest)
478
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
479
    ActivityId activityId = ActivityId.fromBytes(completeRequest.getTaskToken());
1✔
480
    TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId());
1✔
481
    mutableState.completeActivityTask(activityId.getId(), completeRequest);
1✔
482
  }
1✔
483

484
  @Override
485
  public void RespondActivityTaskCompletedByID(
486
      RespondActivityTaskCompletedByIDRequest completeRequest)
487
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
488
    ActivityId activityId =
1✔
489
        new ActivityId(
490
            completeRequest.getDomain(),
1✔
491
            completeRequest.getWorkflowID(),
1✔
492
            completeRequest.getRunID(),
1✔
493
            completeRequest.getActivityID());
1✔
494
    TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId());
1✔
495
    mutableState.completeActivityTaskById(activityId.getId(), completeRequest);
1✔
496
  }
1✔
497

498
  @Override
499
  public void RespondActivityTaskFailed(RespondActivityTaskFailedRequest failRequest)
500
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
501
    ActivityId activityId = ActivityId.fromBytes(failRequest.getTaskToken());
1✔
502
    TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId());
1✔
503
    mutableState.failActivityTask(activityId.getId(), failRequest);
1✔
504
  }
1✔
505

506
  @Override
507
  public void RespondActivityTaskFailedByID(RespondActivityTaskFailedByIDRequest failRequest)
508
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
509
    ActivityId activityId =
1✔
510
        new ActivityId(
511
            failRequest.getDomain(),
1✔
512
            failRequest.getWorkflowID(),
1✔
513
            failRequest.getRunID(),
1✔
514
            failRequest.getActivityID());
1✔
515
    TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId());
1✔
516
    mutableState.failActivityTaskById(activityId.getId(), failRequest);
1✔
517
  }
1✔
518

519
  @Override
520
  public void RespondActivityTaskCanceled(RespondActivityTaskCanceledRequest canceledRequest)
521
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
522
    ActivityId activityId = ActivityId.fromBytes(canceledRequest.getTaskToken());
1✔
523
    TestWorkflowMutableState mutableState = getMutableState(activityId.getExecutionId());
1✔
524
    mutableState.cancelActivityTask(activityId.getId(), canceledRequest);
1✔
525
  }
1✔
526

527
  @Override
528
  public void RespondActivityTaskCanceledByID(
529
      RespondActivityTaskCanceledByIDRequest canceledRequest)
530
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
531
    ActivityId activityId =
1✔
532
        new ActivityId(
533
            canceledRequest.getDomain(),
1✔
534
            canceledRequest.getWorkflowID(),
1✔
535
            canceledRequest.getRunID(),
1✔
536
            canceledRequest.getActivityID());
1✔
537
    TestWorkflowMutableState mutableState = getMutableState(activityId.getWorkflowId());
1✔
538
    mutableState.cancelActivityTaskById(activityId.getId(), canceledRequest);
1✔
539
  }
1✔
540

541
  @Override
542
  public void RequestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest)
543
      throws TException {
544
    ExecutionId executionId =
1✔
545
        new ExecutionId(cancelRequest.getDomain(), cancelRequest.getWorkflowExecution());
1✔
546
    TestWorkflowMutableState mutableState = getMutableState(executionId);
1✔
547
    mutableState.requestCancelWorkflowExecution(cancelRequest);
1✔
548
  }
1✔
549

550
  @Override
551
  public void SignalWorkflowExecution(SignalWorkflowExecutionRequest signalRequest)
552
      throws TException {
553
    ExecutionId executionId =
1✔
554
        new ExecutionId(signalRequest.getDomain(), signalRequest.getWorkflowExecution());
1✔
555
    TestWorkflowMutableState mutableState = getMutableState(executionId);
1✔
556
    mutableState.signal(signalRequest);
1✔
557
  }
1✔
558

559
  @Override
560
  public StartWorkflowExecutionResponse SignalWithStartWorkflowExecution(
561
      SignalWithStartWorkflowExecutionRequest r)
562
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
563
          DomainNotActiveError, LimitExceededError, WorkflowExecutionAlreadyStartedError,
564
          TException {
565
    ExecutionId executionId = new ExecutionId(r.getDomain(), r.getWorkflowId(), null);
1✔
566
    TestWorkflowMutableState mutableState = getMutableState(executionId, false);
1✔
567
    SignalWorkflowExecutionRequest signalRequest =
1✔
568
        new SignalWorkflowExecutionRequest()
569
            .setInput(r.getSignalInput())
1✔
570
            .setSignalName(r.getSignalName())
1✔
571
            .setControl(r.getControl())
1✔
572
            .setDomain(r.getDomain())
1✔
573
            .setWorkflowExecution(executionId.getExecution())
1✔
574
            .setRequestId(r.getRequestId())
1✔
575
            .setIdentity(r.getIdentity());
1✔
576
    if (mutableState != null) {
1✔
577
      mutableState.signal(signalRequest);
1✔
578
      return new StartWorkflowExecutionResponse()
1✔
579
          .setRunId(mutableState.getExecutionId().getExecution().getRunId());
1✔
580
    }
581
    StartWorkflowExecutionRequest startRequest =
1✔
582
        new StartWorkflowExecutionRequest()
583
            .setInput(r.getInput())
1✔
584
            .setExecutionStartToCloseTimeoutSeconds(r.getExecutionStartToCloseTimeoutSeconds())
1✔
585
            .setTaskStartToCloseTimeoutSeconds(r.getTaskStartToCloseTimeoutSeconds())
1✔
586
            .setDomain(r.getDomain())
1✔
587
            .setRetryPolicy(r.getRetryPolicy())
1✔
588
            .setTaskList(r.getTaskList())
1✔
589
            .setWorkflowId(r.getWorkflowId())
1✔
590
            .setWorkflowIdReusePolicy(r.getWorkflowIdReusePolicy())
1✔
591
            .setWorkflowType(r.getWorkflowType())
1✔
592
            .setCronSchedule(r.getCronSchedule())
1✔
593
            .setRequestId(r.getRequestId())
1✔
594
            .setIdentity(r.getIdentity());
1✔
595
    return startWorkflowExecutionImpl(
1✔
596
        startRequest, 0, Optional.empty(), OptionalLong.empty(), Optional.of(signalRequest));
1✔
597
  }
598

599
  @Override
600
  public SignalWithStartWorkflowExecutionAsyncResponse SignalWithStartWorkflowExecutionAsync(
601
      SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest)
602
      throws BadRequestError, WorkflowExecutionAlreadyStartedError, ServiceBusyError,
603
          DomainNotActiveError, LimitExceededError, EntityNotExistsError,
604
          ClientVersionNotSupportedError, TException {
605
    SignalWithStartWorkflowExecution(signalWithStartRequest.getRequest());
×
606
    return new SignalWithStartWorkflowExecutionAsyncResponse();
×
607
  }
608

609
  // TODO: https://github.com/uber/cadence-java-client/issues/359
610
  @Override
611
  public ResetWorkflowExecutionResponse ResetWorkflowExecution(
612
      ResetWorkflowExecutionRequest resetRequest)
613
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
614
          DomainNotActiveError, LimitExceededError, ClientVersionNotSupportedError, TException {
615
    return null;
×
616
  }
617

618
  public void signalExternalWorkflowExecution(
619
      String signalId,
620
      SignalExternalWorkflowExecutionDecisionAttributes a,
621
      TestWorkflowMutableState source)
622
      throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
623
          BadRequestError {
624
    ExecutionId executionId = new ExecutionId(a.getDomain(), a.getExecution());
1✔
625
    TestWorkflowMutableState mutableState = null;
1✔
626
    try {
627
      mutableState = getMutableState(executionId);
1✔
628
      mutableState.signalFromWorkflow(a);
1✔
629
      source.completeSignalExternalWorkflowExecution(
1✔
630
          signalId, mutableState.getExecutionId().getExecution().getRunId());
1✔
631
    } catch (EntityNotExistsError entityNotExistsError) {
1✔
632
      source.failSignalExternalWorkflowExecution(
1✔
633
          signalId, SignalExternalWorkflowExecutionFailedCause.UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION);
634
    }
1✔
635
  }
1✔
636

637
  @Override
638
  public void TerminateWorkflowExecution(TerminateWorkflowExecutionRequest terminateRequest)
639
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
640
          TException {
641
    throw new UnsupportedOperationException("not implemented");
×
642
  }
643

644
  /**
645
   * Creates next run of a workflow execution
646
   *
647
   * @return RunId
648
   */
649
  public String continueAsNew(
650
      StartWorkflowExecutionRequest previousRunStartRequest,
651
      WorkflowExecutionContinuedAsNewEventAttributes a,
652
      Optional<RetryState> retryState,
653
      String identity,
654
      ExecutionId executionId,
655
      Optional<TestWorkflowMutableState> parent,
656
      OptionalLong parentChildInitiatedEventId)
657
      throws InternalServiceError, BadRequestError {
658
    StartWorkflowExecutionRequest startRequest =
1✔
659
        new StartWorkflowExecutionRequest()
660
            .setWorkflowType(a.getWorkflowType())
1✔
661
            .setExecutionStartToCloseTimeoutSeconds(a.getExecutionStartToCloseTimeoutSeconds())
1✔
662
            .setTaskStartToCloseTimeoutSeconds(a.getTaskStartToCloseTimeoutSeconds())
1✔
663
            .setDomain(executionId.getDomain())
1✔
664
            .setTaskList(a.getTaskList())
1✔
665
            .setWorkflowId(executionId.getWorkflowId().getWorkflowId())
1✔
666
            .setWorkflowIdReusePolicy(previousRunStartRequest.getWorkflowIdReusePolicy())
1✔
667
            .setIdentity(identity)
1✔
668
            .setRetryPolicy(previousRunStartRequest.getRetryPolicy())
1✔
669
            .setCronSchedule(previousRunStartRequest.getCronSchedule());
1✔
670
    if (a.isSetInput()) {
1✔
671
      startRequest.setInput(a.getInput());
1✔
672
    }
673
    lock.lock();
1✔
674
    try {
675
      StartWorkflowExecutionResponse response =
1✔
676
          startWorkflowExecutionNoRunningCheckLocked(
1✔
677
              startRequest,
678
              Optional.of(executionId.getExecution().getRunId()),
1✔
679
              retryState,
680
              a.getBackoffStartIntervalInSeconds(),
1✔
681
              a.getLastCompletionResult(),
1✔
682
              parent,
683
              parentChildInitiatedEventId,
684
              Optional.empty(),
1✔
685
              executionId.getWorkflowId());
1✔
686
      return response.getRunId();
1✔
687
    } finally {
688
      lock.unlock();
1✔
689
    }
690
  }
691

692
  @Override
693
  public ListOpenWorkflowExecutionsResponse ListOpenWorkflowExecutions(
694
      ListOpenWorkflowExecutionsRequest listRequest)
695
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
696
          TException {
697
    Optional<String> workflowIdFilter;
698
    WorkflowExecutionFilter executionFilter = listRequest.getExecutionFilter();
1✔
699
    if (executionFilter != null
1✔
700
        && executionFilter.isSetWorkflowId()
×
701
        && !executionFilter.getWorkflowId().isEmpty()) {
×
702
      workflowIdFilter = Optional.of(executionFilter.getWorkflowId());
×
703
    } else {
704
      workflowIdFilter = Optional.empty();
1✔
705
    }
706
    List<WorkflowExecutionInfo> result = store.listWorkflows(WorkflowState.OPEN, workflowIdFilter);
1✔
707
    return new ListOpenWorkflowExecutionsResponse().setExecutions(result);
1✔
708
  }
709

710
  @Override
711
  public ListClosedWorkflowExecutionsResponse ListClosedWorkflowExecutions(
712
      ListClosedWorkflowExecutionsRequest listRequest)
713
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
714
          TException {
715
    Optional<String> workflowIdFilter;
716
    WorkflowExecutionFilter executionFilter = listRequest.getExecutionFilter();
1✔
717
    if (executionFilter != null
1✔
718
        && executionFilter.isSetWorkflowId()
1✔
719
        && !executionFilter.getWorkflowId().isEmpty()) {
1✔
720
      workflowIdFilter = Optional.of(executionFilter.getWorkflowId());
1✔
721
    } else {
722
      workflowIdFilter = Optional.empty();
1✔
723
    }
724
    List<WorkflowExecutionInfo> result =
1✔
725
        store.listWorkflows(WorkflowState.CLOSED, workflowIdFilter);
1✔
726
    return new ListClosedWorkflowExecutionsResponse().setExecutions(result);
1✔
727
  }
728

729
  @Override
730
  public ListWorkflowExecutionsResponse ListWorkflowExecutions(
731
      ListWorkflowExecutionsRequest listRequest)
732
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
733
          ClientVersionNotSupportedError, TException {
734
    throw new UnsupportedOperationException("not implemented");
×
735
  }
736

737
  @Override
738
  public ListArchivedWorkflowExecutionsResponse ListArchivedWorkflowExecutions(
739
      ListArchivedWorkflowExecutionsRequest listRequest)
740
      throws BadRequestError, EntityNotExistsError, ServiceBusyError,
741
          ClientVersionNotSupportedError, TException {
742
    throw new UnsupportedOperationException("not implemented");
×
743
  }
744

745
  @Override
746
  public ListWorkflowExecutionsResponse ScanWorkflowExecutions(
747
      ListWorkflowExecutionsRequest listRequest)
748
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
749
          ClientVersionNotSupportedError, TException {
750
    throw new UnsupportedOperationException("not implemented");
×
751
  }
752

753
  @Override
754
  public CountWorkflowExecutionsResponse CountWorkflowExecutions(
755
      CountWorkflowExecutionsRequest countRequest)
756
      throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
757
          ClientVersionNotSupportedError, TException {
758
    throw new UnsupportedOperationException("not implemented");
×
759
  }
760

761
  @Override
762
  public GetSearchAttributesResponse GetSearchAttributes()
763
      throws InternalServiceError, ServiceBusyError, ClientVersionNotSupportedError, TException {
764
    throw new UnsupportedOperationException("not implemented");
×
765
  }
766

767
  @Override
768
  public void RespondQueryTaskCompleted(RespondQueryTaskCompletedRequest completeRequest)
769
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
770
    QueryId queryId = QueryId.fromBytes(completeRequest.getTaskToken());
1✔
771
    TestWorkflowMutableState mutableState = getMutableState(queryId.getExecutionId());
1✔
772
    mutableState.completeQuery(queryId, completeRequest);
1✔
773
  }
1✔
774

775
  @Override
776
  public ResetStickyTaskListResponse ResetStickyTaskList(ResetStickyTaskListRequest resetRequest)
777
      throws BadRequestError, InternalServiceError, EntityNotExistsError, LimitExceededError,
778
          ServiceBusyError, DomainNotActiveError, TException {
779
    throw new UnsupportedOperationException("not implemented");
×
780
  }
781

782
  @Override
783
  public QueryWorkflowResponse QueryWorkflow(QueryWorkflowRequest queryRequest)
784
      throws BadRequestError, InternalServiceError, EntityNotExistsError, QueryFailedError,
785
          TException {
786
    ExecutionId executionId =
1✔
787
        new ExecutionId(queryRequest.getDomain(), queryRequest.getExecution());
1✔
788
    TestWorkflowMutableState mutableState = getMutableState(executionId);
1✔
789
    return mutableState.query(queryRequest);
1✔
790
  }
791

792
  @Override
793
  public DescribeWorkflowExecutionResponse DescribeWorkflowExecution(
794
      DescribeWorkflowExecutionRequest describeRequest)
795
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
796
    throw new UnsupportedOperationException("not implemented");
×
797
  }
798

799
  @Override
800
  public DescribeTaskListResponse DescribeTaskList(DescribeTaskListRequest request)
801
      throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
802
    throw new UnsupportedOperationException("not implemented");
×
803
  }
804

805
  @Override
806
  public ClusterInfo GetClusterInfo() throws InternalServiceError, ServiceBusyError, TException {
807
    throw new UnsupportedOperationException("not implemented");
×
808
  }
809

810
  @Override
811
  public ListTaskListPartitionsResponse ListTaskListPartitions(
812
      ListTaskListPartitionsRequest request)
813
      throws BadRequestError, EntityNotExistsError, LimitExceededError, ServiceBusyError,
814
          TException {
815
    throw new UnsupportedOperationException("not implemented");
×
816
  }
817

818
  @Override
819
  public void RefreshWorkflowTasks(RefreshWorkflowTasksRequest request)
820
      throws BadRequestError, DomainNotActiveError, ServiceBusyError, EntityNotExistsError,
821
          TException {
822
    throw new UnsupportedOperationException("not implemented");
×
823
  }
824

825
  @Override
826
  public void RegisterDomain(
827
      RegisterDomainRequest registerRequest, AsyncMethodCallback resultHandler) throws TException {
828
    throw new UnsupportedOperationException("not implemented");
×
829
  }
830

831
  @Override
832
  public void DescribeDomain(
833
      DescribeDomainRequest describeRequest, AsyncMethodCallback resultHandler) throws TException {
834
    throw new UnsupportedOperationException("not implemented");
×
835
  }
836

837
  @Override
838
  public void ListDomains(ListDomainsRequest listRequest, AsyncMethodCallback resultHandler)
839
      throws TException {
840
    throw new UnsupportedOperationException("not implemented");
×
841
  }
842

843
  @Override
844
  public void UpdateDomain(UpdateDomainRequest updateRequest, AsyncMethodCallback resultHandler)
845
      throws TException {
846
    throw new UnsupportedOperationException("not implemented");
×
847
  }
848

849
  @Override
850
  public void DeprecateDomain(
851
      DeprecateDomainRequest deprecateRequest, AsyncMethodCallback resultHandler)
852
      throws TException {
853
    throw new UnsupportedOperationException("not implemented");
×
854
  }
855

856
  @Override
857
  public void RestartWorkflowExecution(
858
      RestartWorkflowExecutionRequest restartRequest, AsyncMethodCallback resultHandler)
859
      throws TException {
860
    throw new UnsupportedOperationException("not implemented");
×
861
  }
862

863
  @Override
864
  public void GetTaskListsByDomain(
865
      GetTaskListsByDomainRequest request, AsyncMethodCallback resultHandler)
866
      throws org.apache.thrift.TException {
867
    throw new UnsupportedOperationException("not implemented");
×
868
  }
869

870
  @Override
871
  public void StartWorkflowExecution(
872
      StartWorkflowExecutionRequest startRequest, AsyncMethodCallback resultHandler)
873
      throws TException {
874
    StartWorkflowExecutionWithTimeout(startRequest, resultHandler, null);
×
875
  }
×
876

877
  @Override
878
  public void StartWorkflowExecutionWithTimeout(
879
      StartWorkflowExecutionRequest startRequest,
880
      AsyncMethodCallback resultHandler,
881
      Long timeoutInMillis)
882
      throws TException {
883
    forkJoinPool.execute(
1✔
884
        () -> {
885
          try {
886
            StartWorkflowExecutionResponse result = StartWorkflowExecution(startRequest);
1✔
887
            resultHandler.onComplete(result);
1✔
888
          } catch (TException e) {
1✔
889
            resultHandler.onError(e);
1✔
890
          }
1✔
891
        });
1✔
892
  }
1✔
893

894
  @Override
895
  public void StartWorkflowExecutionAsync(
896
      StartWorkflowExecutionAsyncRequest startRequest, AsyncMethodCallback resultHandler)
897
      throws TException {
898
    StartWorkflowExecutionAsyncWithTimeout(startRequest, resultHandler, null);
×
899
  }
×
900

901
  @Override
902
  public void StartWorkflowExecutionAsyncWithTimeout(
903
      StartWorkflowExecutionAsyncRequest startAsyncRequest,
904
      AsyncMethodCallback resultHandler,
905
      Long timeoutInMillis)
906
      throws TException {
907
    // Treat it like a synchronous call but ignore the result
908
    StartWorkflowExecutionWithTimeout(
×
909
        startAsyncRequest.getRequest(),
×
910
        new AsyncMethodCallback() {
×
911
          @Override
912
          public void onComplete(Object response) {
913
            // Noop
914
          }
×
915

916
          @Override
917
          public void onError(Exception exception) {
918
            // Noop
919
          }
×
920
        },
921
        timeoutInMillis);
922
    resultHandler.onComplete(new StartWorkflowExecutionAsyncResponse());
×
923
  }
×
924

925
  @SuppressWarnings("unchecked") // Generator ignores that AsyncMethodCallback is generic
926
  @Override
927
  public void GetWorkflowExecutionHistory(
928
      GetWorkflowExecutionHistoryRequest getRequest, AsyncMethodCallback resultHandler)
929
      throws TException {
930
    forkJoinPool.execute(
1✔
931
        () -> {
932
          try {
933
            GetWorkflowExecutionHistoryResponse result = GetWorkflowExecutionHistory(getRequest);
1✔
934
            resultHandler.onComplete(result);
1✔
935
          } catch (TException e) {
×
936
            resultHandler.onError(e);
×
937
          }
1✔
938
        });
1✔
939
  }
1✔
940

941
  @SuppressWarnings("unchecked") // Generator ignores that AsyncMethodCallback is generic
942
  @Override
943
  public void GetWorkflowExecutionHistoryWithTimeout(
944
      GetWorkflowExecutionHistoryRequest getRequest,
945
      AsyncMethodCallback resultHandler,
946
      Long timeoutInMillis)
947
      throws TException {
948
    GetWorkflowExecutionHistory(getRequest, resultHandler);
1✔
949
  }
1✔
950

951
  @Override
952
  public CompletableFuture<Boolean> isHealthy() {
953
    CompletableFuture<Boolean> rval = new CompletableFuture<>();
×
954
    rval.complete(Boolean.TRUE);
×
955
    return rval;
×
956
  }
957

958
  @Override
959
  public void PollForDecisionTask(
960
      PollForDecisionTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws TException {
961
    throw new UnsupportedOperationException("not implemented");
×
962
  }
963

964
  @Override
965
  public void RespondDecisionTaskCompleted(
966
      RespondDecisionTaskCompletedRequest completeRequest, AsyncMethodCallback resultHandler)
967
      throws TException {
968
    throw new UnsupportedOperationException("not implemented");
×
969
  }
970

971
  @Override
972
  public void RespondDecisionTaskFailed(
973
      RespondDecisionTaskFailedRequest failedRequest, AsyncMethodCallback resultHandler)
974
      throws TException {
975
    throw new UnsupportedOperationException("not implemented");
×
976
  }
977

978
  @Override
979
  public void PollForActivityTask(
980
      PollForActivityTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws TException {
981
    throw new UnsupportedOperationException("not implemented");
×
982
  }
983

984
  @Override
985
  public void RecordActivityTaskHeartbeat(
986
      RecordActivityTaskHeartbeatRequest heartbeatRequest, AsyncMethodCallback resultHandler)
987
      throws TException {
988
    throw new UnsupportedOperationException("not implemented");
×
989
  }
990

991
  @Override
992
  public void RecordActivityTaskHeartbeatByID(
993
      RecordActivityTaskHeartbeatByIDRequest heartbeatRequest, AsyncMethodCallback resultHandler)
994
      throws TException {
995
    throw new UnsupportedOperationException("not implemented");
×
996
  }
997

998
  @Override
999
  public void RespondActivityTaskCompleted(
1000
      RespondActivityTaskCompletedRequest completeRequest, AsyncMethodCallback resultHandler)
1001
      throws TException {
1002
    throw new UnsupportedOperationException("not implemented");
×
1003
  }
1004

1005
  @Override
1006
  public void RespondActivityTaskCompletedByID(
1007
      RespondActivityTaskCompletedByIDRequest completeRequest, AsyncMethodCallback resultHandler)
1008
      throws TException {
1009
    throw new UnsupportedOperationException("not implemented");
×
1010
  }
1011

1012
  @Override
1013
  public void RespondActivityTaskFailed(
1014
      RespondActivityTaskFailedRequest failRequest, AsyncMethodCallback resultHandler)
1015
      throws TException {
1016
    throw new UnsupportedOperationException("not implemented");
×
1017
  }
1018

1019
  @Override
1020
  public void RespondActivityTaskFailedByID(
1021
      RespondActivityTaskFailedByIDRequest failRequest, AsyncMethodCallback resultHandler)
1022
      throws TException {
1023
    throw new UnsupportedOperationException("not implemented");
×
1024
  }
1025

1026
  @Override
1027
  public void RespondActivityTaskCanceled(
1028
      RespondActivityTaskCanceledRequest canceledRequest, AsyncMethodCallback resultHandler)
1029
      throws TException {
1030
    throw new UnsupportedOperationException("not implemented");
×
1031
  }
1032

1033
  @Override
1034
  public void RespondActivityTaskCanceledByID(
1035
      RespondActivityTaskCanceledByIDRequest canceledRequest, AsyncMethodCallback resultHandler)
1036
      throws TException {
1037
    throw new UnsupportedOperationException("not implemented");
×
1038
  }
1039

1040
  @Override
1041
  public void RequestCancelWorkflowExecution(
1042
      RequestCancelWorkflowExecutionRequest cancelRequest, AsyncMethodCallback resultHandler)
1043
      throws TException {
1044
    throw new UnsupportedOperationException("not implemented");
×
1045
  }
1046

1047
  @Override
1048
  public void SignalWorkflowExecution(
1049
      SignalWorkflowExecutionRequest signalRequest, AsyncMethodCallback resultHandler)
1050
      throws TException {
1051
    SignalWorkflowExecutionWithTimeout(signalRequest, resultHandler, null);
1✔
1052
  }
1✔
1053

1054
  @Override
1055
  public void SignalWorkflowExecutionWithTimeout(
1056
      SignalWorkflowExecutionRequest signalRequest,
1057
      AsyncMethodCallback resultHandler,
1058
      Long timeoutInMillis)
1059
      throws TException {
1060
    forkJoinPool.execute(
1✔
1061
        () -> {
1062
          try {
1063
            SignalWorkflowExecution(signalRequest);
1✔
1064
            resultHandler.onComplete(null);
1✔
1065
          } catch (TException e) {
×
1066
            resultHandler.onError(e);
×
1067
          }
1✔
1068
        });
1✔
1069
  }
1✔
1070

1071
  @Override
1072
  public void SignalWithStartWorkflowExecution(
1073
      SignalWithStartWorkflowExecutionRequest signalWithStartRequest,
1074
      AsyncMethodCallback resultHandler)
1075
      throws TException {
1076
    throw new UnsupportedOperationException("not implemented");
×
1077
  }
1078

1079
  @Override
1080
  public void SignalWithStartWorkflowExecutionAsync(
1081
      SignalWithStartWorkflowExecutionAsyncRequest signalWithStartRequest,
1082
      AsyncMethodCallback resultHandler)
1083
      throws TException {
1084
    throw new UnsupportedOperationException("not implemented");
×
1085
  }
1086

1087
  @Override
1088
  public void ResetWorkflowExecution(
1089
      ResetWorkflowExecutionRequest resetRequest, AsyncMethodCallback resultHandler)
1090
      throws TException {}
×
1091

1092
  @Override
1093
  public void TerminateWorkflowExecution(
1094
      TerminateWorkflowExecutionRequest terminateRequest, AsyncMethodCallback resultHandler)
1095
      throws TException {
1096
    throw new UnsupportedOperationException("not implemented");
×
1097
  }
1098

1099
  @Override
1100
  public void ListOpenWorkflowExecutions(
1101
      ListOpenWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler)
1102
      throws TException {
1103
    throw new UnsupportedOperationException("not implemented");
×
1104
  }
1105

1106
  @Override
1107
  public void ListClosedWorkflowExecutions(
1108
      ListClosedWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler)
1109
      throws TException {
1110
    throw new UnsupportedOperationException("not implemented");
×
1111
  }
1112

1113
  @Override
1114
  public void ListWorkflowExecutions(
1115
      ListWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler)
1116
      throws TException {
1117
    throw new UnsupportedOperationException("not implemented");
×
1118
  }
1119

1120
  @Override
1121
  public void ListArchivedWorkflowExecutions(
1122
      ListArchivedWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler)
1123
      throws TException {}
×
1124

1125
  @Override
1126
  public void ScanWorkflowExecutions(
1127
      ListWorkflowExecutionsRequest listRequest, AsyncMethodCallback resultHandler)
1128
      throws TException {
1129
    throw new UnsupportedOperationException("not implemented");
×
1130
  }
1131

1132
  @Override
1133
  public void CountWorkflowExecutions(
1134
      CountWorkflowExecutionsRequest countRequest, AsyncMethodCallback resultHandler)
1135
      throws TException {
1136
    throw new UnsupportedOperationException("not implemented");
×
1137
  }
1138

1139
  @Override
1140
  public void GetSearchAttributes(AsyncMethodCallback resultHandler) throws TException {
1141
    throw new UnsupportedOperationException("not implemented");
×
1142
  }
1143

1144
  @Override
1145
  public void RespondQueryTaskCompleted(
1146
      RespondQueryTaskCompletedRequest completeRequest, AsyncMethodCallback resultHandler)
1147
      throws TException {
1148
    throw new UnsupportedOperationException("not implemented");
×
1149
  }
1150

1151
  @Override
1152
  public void ResetStickyTaskList(
1153
      ResetStickyTaskListRequest resetRequest, AsyncMethodCallback resultHandler)
1154
      throws TException {
1155
    throw new UnsupportedOperationException("not implemented");
×
1156
  }
1157

1158
  @Override
1159
  public void QueryWorkflow(QueryWorkflowRequest queryRequest, AsyncMethodCallback resultHandler)
1160
      throws TException {
1161
    throw new UnsupportedOperationException("not implemented");
×
1162
  }
1163

1164
  @Override
1165
  public void DescribeWorkflowExecution(
1166
      DescribeWorkflowExecutionRequest describeRequest, AsyncMethodCallback resultHandler)
1167
      throws TException {
1168
    throw new UnsupportedOperationException("not implemented");
×
1169
  }
1170

1171
  @Override
1172
  public void DescribeTaskList(DescribeTaskListRequest request, AsyncMethodCallback resultHandler)
1173
      throws TException {
1174
    throw new UnsupportedOperationException("not implemented");
×
1175
  }
1176

1177
  @Override
1178
  public void GetClusterInfo(AsyncMethodCallback resultHandler) throws TException {}
×
1179

1180
  @Override
1181
  public void ListTaskListPartitions(
1182
      ListTaskListPartitionsRequest request, AsyncMethodCallback resultHandler) throws TException {}
×
1183

1184
  @Override
1185
  public void RefreshWorkflowTasks(
1186
      RefreshWorkflowTasksRequest request, AsyncMethodCallback resultHandler) throws TException {}
×
1187

1188
  private <R> R requireNotNull(String fieldName, R value) throws BadRequestError {
1189
    if (value == null) {
1✔
1190
      throw new BadRequestError("Missing requried field \"" + fieldName + "\".");
×
1191
    }
1192
    return value;
1✔
1193
  }
1194

1195
  /**
1196
   * Adds diagnostic data about internal service state to the provided {@link StringBuilder}.
1197
   * Currently includes histories of all workflow instances stored in the service.
1198
   */
1199
  public void getDiagnostics(StringBuilder result) {
1200
    store.getDiagnostics(result);
1✔
1201
  }
1✔
1202

1203
  public long currentTimeMillis() {
1204
    return store.getTimer().getClock().getAsLong();
1✔
1205
  }
1206

1207
  /** Invokes callback after the specified delay according to internal service clock. */
1208
  public void registerDelayedCallback(Duration delay, Runnable r) {
1209
    store.registerDelayedCallback(delay, r);
1✔
1210
  }
1✔
1211

1212
  /**
1213
   * Disables time skipping. To enable back call {@link #unlockTimeSkipping(String)}. These calls
1214
   * are counted, so calling unlock does not guarantee that time is going to be skipped immediately
1215
   * as another lock can be holding it.
1216
   */
1217
  public void lockTimeSkipping(String caller) {
1218
    store.getTimer().lockTimeSkipping(caller);
1✔
1219
  }
1✔
1220

1221
  public void unlockTimeSkipping(String caller) {
1222
    store.getTimer().unlockTimeSkipping(caller);
1✔
1223
  }
1✔
1224

1225
  /**
1226
   * Blocks calling thread until internal clock doesn't pass the current + duration time. Might not
1227
   * block at all due to time skipping.
1228
   */
1229
  public void sleep(Duration duration) {
1230
    CompletableFuture<Void> result = new CompletableFuture<>();
1✔
1231
    store
1✔
1232
        .getTimer()
1✔
1233
        .schedule(
1✔
1234
            duration,
1235
            () -> {
1236
              store.getTimer().lockTimeSkipping("TestWorkflowService sleep");
1✔
1237
              result.complete(null);
1✔
1238
            },
1✔
1239
            "workflow sleep");
1240
    store.getTimer().unlockTimeSkipping("TestWorkflowService sleep");
1✔
1241
    try {
1242
      result.get();
1✔
1243
    } catch (InterruptedException e) {
×
1244
      throw new RuntimeException(e);
×
1245
    } catch (ExecutionException e) {
×
1246
      throw new RuntimeException(e);
×
1247
    }
1✔
1248
  }
1✔
1249
}
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