From 8d5de6b292981818e81ffd6cb3b8773c710884ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=A8=E7=BA=A2=E5=B0=98=E4=B8=AD=E6=88=90=E4=BB=99?= <68594013+MundaneImmortal@users.noreply.github.com> Date: Sun, 20 Mar 2022 22:43:34 -0500 Subject: [PATCH] NIFI-9818 fix flaky tests This closes #5883 Signed-off-by: Mike Thomsen --- .../nifi/serialization/record/util/DataTypeUtils.java | 2 +- .../nifi/serialization/record/TestDataTypeUtils.java | 5 +++-- .../apache/nifi/serialization/record/TestMapRecord.java | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java index 5a8649e75c..1416b9777d 100644 --- a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java +++ b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java @@ -548,7 +548,7 @@ public class DataTypeUtils { map = (Map) value; } else { final Map m = (Map) value; - map = new HashMap<>(m.size()); + map = new LinkedHashMap<>(m.size()); m.forEach((k, v) -> map.put(k == null ? null : k.toString(), v)); } return inferRecordDataType(map); diff --git a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java index 21ec9199ef..8d9f13aaf7 100644 --- a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java +++ b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestDataTypeUtils.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -611,7 +612,7 @@ public class TestDataTypeUtils { @Test public void testInferTypeWithMapStringKeys() { - Map map = new HashMap<>(); + Map map = new LinkedHashMap<>(); map.put("a", "Hello"); map.put("b", "World"); @@ -626,7 +627,7 @@ public class TestDataTypeUtils { @Test public void testInferTypeWithMapNonStringKeys() { - Map map = new HashMap<>(); + Map map = new LinkedHashMap<>(); map.put(1, "Hello"); map.put(2, "World"); diff --git a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java index 9250d5f17b..2240e57270 100644 --- a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java +++ b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/TestMapRecord.java @@ -24,7 +24,8 @@ import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -78,7 +79,7 @@ public class TestMapRecord { } private Set set(final String... values) { - final Set set = new HashSet<>(); + final Set set = new LinkedHashSet<>(); for (final String value : values) { set.add(value); } @@ -122,7 +123,7 @@ public class TestMapRecord { fields.add(new RecordField("foo", RecordFieldType.STRING.getDataType(), null, set("bar", "baz"))); final RecordSchema schema = new SimpleRecordSchema(fields); - final Map values = new HashMap<>(); + final Map values = new LinkedHashMap<>(); values.put("baz", 1); values.put("bar", 33); @@ -161,7 +162,7 @@ public class TestMapRecord { fields.add(new RecordField("foo", RecordFieldType.STRING.getDataType(), "hello", set("bar", "baz"))); final RecordSchema schema = new SimpleRecordSchema(fields); - final Map values = new HashMap<>(); + final Map values = new LinkedHashMap<>(); values.put("baz", 1); values.put("bar", 33);