• 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

77.42
/src/main/java/com/uber/cadence/internal/replay/ActivityDecisionStateMachine.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.RequestCancelActivityTaskDecisionAttributes;
24
import com.uber.cadence.ScheduleActivityTaskDecisionAttributes;
25

26
final class ActivityDecisionStateMachine extends DecisionStateMachineBase {
27

28
  private ScheduleActivityTaskDecisionAttributes scheduleAttributes;
29

30
  public ActivityDecisionStateMachine(
31
      DecisionId id, ScheduleActivityTaskDecisionAttributes scheduleAttributes) {
32
    super(id);
1✔
33
    this.scheduleAttributes = scheduleAttributes;
1✔
34
  }
1✔
35

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

48
  @Override
49
  public void handleDecisionTaskStartedEvent() {
50
    switch (state) {
1✔
51
      case CANCELED_AFTER_INITIATED:
52
        stateHistory.add("handleDecisionTaskStartedEvent");
1✔
53
        state = DecisionState.CANCELLATION_DECISION_SENT;
1✔
54
        stateHistory.add(state.toString());
1✔
55
        break;
1✔
56
      default:
57
        super.handleDecisionTaskStartedEvent();
1✔
58
    }
59
  }
1✔
60

61
  @Override
62
  public void handleCancellationFailureEvent(HistoryEvent event) {
63
    switch (state) {
×
64
      case CANCELLATION_DECISION_SENT:
65
        stateHistory.add("handleCancellationFailureEvent");
×
66
        state = DecisionState.INITIATED;
×
67
        stateHistory.add(state.toString());
×
68
        break;
×
69
      default:
70
        super.handleCancellationFailureEvent(event);
×
71
    }
72
  }
×
73

74
  private Decision createRequestCancelActivityTaskDecision() {
75
    RequestCancelActivityTaskDecisionAttributes tryCancel =
1✔
76
        new RequestCancelActivityTaskDecisionAttributes();
77
    tryCancel.setActivityId(scheduleAttributes.getActivityId());
1✔
78
    Decision decision = new Decision();
1✔
79
    decision.setRequestCancelActivityTaskDecisionAttributes(tryCancel);
1✔
80
    decision.setDecisionType(DecisionType.RequestCancelActivityTask);
1✔
81
    return decision;
1✔
82
  }
83

84
  private Decision createScheduleActivityTaskDecision() {
85
    Decision decision = new Decision();
1✔
86
    decision.setScheduleActivityTaskDecisionAttributes(scheduleAttributes);
1✔
87
    decision.setDecisionType(DecisionType.ScheduleActivityTask);
1✔
88
    return decision;
1✔
89
  }
90
}
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