Skip to content

Commit 029e4b6

Browse files
authored
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 ce469cf commit 029e4b6

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public void testCloseWhileRelocatingShards() throws Exception {
119119

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

123125
final Set<String> acknowledgedCloses = ConcurrentCollections.newConcurrentSet();
124126
try {
@@ -146,8 +148,7 @@ public void testCloseWhileRelocatingShards() throws Exception {
146148
}
147149

148150
final DiscoveryNode sourceNode = clusterService.state().nodes().resolveNode(primary.currentNodeId());
149-
((MockTransportService) internalCluster().getInstance(TransportService.class, targetNode))
150-
.addSendBehavior(internalCluster().getInstance(TransportService.class, sourceNode.getName()),
151+
targetTransportService.addSendBehavior(internalCluster().getInstance(TransportService.class, sourceNode.getName()),
151152
(connection, requestId, action, request, options) -> {
152153
if (PeerRecoverySourceService.Actions.START_RECOVERY.equals(action)) {
153154
logger.debug("blocking recovery of shard {}", ((StartRecoveryRequest) request).shardId());
@@ -210,28 +211,30 @@ public void testCloseWhileRelocatingShards() throws Exception {
210211
}
211212
}
212213
}
213-
} finally {
214-
assertAcked(client().admin().cluster().prepareUpdateSettings()
215-
.setTransientSettings(Settings.builder()
216-
.putNull(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey())));
217-
}
218214

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

227-
assertThat("Consider that the test failed if no indices were successfully closed", acknowledgedCloses.size(), greaterThan(0));
228-
assertAcked(client().admin().indices().prepareOpen("index-*"));
229-
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);
230228

231-
for (String index : acknowledgedCloses) {
232-
long docsCount = client().prepareSearch(index).setSize(0).get().getHits().getTotalHits().value;
233-
assertEquals("Expected " + docsPerIndex.get(index) + " docs in index " + index + " but got " + docsCount
234-
+ " (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().value;
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())));
235238
}
236239
}
237240
}

0 commit comments

Comments
 (0)