Skip to content

Commit 44be39a

Browse files
authored
Merge pull request #2 from kaiyaok2/fixed_all_flaky_tests
Addresses Changes
2 parents 4c281d4 + 3e70d9a commit 44be39a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

sdk1/src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/internal/AttributeValueMarshaller.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.ArrayList;
2626
import java.util.Collections;
2727
import java.util.HashMap;
28+
import java.util.TreeMap;
2829
import java.util.List;
2930
import java.util.Map;
3031

@@ -119,7 +120,10 @@ private static void marshall(final AttributeValue attributeValue, final DataOutp
119120
marshall(attr, out);
120121
}
121122
} else if (attributeValue.getM() != null) {
122-
final Map<String, AttributeValue> m = attributeValue.getM();
123+
// Using TreeMap to ensure deterministic entry order
124+
final Map<String, AttributeValue> m = new TreeMap<>(attributeValue.getM());
125+
// Update the deterministic order to attributeValue
126+
attributeValue.setM(m);
123127
final List<String> mKeys = new ArrayList<String>(m.keySet());
124128
Collections.sort(mKeys);
125129
out.writeChar('M');

sdk1/src/test/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/DynamoDBEncryptorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public void ensureEncryptedAttributesUnmodified() throws GeneralSecurityExceptio
199199
Map<String, AttributeValue> encryptedAttributes =
200200
encryptor.encryptAllFieldsExcept(
201201
Collections.unmodifiableMap(attribs), context, "hashKey", "rangeKey", "version");
202+
// Using TreeMap before casting to string to avoid nondeterministic key orders.
202203
String encryptedString = new TreeMap<>(encryptedAttributes).toString();
203204
encryptor.decryptAllFieldsExcept(
204205
Collections.unmodifiableMap(encryptedAttributes),

sdk1/src/test/java/com/amazonaws/services/dynamodbv2/datamodeling/internal/AttributeValueMarshallerTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,9 @@ public void testSimpleMapWithNull() {
266266
marshall(av);
267267
Assert.fail("Unexpected success");
268268
} catch (final NullPointerException npe) {
269-
// Map entries may permute under nondeterministic Java API
270-
String npeMessage = npe.getMessage();
271-
String common = "Encountered null map value for key NullKeyValue while marshalling attribute value ";
272-
String case1 = common + "{M: {KeyValue={S: ValueValue,}, NullKeyValue=null},}";
273-
String case2 = common + "{M: {NullKeyValue=null, KeyValue={S: ValueValue,}},}";
274-
Assert.assertTrue(case1.equals(npeMessage) || case2.equals(npeMessage));
269+
Assert.assertEquals(
270+
"Encountered null map value for key NullKeyValue while marshalling attribute value {M: {KeyValue={S: ValueValue,}, NullKeyValue=null},}",
271+
npe.getMessage());
275272
}
276273
}
277274

0 commit comments

Comments
 (0)