|
@@ -69,7 +69,7 @@ public class GroupShardsIteratorTests extends ESTestCase {
|
|
|
ShardId shardId = new ShardId(index, 1);
|
|
|
list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId, 0)));
|
|
|
}
|
|
|
- GroupShardsIterator iter = new GroupShardsIterator<>(list);
|
|
|
+ GroupShardsIterator<ShardIterator> iter = new GroupShardsIterator<>(list);
|
|
|
assertEquals(7, iter.totalSizeWith1ForEmpty());
|
|
|
assertEquals(5, iter.size());
|
|
|
assertEquals(6, iter.totalSize());
|
|
@@ -106,13 +106,24 @@ public class GroupShardsIteratorTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
Collections.shuffle(list, random());
|
|
|
- List<ShardIterator> actualIterators = new ArrayList<>();
|
|
|
- GroupShardsIterator<ShardIterator> iter = new GroupShardsIterator<>(list);
|
|
|
- for (ShardIterator shardsIterator : iter) {
|
|
|
- actualIterators.add(shardsIterator);
|
|
|
+ {
|
|
|
+ GroupShardsIterator<ShardIterator> unsorted = new GroupShardsIterator<>(list);
|
|
|
+ GroupShardsIterator<ShardIterator> iter = new GroupShardsIterator<>(list);
|
|
|
+ List<ShardIterator> actualIterators = new ArrayList<>();
|
|
|
+ for (ShardIterator shardsIterator : iter) {
|
|
|
+ actualIterators.add(shardsIterator);
|
|
|
+ }
|
|
|
+ assertEquals(actualIterators, list);
|
|
|
+ }
|
|
|
+ {
|
|
|
+ GroupShardsIterator<ShardIterator> iter = GroupShardsIterator.sortAndCreate(list);
|
|
|
+ List<ShardIterator> actualIterators = new ArrayList<>();
|
|
|
+ for (ShardIterator shardsIterator : iter) {
|
|
|
+ actualIterators.add(shardsIterator);
|
|
|
+ }
|
|
|
+ CollectionUtil.timSort(actualIterators);
|
|
|
+ assertEquals(actualIterators, list);
|
|
|
}
|
|
|
- CollectionUtil.timSort(actualIterators);
|
|
|
- assertEquals(actualIterators, list);
|
|
|
}
|
|
|
|
|
|
public void testOrderingWithSearchShardIterators() {
|
|
@@ -123,7 +134,7 @@ public class GroupShardsIteratorTests extends ESTestCase {
|
|
|
String[] clusters = generateRandomStringArray(5, 10, false, false);
|
|
|
Arrays.sort(clusters);
|
|
|
|
|
|
- List<SearchShardIterator> expected = new ArrayList<>();
|
|
|
+ List<SearchShardIterator> sorted = new ArrayList<>();
|
|
|
int numShards = randomIntBetween(1, 10);
|
|
|
for (int i = 0; i < numShards; i++) {
|
|
|
for (String index : indices) {
|
|
@@ -131,23 +142,33 @@ public class GroupShardsIteratorTests extends ESTestCase {
|
|
|
ShardId shardId = new ShardId(index, uuid, i);
|
|
|
SearchShardIterator shardIterator = new SearchShardIterator(null, shardId,
|
|
|
GroupShardsIteratorTests.randomShardRoutings(shardId), OriginalIndicesTests.randomOriginalIndices());
|
|
|
- expected.add(shardIterator);
|
|
|
+ sorted.add(shardIterator);
|
|
|
for (String cluster : clusters) {
|
|
|
SearchShardIterator remoteIterator = new SearchShardIterator(cluster, shardId,
|
|
|
GroupShardsIteratorTests.randomShardRoutings(shardId), OriginalIndicesTests.randomOriginalIndices());
|
|
|
- expected.add(remoteIterator);
|
|
|
+ sorted.add(remoteIterator);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<SearchShardIterator> shuffled = new ArrayList<>(expected);
|
|
|
+ List<SearchShardIterator> shuffled = new ArrayList<>(sorted);
|
|
|
Collections.shuffle(shuffled, random());
|
|
|
- List<ShardIterator> actualIterators = new ArrayList<>();
|
|
|
- GroupShardsIterator<SearchShardIterator> iter = new GroupShardsIterator<>(shuffled);
|
|
|
- for (SearchShardIterator searchShardIterator : iter) {
|
|
|
- actualIterators.add(searchShardIterator);
|
|
|
+ {
|
|
|
+ List<ShardIterator> actualIterators = new ArrayList<>();
|
|
|
+ GroupShardsIterator<SearchShardIterator> iter = new GroupShardsIterator<>(shuffled);
|
|
|
+ for (SearchShardIterator searchShardIterator : iter) {
|
|
|
+ actualIterators.add(searchShardIterator);
|
|
|
+ }
|
|
|
+ assertEquals(shuffled, actualIterators);
|
|
|
+ }
|
|
|
+ {
|
|
|
+ List<ShardIterator> actualIterators = new ArrayList<>();
|
|
|
+ GroupShardsIterator<SearchShardIterator> iter = GroupShardsIterator.sortAndCreate(shuffled);
|
|
|
+ for (SearchShardIterator searchShardIterator : iter) {
|
|
|
+ actualIterators.add(searchShardIterator);
|
|
|
+ }
|
|
|
+ assertEquals(sorted, actualIterators);
|
|
|
}
|
|
|
- assertEquals(expected, actualIterators);
|
|
|
}
|
|
|
}
|