Skip to content

Commit

Permalink
Fix flaky tests (apache#2645)
Browse files Browse the repository at this point in the history
in org.apache.helix.rest.metadatastore.
TestZkMetadataStoreDirectory
  • Loading branch information
simonh5 committed Oct 5, 2023
1 parent 6241bcb commit 9cd4181
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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<String> collection1,
Collection<String> collection2) {
Assert.assertEquals(collection2.size(), collection1.size());
Assert.assertTrue(collection2.containsAll(collection1));
Assert.assertTrue(collection1.containsAll(collection2));
}
}

0 comments on commit 9cd4181

Please sign in to comment.