• 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

54.39
/src/main/java/com/uber/cadence/internal/replay/ChildWorkflowDecisionStateMachine.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.RequestCancelExternalWorkflowExecutionDecisionAttributes;
24
import com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes;
25

26
final class ChildWorkflowDecisionStateMachine extends DecisionStateMachineBase {
27

28
  private StartChildWorkflowExecutionDecisionAttributes startAttributes;
29

30
  public ChildWorkflowDecisionStateMachine(
31
      DecisionId id, StartChildWorkflowExecutionDecisionAttributes startAttributes) {
32
    super(id);
1✔
33
    this.startAttributes = startAttributes;
1✔
34
  }
1✔
35

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

48
  @Override
49
  public void handleDecisionTaskStartedEvent() {
50
    switch (state) {
1✔
51
      case CANCELED_AFTER_STARTED:
52
        state = DecisionState.CANCELLATION_DECISION_SENT;
×
53
        break;
×
54
      default:
55
        super.handleDecisionTaskStartedEvent();
1✔
56
    }
57
  }
1✔
58

59
  @Override
60
  public void handleStartedEvent(HistoryEvent event) {
61
    stateHistory.add("handleStartedEvent");
1✔
62
    switch (state) {
1✔
63
      case INITIATED:
64
        state = DecisionState.STARTED;
1✔
65
        break;
1✔
66
      case CANCELED_AFTER_INITIATED:
67
        state = DecisionState.CANCELED_AFTER_STARTED;
×
68
        break;
×
69
      default:
70
    }
71
    stateHistory.add(state.toString());
1✔
72
  }
1✔
73

74
  @Override
75
  public void handleCancellationFailureEvent(HistoryEvent event) {
76
    switch (state) {
×
77
      case CANCELLATION_DECISION_SENT:
78
        stateHistory.add("handleCancellationFailureEvent");
×
79
        state = DecisionState.STARTED;
×
80
        stateHistory.add(state.toString());
×
81
        break;
×
82
      default:
83
        super.handleCancellationFailureEvent(event);
×
84
    }
85
  }
×
86

87
  @Override
88
  public boolean cancel(Runnable immediateCancellationCallback) {
89
    switch (state) {
×
90
      case STARTED:
91
        stateHistory.add("cancel");
×
92
        state = DecisionState.CANCELED_AFTER_STARTED;
×
93
        stateHistory.add(state.toString());
×
94
        return true;
×
95
      default:
96
        return super.cancel(immediateCancellationCallback);
×
97
    }
98
  }
99

100
  @Override
101
  public void handleCancellationEvent() {
102
    switch (state) {
1✔
103
      case STARTED:
104
        stateHistory.add("handleCancellationEvent");
1✔
105
        state = DecisionState.COMPLETED;
1✔
106
        stateHistory.add(state.toString());
1✔
107
        break;
1✔
108
      default:
109
        super.handleCancellationEvent();
×
110
    }
111
  }
1✔
112

113
  @Override
114
  public void handleCompletionEvent() {
115
    switch (state) {
1✔
116
      case STARTED:
117
      case CANCELED_AFTER_STARTED:
118
        stateHistory.add("handleCompletionEvent");
1✔
119
        state = DecisionState.COMPLETED;
1✔
120
        stateHistory.add(state.toString());
1✔
121
        break;
1✔
122
      default:
123
        super.handleCompletionEvent();
×
124
    }
125
  }
1✔
126

127
  private Decision createRequestCancelExternalWorkflowExecutionDecision() {
128
    RequestCancelExternalWorkflowExecutionDecisionAttributes tryCancel =
×
129
        new RequestCancelExternalWorkflowExecutionDecisionAttributes();
130
    tryCancel.setWorkflowId(startAttributes.getWorkflowId());
×
131
    Decision decision = new Decision();
×
132
    decision.setRequestCancelExternalWorkflowExecutionDecisionAttributes(tryCancel);
×
133
    decision.setDecisionType(DecisionType.RequestCancelExternalWorkflowExecution);
×
134
    return decision;
×
135
  }
136

137
  private Decision createStartChildWorkflowExecutionDecision() {
138
    Decision decision = new Decision();
1✔
139
    decision.setStartChildWorkflowExecutionDecisionAttributes(startAttributes);
1✔
140
    decision.setDecisionType(DecisionType.StartChildWorkflowExecution);
1✔
141
    return decision;
1✔
142
  }
143
}
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