madrob commented on a change in pull request #1366: SOLR-14342: Optimize core
loading order in SolrCloud.
URL: https://github.com/apache/lucene-solr/pull/1366#discussion_r395417505
##########
File path: solr/core/src/test/org/apache/solr/core/CoreSorterTest.java
##########
@@ -71,168 +69,141 @@ public void testComparator() {
);
+ testComparator(expected, l);
+
+ integrationTest(expected, l);
+ }
+
+ private void testComparator(List<CountsForEachShard> expectedCounts,
List<CountsForEachShard> inputCounts) {
for (int i = 0; i < 10; i++) {
- List<CountsForEachShard> copy = new ArrayList<>(l);
+ List<CountsForEachShard> copy = new ArrayList<>(inputCounts);
Collections.shuffle(copy, random());
Collections.sort(copy, CoreSorter.countsComparator);
for (int j = 0; j < copy.size(); j++) {
- assertEquals(expected.get(j), copy.get(j));
+ assertEquals(expectedCounts.get(j), copy.get(j));
}
}
}
- public void testSort() throws Exception {
- CoreContainer mockCC = getMockContainer();
- MockCoreSorter coreSorter = (MockCoreSorter) new
MockCoreSorter().init(mockCC);
- List<CoreDescriptor> copy = new ArrayList<>(coreSorter.getLocalCores());
- Collections.sort(copy, coreSorter::compare);
- List<CountsForEachShard> l = copy.stream()
- .map(CoreDescriptor::getCloudDescriptor)
- .map(it -> coreSorter.shardsVsReplicaCounts.get(getShardName(it)))
- .collect(toList());
- for (int i = 1; i < l.size(); i++) {
- CountsForEachShard curr = l.get(i);
- CountsForEachShard prev = l.get(i-1);
- assertTrue(CoreSorter.countsComparator.compare(prev, curr) < 1);
- }
-
- for (CountsForEachShard c : l) {
- System.out.println(c);
- }
- }
-
- private CoreContainer getMockContainer() {
+ private void integrationTest(List<CountsForEachShard> expectedCounts,
List<CountsForEachShard> _inputCounts) {
assumeWorkingMockito();
-
- CoreContainer mockCC = mock(CoreContainer.class);
- ZkController mockZKC = mock(ZkController.class);
- ClusterState mockClusterState = mock(ClusterState.class);
- when(mockCC.isZooKeeperAware()).thenReturn(true);
- when(mockCC.getZkController()).thenReturn(mockZKC);
- when(mockClusterState.getLiveNodes()).thenReturn(liveNodes);
- when(mockZKC.getClusterState()).thenReturn(mockClusterState);
- return mockCC;
- }
- static class ReplicaInfo {
- final int coll, slice, replica;
- final String replicaName;
- CloudDescriptor cd;
-
- ReplicaInfo(int coll, int slice, int replica) {
- this.coll = coll;
- this.slice = slice;
- this.replica = replica;
- replicaName = "coll_" + coll + "_" + slice + "_" + replica;
- Properties p = new Properties();
- p.setProperty(CoreDescriptor.CORE_SHARD, "shard_" + slice);
- p.setProperty(CoreDescriptor.CORE_COLLECTION, "coll_" + slice);
- p.setProperty(CoreDescriptor.CORE_NODE_NAME, replicaName);
- cd = new CloudDescriptor(null, replicaName, p);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof ReplicaInfo) {
- ReplicaInfo replicaInfo = (ReplicaInfo) obj;
- return replicaInfo.replicaName.equals(replicaName);
+ List<CountsForEachShard> perShardCounts = new ArrayList<>(_inputCounts);
+ Collections.shuffle(perShardCounts);
Review comment:
pass `random()`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]