• 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

67.35
/src/main/java/com/uber/cadence/internal/replay/SignalDecisionStateMachine.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.Decision;
21
import com.uber.cadence.DecisionType;
22
import com.uber.cadence.HistoryEvent;
23
import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes;
24

25
class SignalDecisionStateMachine extends DecisionStateMachineBase {
26

27
  private SignalExternalWorkflowExecutionDecisionAttributes attributes;
28

29
  private boolean canceled;
30

31
  public SignalDecisionStateMachine(
32
      DecisionId id, SignalExternalWorkflowExecutionDecisionAttributes attributes) {
33
    super(id);
1✔
34
    this.attributes = attributes;
1✔
35
  }
1✔
36

37
  @Override
38
  public Decision getDecision() {
39
    switch (state) {
1✔
40
      case CREATED:
41
        return createSignalExternalWorkflowExecutionDecision();
1✔
42
      default:
43
        return null;
1✔
44
    }
45
  }
46

47
  @Override
48
  public boolean isDone() {
49
    return state == DecisionState.COMPLETED || canceled;
1✔
50
  }
51

52
  @Override
53
  public boolean cancel(Runnable immediateCancellationCallback) {
54
    stateHistory.add("cancel");
1✔
55
    boolean result = false;
1✔
56
    switch (state) {
1✔
57
      case CREATED:
58
      case INITIATED:
59
        state = DecisionState.COMPLETED;
1✔
60
        if (immediateCancellationCallback != null) {
1✔
61
          immediateCancellationCallback.run();
×
62
        }
63
        result = true;
1✔
64
        break;
1✔
65
      case DECISION_SENT:
66
        state = DecisionState.CANCELED_BEFORE_INITIATED;
×
67
        if (immediateCancellationCallback != null) {
×
68
          immediateCancellationCallback.run();
×
69
        }
70
        result = true;
×
71
        break;
×
72
      default:
73
        failStateTransition();
×
74
    }
75
    canceled = true;
1✔
76
    stateHistory.add(state.toString());
1✔
77
    return result;
1✔
78
  }
79

80
  @Override
81
  public void handleInitiatedEvent(HistoryEvent event) {
82
    stateHistory.add("handleInitiatedEvent");
1✔
83
    switch (state) {
1✔
84
      case DECISION_SENT:
85
        state = DecisionState.INITIATED;
1✔
86
        break;
1✔
87
      case CANCELED_BEFORE_INITIATED:
88
        // No state change
89
        break;
×
90
      default:
91
        failStateTransition();
×
92
    }
93
    stateHistory.add(state.toString());
1✔
94
  }
1✔
95

96
  @Override
97
  public void handleInitiationFailedEvent(HistoryEvent event) {
98
    throw new UnsupportedOperationException();
×
99
  }
100

101
  @Override
102
  public void handleStartedEvent(HistoryEvent event) {
103
    throw new UnsupportedOperationException();
×
104
  }
105

106
  @Override
107
  public void handleCompletionEvent() {
108
    stateHistory.add("handleCompletionEvent");
1✔
109
    switch (state) {
1✔
110
      case DECISION_SENT:
111
      case INITIATED:
112
      case CANCELED_BEFORE_INITIATED:
113
        state = DecisionState.COMPLETED;
1✔
114
        break;
1✔
115
      case COMPLETED:
116
        // No state change
117
        break;
×
118
      default:
119
        failStateTransition();
×
120
    }
121
    stateHistory.add(state.toString());
1✔
122
  }
1✔
123

124
  @Override
125
  public void handleCancellationInitiatedEvent() {
126
    throw new UnsupportedOperationException();
×
127
  }
128

129
  @Override
130
  public void handleCancellationFailureEvent(HistoryEvent event) {
131
    throw new UnsupportedOperationException();
×
132
  }
133

134
  @Override
135
  public void handleCancellationEvent() {
136
    throw new UnsupportedOperationException();
×
137
  }
138

139
  private Decision createSignalExternalWorkflowExecutionDecision() {
140
    Decision decision = new Decision();
1✔
141
    decision.setSignalExternalWorkflowExecutionDecisionAttributes(attributes);
1✔
142
    decision.setDecisionType(DecisionType.SignalExternalWorkflowExecution);
1✔
143
    return decision;
1✔
144
  }
145
}
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