Skip to content

Commit 9c284e6

Browse files
committed
Clear send behavior rule in CloseWhileRelocatingShardsIT (#38159)
The current CloseWhileRelocatingShardsIT test adds some "send behavior" rule to a target node's mocked transport service in order to detect when shard relocating are started. These rules are never cleared and prevent the test to complete normally after the rebalance is re-enabled again. This commit changes the test so that rules are cleared and most verifications are done before the rebalance is reenabled again. Closes #38090
1 parent b10e95f commit 9c284e6

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

server/src/test/java/org/elasticsearch/indices/state/CloseWhileRelocatingShardsIT.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ protected int maximumNumberOfShards() {
8080
return 3;
8181
}
8282

83-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38090")
8483
@TestLogging("org.elasticsearch.cluster.metadata.MetaDataIndexStateService:DEBUG,org.elasticsearch.action.admin.indices.close:DEBUG")
8584
public void testCloseWhileRelocatingShards() throws Exception {
8685
final String[] indices = new String[randomIntBetween(3, 5)];
@@ -120,6 +119,8 @@ public void testCloseWhileRelocatingShards() throws Exception {
120119

121120
final String targetNode = internalCluster().startDataOnlyNode();
122121
ensureClusterSizeConsistency(); // wait for the master to finish processing join.
122+
final MockTransportService targetTransportService =
123+
(MockTransportService) internalCluster().getInstance(TransportService.class, targetNode);
123124

124125
final Set<String> acknowledgedCloses = ConcurrentCollections.newConcurrentSet();
125126
try {
@@ -147,8 +148,7 @@ public void testCloseWhileRelocatingShards() throws Exception {
147148
}
148149

149150
final DiscoveryNode sourceNode = clusterService.state().nodes().resolveNode(primary.currentNodeId());
150-
((MockTransportService) internalCluster().getInstance(TransportService.class, targetNode))
151-
.addSendBehavior(internalCluster().getInstance(TransportService.class, sourceNode.getName()),
151+
targetTransportService.addSendBehavior(internalCluster().getInstance(TransportService.class, sourceNode.getName()),
152152
(connection, requestId, action, request, options) -> {
153153
if (PeerRecoverySourceService.Actions.START_RECOVERY.equals(action)) {
154154
logger.debug("blocking recovery of shard {}", ((StartRecoveryRequest) request).shardId());
@@ -211,28 +211,30 @@ public void testCloseWhileRelocatingShards() throws Exception {
211211
}
212212
}
213213
}
214-
} finally {
215-
assertAcked(client().admin().cluster().prepareUpdateSettings()
216-
.setTransientSettings(Settings.builder()
217-
.putNull(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey())));
218-
}
219214

220-
for (String index : indices) {
221-
if (acknowledgedCloses.contains(index)) {
222-
assertIndexIsClosed(index);
223-
} else {
224-
assertIndexIsOpened(index);
215+
for (String index : indices) {
216+
if (acknowledgedCloses.contains(index)) {
217+
assertIndexIsClosed(index);
218+
} else {
219+
assertIndexIsOpened(index);
220+
}
225221
}
226-
}
227222

228-
assertThat("Consider that the test failed if no indices were successfully closed", acknowledgedCloses.size(), greaterThan(0));
229-
assertAcked(client().admin().indices().prepareOpen("index-*"));
230-
ensureGreen(indices);
223+
targetTransportService.clearAllRules();
224+
225+
assertThat("Consider that the test failed if no indices were successfully closed", acknowledgedCloses.size(), greaterThan(0));
226+
assertAcked(client().admin().indices().prepareOpen("index-*"));
227+
ensureGreen(indices);
231228

232-
for (String index : acknowledgedCloses) {
233-
long docsCount = client().prepareSearch(index).setSize(0).get().getHits().getTotalHits();
234-
assertEquals("Expected " + docsPerIndex.get(index) + " docs in index " + index + " but got " + docsCount
235-
+ " (close acknowledged=" + acknowledgedCloses.contains(index) + ")", (long) docsPerIndex.get(index), docsCount);
229+
for (String index : acknowledgedCloses) {
230+
long docsCount = client().prepareSearch(index).setSize(0).get().getHits().getTotalHits();
231+
assertEquals("Expected " + docsPerIndex.get(index) + " docs in index " + index + " but got " + docsCount
232+
+ " (close acknowledged=" + acknowledgedCloses.contains(index) + ")", (long) docsPerIndex.get(index), docsCount);
233+
}
234+
} finally {
235+
assertAcked(client().admin().cluster().prepareUpdateSettings()
236+
.setTransientSettings(Settings.builder()
237+
.putNull(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey())));
236238
}
237239
}
238240
}

0 commit comments

Comments
 (0)