-
Notifications
You must be signed in to change notification settings - Fork 115
adds coverage to SignalExternalWorkflowParameters struct file's methods #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davidporter-id-au
merged 1 commit into
cadence-workflow:master
from
davidporter-id-au:bugfix/minor-coverage
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,10 +94,20 @@ public SignalExternalWorkflowParameters withWorkflowId(String workflowId) { | |
|
||
@Override | ||
public String toString() { | ||
|
||
String inputStr; | ||
if (input == null) { | ||
inputStr = ""; | ||
} else if (input.length > 512) { | ||
inputStr = new String(input, 0, 512, StandardCharsets.UTF_8); | ||
} else { | ||
inputStr = new String(input, StandardCharsets.UTF_8); | ||
} | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append("{"); | ||
sb.append("SignalName: " + signalName + ", "); | ||
sb.append("Input: " + new String(input, 0, 512, StandardCharsets.UTF_8) + ", "); | ||
sb.append("Input: " + inputStr + ", "); | ||
sb.append("WorkflowId: " + workflowId + ", "); | ||
sb.append("RunId: " + runId + ", "); | ||
sb.append("}"); | ||
|
@@ -108,6 +118,7 @@ public SignalExternalWorkflowParameters copy() { | |
SignalExternalWorkflowParameters result = new SignalExternalWorkflowParameters(); | ||
result.setInput(input); | ||
result.setRunId(runId); | ||
result.setDomain(domain); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this was missing also? |
||
result.setSignalName(signalName); | ||
result.setWorkflowId(workflowId); | ||
return result; | ||
|
190 changes: 190 additions & 0 deletions
190
src/test/java/com/uber/cadence/internal/replay/SignalExternalWorkflowParametersTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
/** | ||
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
* except in compliance with the License. A copy of the License is located at | ||
* | ||
* <p>http://aws.amazon.com/apache2.0 | ||
* | ||
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.uber.cadence.internal.replay; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.lang.reflect.Field; | ||
import java.nio.charset.StandardCharsets; | ||
import org.junit.Test; | ||
|
||
public class SignalExternalWorkflowParametersTest { | ||
|
||
@Test | ||
public void testSetAndGetDomain() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
params.setDomain("TestDomain"); | ||
assertEquals("TestDomain", params.getDomain()); | ||
} | ||
|
||
@Test | ||
public void testSetAndGetInput() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
byte[] input = "TestInput".getBytes(StandardCharsets.UTF_8); | ||
params.setInput(input); | ||
assertArrayEquals(input, params.getInput()); | ||
} | ||
|
||
@Test | ||
public void testWithInputChain() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
|
||
byte[] input = "ChainInput".getBytes(StandardCharsets.UTF_8); | ||
SignalExternalWorkflowParameters result = params.withInput(input); | ||
assertArrayEquals(input, params.getInput()); | ||
assertSame(params, result); | ||
} | ||
|
||
@Test | ||
public void testSetAndGetRunId() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
params.setRunId("TestRunId"); | ||
assertEquals("TestRunId", params.getRunId()); | ||
} | ||
|
||
@Test | ||
public void testWithRunIdChain() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
|
||
SignalExternalWorkflowParameters result = params.withRunId("ChainRunId"); | ||
assertEquals("ChainRunId", params.getRunId()); | ||
assertSame(params, result); | ||
} | ||
|
||
@Test | ||
public void testSetAndGetSignalName() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
|
||
params.setSignalName("TestSignalName"); | ||
assertEquals("TestSignalName", params.getSignalName()); | ||
} | ||
|
||
@Test | ||
public void testWithSignalNameChain() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
SignalExternalWorkflowParameters result = params.withSignalName("ChainSignalName"); | ||
assertEquals("ChainSignalName", params.getSignalName()); | ||
assertSame(params, result); | ||
} | ||
|
||
@Test | ||
public void testSetAndGetWorkflowId() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
params.setWorkflowId("TestWorkflowId"); | ||
assertEquals("TestWorkflowId", params.getWorkflowId()); | ||
} | ||
|
||
@Test | ||
public void testWithWorkflowIdChain() { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
SignalExternalWorkflowParameters result = params.withWorkflowId("ChainWorkflowId"); | ||
assertEquals("ChainWorkflowId", params.getWorkflowId()); | ||
assertSame(params, result); | ||
} | ||
|
||
@Test | ||
public void testStringification() { | ||
|
||
String longStr = | ||
"1000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000000" | ||
+ "0000000000000000000000000000000000000000000000000000000000000000000000001"; | ||
|
||
SignalExternalWorkflowParameters longParams = | ||
new SignalExternalWorkflowParameters() | ||
.withWorkflowId("ChainWorkflowId") | ||
.withSignalName("signalName") | ||
.withInput(longStr.getBytes()) | ||
.withRunId("some-run-id"); | ||
|
||
SignalExternalWorkflowParameters shortParams = | ||
new SignalExternalWorkflowParameters() | ||
.withWorkflowId("ChainWorkflowId") | ||
.withSignalName("signalName") | ||
.withInput("smol".getBytes()) | ||
.withRunId("some-run-id"); | ||
|
||
assertEquals( | ||
"{SignalName: signalName, Input: " | ||
+ longStr.substring(0, 512) | ||
+ ", WorkflowId: ChainWorkflowId, RunId: some-run-id, }", | ||
longParams.toString()); | ||
|
||
assertEquals( | ||
"{SignalName: signalName, Input: " | ||
+ "smol" | ||
+ ", WorkflowId: ChainWorkflowId, RunId: some-run-id, }", | ||
shortParams.toString()); | ||
|
||
assertEquals( | ||
"{SignalName: null, Input: , WorkflowId: null, RunId: null, }", | ||
new SignalExternalWorkflowParameters().toString()); | ||
} | ||
|
||
@Test | ||
public void testClone() throws CloneNotSupportedException { | ||
SignalExternalWorkflowParameters params = new SignalExternalWorkflowParameters(); | ||
params.setDomain("Domain"); | ||
params.setRunId("RunId"); | ||
params.setSignalName("SignalName"); | ||
params.setWorkflowId("WorkflowId"); | ||
params.setInput("Input".getBytes(StandardCharsets.UTF_8)); | ||
|
||
SignalExternalWorkflowParameters clonedParams = params.copy(); | ||
|
||
assertNotSame(params, clonedParams); | ||
|
||
assertEquals(params.getDomain(), clonedParams.getDomain()); | ||
assertArrayEquals(params.getInput(), clonedParams.getInput()); | ||
assertEquals(params.getRunId(), clonedParams.getRunId()); | ||
assertEquals(params.getSignalName(), clonedParams.getSignalName()); | ||
assertEquals(params.getWorkflowId(), clonedParams.getWorkflowId()); | ||
|
||
// there's 5 assertions here | ||
// update if there's any additional properties | ||
assertEquals(5, getPropertyCount(params)); | ||
} | ||
|
||
private static int getPropertyCount(Object obj) { | ||
int count = 0; | ||
Class<?> clazz = obj.getClass(); | ||
|
||
while (clazz != null) { | ||
Field[] fields = clazz.getDeclaredFields(); | ||
|
||
for (Field field : fields) { | ||
if (!field.getName().equals("$jacocoData")) { | ||
count++; | ||
} | ||
} | ||
clazz = clazz.getSuperclass(); | ||
} | ||
|
||
return count; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole thing seems utterly pointless and not good personally I'd rather see JSON representation, but fixing it up since god forbid, someone mgiht actually be caring about it's current not good structure.
the main issue is that before, it broke for short strings, which is probably not what you want for a tostring