|
9 | 9 |
|
10 | 10 | package org.elasticsearch.test; |
11 | 11 |
|
12 | | -import io.netty.util.ThreadDeathWatcher; |
13 | | -import io.netty.util.concurrent.GlobalEventExecutor; |
14 | | - |
15 | 12 | import com.carrotsearch.randomizedtesting.RandomizedContext; |
16 | 13 | import com.carrotsearch.randomizedtesting.generators.RandomNumbers; |
17 | 14 | import com.carrotsearch.randomizedtesting.generators.RandomPicks; |
18 | | - |
| 15 | +import io.netty.util.ThreadDeathWatcher; |
| 16 | +import io.netty.util.concurrent.GlobalEventExecutor; |
19 | 17 | import org.apache.http.HttpHost; |
20 | 18 | import org.apache.logging.log4j.Logger; |
21 | 19 | import org.apache.lucene.search.Sort; |
@@ -1594,9 +1592,29 @@ protected BroadcastResponse forceMerge() { |
1594 | 1592 | waitForRelocation(); |
1595 | 1593 | BroadcastResponse actionGet = indicesAdmin().prepareForceMerge().setMaxNumSegments(1).get(); |
1596 | 1594 | assertNoFailures(actionGet); |
| 1595 | + if (randomBoolean()) { |
| 1596 | + // after a force merge there should only be 1 segment per shard |
| 1597 | + var shardsWithMultipleSegments = getShardSegments().stream() |
| 1598 | + .filter(shardSegments -> shardSegments.getSegments().size() > 1) |
| 1599 | + .toList(); |
| 1600 | + assertTrue("there are shards with multiple segments " + shardsWithMultipleSegments, shardsWithMultipleSegments.isEmpty()); |
| 1601 | + } |
1597 | 1602 | return actionGet; |
1598 | 1603 | } |
1599 | 1604 |
|
| 1605 | + /** |
| 1606 | + * Returns the segments of the shards of the indices. |
| 1607 | + */ |
| 1608 | + protected List<ShardSegments> getShardSegments(String... indices) { |
| 1609 | + IndicesSegmentResponse indicesSegmentResponse = indicesAdmin().prepareSegments(indices).get(); |
| 1610 | + return indicesSegmentResponse.getIndices() |
| 1611 | + .values() |
| 1612 | + .stream() |
| 1613 | + .flatMap(indexSegments -> indexSegments.getShards().values().stream()) |
| 1614 | + .flatMap(indexShardSegments -> Stream.of(indexShardSegments.shards())) |
| 1615 | + .toList(); |
| 1616 | + } |
| 1617 | + |
1600 | 1618 | /** |
1601 | 1619 | * Returns <code>true</code> iff the given index exists otherwise <code>false</code> |
1602 | 1620 | */ |
|
0 commit comments