From 7ba774fa264cdf929791f830563542c6b3df4674 Mon Sep 17 00:00:00 2001 From: Simon Hofbauer <61789910+hofi1@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:14:31 +0100 Subject: [PATCH] Fix flaky tests (#2645) (#2666) in org.apache.helix.rest.metadatastore. TestZkMetadataStoreDirectory Co-authored-by: simonh5 --- .../metadatastore/TestZkMetadataStoreDirectory.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/helix-rest/src/test/java/org/apache/helix/rest/metadatastore/TestZkMetadataStoreDirectory.java b/helix-rest/src/test/java/org/apache/helix/rest/metadatastore/TestZkMetadataStoreDirectory.java index 64e04df9fc..38ddfba870 100644 --- a/helix-rest/src/test/java/org/apache/helix/rest/metadatastore/TestZkMetadataStoreDirectory.java +++ b/helix-rest/src/test/java/org/apache/helix/rest/metadatastore/TestZkMetadataStoreDirectory.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -31,7 +32,6 @@ import org.apache.helix.TestHelper; import org.apache.helix.msdcommon.constant.MetadataStoreRoutingConstants; -import org.apache.helix.msdcommon.exception.InvalidRoutingDataException; import org.apache.helix.rest.server.AbstractTestClass; import org.apache.helix.zookeeper.datamodel.ZNRecord; import org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer; @@ -136,7 +136,7 @@ public void testGetAllMetadataStoreRealms() { realms.add(TEST_REALM_2); for (String namespace : _routingZkAddrMap.keySet()) { - Assert.assertEquals(_metadataStoreDirectory.getAllMetadataStoreRealms(namespace), realms); + assertCollectionsContainSameElementsIgnoringOrder(_metadataStoreDirectory.getAllMetadataStoreRealms(namespace), realms); } } @@ -147,7 +147,7 @@ public void testGetAllShardingKeys() { allShardingKeys.addAll(TEST_SHARDING_KEYS_2); for (String namespace : _routingZkAddrMap.keySet()) { - Assert.assertEquals(_metadataStoreDirectory.getAllShardingKeys(namespace), allShardingKeys); + assertCollectionsContainSameElementsIgnoringOrder(_metadataStoreDirectory.getAllShardingKeys(namespace),allShardingKeys); } } @@ -375,4 +375,10 @@ private void clearRoutingData() throws Exception { return true; }, TestHelper.WAIT_DURATION), "Routing data path should be deleted after the tests."); } + private void assertCollectionsContainSameElementsIgnoringOrder(Collection collection1, + Collection collection2) { + Assert.assertEquals(collection2.size(), collection1.size()); + Assert.assertTrue(collection2.containsAll(collection1)); + Assert.assertTrue(collection1.containsAll(collection2)); + } }