@@ -29,13 +29,15 @@ public void testTruncatingStepInfo() {
2929 Map <String , String > custom = createCustomMetadata ();
3030 LifecycleExecutionState state = LifecycleExecutionState .fromCustomMetadata (custom );
3131 assertThat (custom .get ("step_info" ), equalTo (state .stepInfo ()));
32- String longStepInfo = randomAlphanumericOfLength (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH + 100 );
32+ String longStepInfo = "{\" key\" : \" "
33+ + randomAlphanumericOfLength (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH + 100 )
34+ + "\" }" ;
3335 LifecycleExecutionState newState = LifecycleExecutionState .builder (state ).setStepInfo (longStepInfo ).build ();
3436 // Length includes the post suffix (`... (X chars truncated)`)
35- assertThat (newState .stepInfo ().length (), equalTo (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH + 26 ));
37+ assertThat (newState .stepInfo ().length (), equalTo (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH + 25 ));
3638 assertThat (
37- newState .stepInfo ().substring (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH , 1050 ),
38- equalTo ("... (98 chars truncated)\" }" )
39+ newState .stepInfo ().substring (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH - 2 , 1049 ),
40+ equalTo ("... (111 chars truncated)\" }" )
3941 );
4042 }
4143
@@ -147,19 +149,14 @@ public void testGetCurrentStepKey() {
147149 }
148150
149151 public void testPotentiallyTruncateLongJsonWithExplanationNotTruncated () {
150- // +2 because with the JSON ending in `"}`, we'll add it back anyway so it's a NOP
151- final String input = randomAlphaOfLengthBetween (0 , LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH + 2 );
152+ final String input = randomAlphaOfLengthBetween (0 , LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH );
152153 assertSame (input , LifecycleExecutionState .potentiallyTruncateLongJsonWithExplanation (input ));
153154 }
154155
155156 public void testPotentiallyTruncateLongJsonWithExplanationOneCharTruncated () {
156157 final String jsonBaseFormat = "{\" key\" : \" %s\" }" ;
157158 final int baseLength = Strings .format (jsonBaseFormat , "" ).length ();
158- final String value = randomAlphanumericOfLength (
159- // +3 because +1 and +2 are no-ops, they will truncate the end of JSON `"}` and then add it back,
160- // so we need another char to truncate.
161- LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH - baseLength + 3
162- );
159+ final String value = randomAlphanumericOfLength (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH - baseLength + 1 );
163160 final String input = Strings .format (jsonBaseFormat , value );
164161 final String expectedOutput = Strings .format (jsonBaseFormat , value .substring (0 , value .length () - 1 ) + "... (1 chars truncated)" );
165162 assertEquals (expectedOutput , LifecycleExecutionState .potentiallyTruncateLongJsonWithExplanation (input ));
@@ -168,11 +165,7 @@ public void testPotentiallyTruncateLongJsonWithExplanationOneCharTruncated() {
168165 public void testPotentiallyTruncateLongJsonWithExplanationTwoCharsTruncated () {
169166 final String jsonBaseFormat = "{\" key\" : \" %s\" }" ;
170167 final int baseLength = Strings .format (jsonBaseFormat , "" ).length ();
171- final String value = randomAlphanumericOfLength (
172- // +4 because +1 and +2 are no-ops, they will truncate the end of JSON `"}` and then add it back,
173- // so we need another two chars to truncate.
174- LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH - baseLength + 4
175- );
168+ final String value = randomAlphanumericOfLength (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH - baseLength + 2 );
176169 final String input = Strings .format (jsonBaseFormat , value );
177170 final String expectedOutput = Strings .format (jsonBaseFormat , value .substring (0 , value .length () - 2 ) + "... (2 chars truncated)" );
178171 assertEquals (expectedOutput , LifecycleExecutionState .potentiallyTruncateLongJsonWithExplanation (input ));
0 commit comments