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

uber / cadence-java-client / 2555

24 Oct 2024 10:50PM UTC coverage: 66.622% (+0.4%) from 66.195%
2555

push

buildkite

web-flow
Refactor Test environment initialization to CadenceTestRule from WorkflowTest. (#923)

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.

12910 of 19378 relevant lines covered (66.62%)

0.67 hits per line

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

80.0
/src/main/java/com/uber/cadence/internal/replay/TimerDecisionStateMachine.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.replay;
19

20
import com.uber.cadence.CancelTimerDecisionAttributes;
21
import com.uber.cadence.Decision;
22
import com.uber.cadence.DecisionType;
23
import com.uber.cadence.HistoryEvent;
24
import com.uber.cadence.StartTimerDecisionAttributes;
25

26
/**
27
 * Timer doesn't have separate initiation decision as it is started immediately. But from the state
28
 * machine point of view it is modeled the same as activity with no TimerStarted event used as
29
 * initiation event.
30
 *
31
 * @author fateev
32
 */
33
class TimerDecisionStateMachine extends DecisionStateMachineBase {
34

35
  private StartTimerDecisionAttributes attributes;
36

37
  private boolean canceled;
38

39
  public TimerDecisionStateMachine(DecisionId id, StartTimerDecisionAttributes attributes) {
40
    super(id);
1✔
41
    this.attributes = attributes;
1✔
42
  }
1✔
43

44
  @Override
45
  public Decision getDecision() {
46
    switch (state) {
1✔
47
      case CREATED:
48
        return createStartTimerDecision();
1✔
49
      case CANCELED_AFTER_INITIATED:
50
        return createCancelTimerDecision();
1✔
51
      default:
52
        return null;
1✔
53
    }
54
  }
55

56
  @Override
57
  public void handleDecisionTaskStartedEvent() {
58
    switch (state) {
1✔
59
      case CANCELED_AFTER_INITIATED:
60
        stateHistory.add("handleDecisionTaskStartedEvent");
1✔
61
        state = DecisionState.CANCELLATION_DECISION_SENT;
1✔
62
        stateHistory.add(state.toString());
1✔
63
        break;
1✔
64
      default:
65
        super.handleDecisionTaskStartedEvent();
1✔
66
    }
67
  }
1✔
68

69
  @Override
70
  public void handleCancellationFailureEvent(HistoryEvent event) {
71
    switch (state) {
×
72
      case CANCELLATION_DECISION_SENT:
73
        stateHistory.add("handleCancellationFailureEvent");
×
74
        state = DecisionState.INITIATED;
×
75
        stateHistory.add(state.toString());
×
76
        break;
×
77
      default:
78
        super.handleCancellationFailureEvent(event);
×
79
    }
80
  }
×
81

82
  @Override
83
  public boolean cancel(Runnable immediateCancellationCallback) {
84
    canceled = true;
1✔
85
    immediateCancellationCallback.run();
1✔
86
    return super.cancel(null);
1✔
87
  }
88

89
  /**
90
   * As timer is canceled immediately there is no need for waiting after cancellation decision was
91
   * sent.
92
   */
93
  @Override
94
  public boolean isDone() {
95
    return state == DecisionState.COMPLETED || canceled;
1✔
96
  }
97

98
  private Decision createCancelTimerDecision() {
99
    CancelTimerDecisionAttributes tryCancel = new CancelTimerDecisionAttributes();
1✔
100
    tryCancel.setTimerId(attributes.getTimerId());
1✔
101
    Decision decision = new Decision();
1✔
102
    decision.setCancelTimerDecisionAttributes(tryCancel);
1✔
103
    decision.setDecisionType(DecisionType.CancelTimer);
1✔
104
    return decision;
1✔
105
  }
106

107
  private Decision createStartTimerDecision() {
108
    Decision decision = new Decision();
1✔
109
    decision.setStartTimerDecisionAttributes(attributes);
1✔
110
    decision.setDecisionType(DecisionType.StartTimer);
1✔
111
    return decision;
1✔
112
  }
113
}
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