Skip to content

Commit 1d0e355

Browse files
authored
Add unit tests for ContinueAsNewWorkflowExecutionParameters (#947)
1 parent b5d8ef8 commit 1d0e355

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

src/main/java/com/uber/cadence/internal/replay/ContinueAsNewWorkflowExecutionParameters.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public String toString() {
9797
sb.append("ExecutionStartToCloseTimeout: " + executionStartToCloseTimeoutSeconds + ", ");
9898
sb.append("TaskStartToCloseTimeout: " + taskStartToCloseTimeoutSeconds + ", ");
9999
sb.append("TaskList: " + taskList + ", ");
100+
sb.append("WorkflowType: " + workflowType + ", ");
100101
sb.append("}");
101102
return sb.toString();
102103
}
@@ -105,9 +106,10 @@ public ContinueAsNewWorkflowExecutionParameters copy() {
105106
ContinueAsNewWorkflowExecutionParameters result =
106107
new ContinueAsNewWorkflowExecutionParameters();
107108
result.setExecutionStartToCloseTimeoutSeconds(executionStartToCloseTimeoutSeconds);
108-
result.setInput(input);
109+
result.setInput(input.clone());
109110
result.setTaskList(taskList);
110111
result.setTaskStartToCloseTimeoutSeconds(taskStartToCloseTimeoutSeconds);
112+
result.setWorkflowType(workflowType);
111113
return result;
112114
}
113115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
7+
* except in compliance with the License. A copy of the License is located at
8+
*
9+
* <p>http://aws.amazon.com/apache2.0
10+
*
11+
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.internal.replay;
16+
17+
import static junit.framework.TestCase.assertEquals;
18+
import static junit.framework.TestCase.assertNotSame;
19+
import static junit.framework.TestCase.assertSame;
20+
import static junit.framework.TestCase.assertTrue;
21+
22+
import java.nio.charset.StandardCharsets;
23+
import java.util.Arrays;
24+
import org.junit.Test;
25+
26+
public class ContinueAsNewWorkflowExecutionParametersTest {
27+
@Test
28+
public void testGettersAndSetters() {
29+
ContinueAsNewWorkflowExecutionParameters parameters =
30+
new ContinueAsNewWorkflowExecutionParameters();
31+
parameters.setWorkflowType("wf-type");
32+
assertEquals("wf-type", parameters.getWorkflowType());
33+
34+
parameters.setExecutionStartToCloseTimeoutSeconds(1);
35+
assertEquals(1, parameters.getExecutionStartToCloseTimeoutSeconds());
36+
ContinueAsNewWorkflowExecutionParameters parameters1 =
37+
parameters.withExecutionStartToCloseTimeoutSeconds(2);
38+
assertEquals(2, parameters1.getExecutionStartToCloseTimeoutSeconds());
39+
assertSame(parameters, parameters1);
40+
41+
parameters.setInput(new byte[] {1, 2, 3});
42+
assertTrue(Arrays.equals(new byte[] {1, 2, 3}, parameters.getInput()));
43+
ContinueAsNewWorkflowExecutionParameters parameters2 =
44+
parameters.withInput(new byte[] {4, 5, 6});
45+
assertTrue(Arrays.equals(new byte[] {4, 5, 6}, parameters2.getInput()));
46+
assertSame(parameters, parameters2);
47+
48+
parameters.setTaskList("task-list");
49+
assertEquals("task-list", parameters.getTaskList());
50+
ContinueAsNewWorkflowExecutionParameters parameters3 = parameters.withTaskList("task-list1");
51+
assertEquals("task-list1", parameters3.getTaskList());
52+
assertSame(parameters, parameters3);
53+
54+
parameters.setTaskStartToCloseTimeoutSeconds(3);
55+
assertEquals(3, parameters.getTaskStartToCloseTimeoutSeconds());
56+
ContinueAsNewWorkflowExecutionParameters parameters4 =
57+
parameters.withTaskStartToCloseTimeoutSeconds(4);
58+
assertEquals(4, parameters4.getTaskStartToCloseTimeoutSeconds());
59+
assertSame(parameters, parameters4);
60+
}
61+
62+
@Test
63+
public void testToString() {
64+
ContinueAsNewWorkflowExecutionParameters params =
65+
new ContinueAsNewWorkflowExecutionParameters();
66+
byte[] input = new byte[600];
67+
Arrays.fill(input, (byte) 'a');
68+
params.setInput(input);
69+
params.setExecutionStartToCloseTimeoutSeconds(3600);
70+
params.setTaskStartToCloseTimeoutSeconds(30);
71+
params.setTaskList("TestTaskList");
72+
params.setWorkflowType("wf-type");
73+
74+
String expected =
75+
"{Input: "
76+
+ new String(input, 0, 512, StandardCharsets.UTF_8)
77+
+ ", "
78+
+ "ExecutionStartToCloseTimeout: 3600, "
79+
+ "TaskStartToCloseTimeout: 30, "
80+
+ "TaskList: TestTaskList, "
81+
+ "WorkflowType: wf-type, }";
82+
assertEquals(expected, params.toString());
83+
}
84+
85+
@Test
86+
public void testCopy() {
87+
ContinueAsNewWorkflowExecutionParameters params =
88+
new ContinueAsNewWorkflowExecutionParameters();
89+
params.setExecutionStartToCloseTimeoutSeconds(3600);
90+
params.setInput("Test input".getBytes(StandardCharsets.UTF_8));
91+
params.setTaskList("TestTaskList");
92+
params.setTaskStartToCloseTimeoutSeconds(30);
93+
params.setWorkflowType("TestWorkflowType");
94+
95+
ContinueAsNewWorkflowExecutionParameters copiedParams = params.copy();
96+
97+
assertEquals(3600, copiedParams.getExecutionStartToCloseTimeoutSeconds());
98+
assertTrue(
99+
Arrays.equals("Test input".getBytes(StandardCharsets.UTF_8), copiedParams.getInput()));
100+
assertEquals("TestTaskList", copiedParams.getTaskList());
101+
assertEquals(30, copiedParams.getTaskStartToCloseTimeoutSeconds());
102+
assertEquals("TestWorkflowType", copiedParams.getWorkflowType());
103+
104+
// Ensure deep copy for input array
105+
assertNotSame(params.getInput(), copiedParams.getInput());
106+
assertNotSame(params, copiedParams);
107+
}
108+
}

0 commit comments

Comments
 (0)