Skip to content

Commit 4518722

Browse files
committed
they pay me by line of code
1 parent b0df401 commit 4518722

File tree

1 file changed

+74
-59
lines changed

1 file changed

+74
-59
lines changed

server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -144,46 +144,53 @@ public void testNodesJoinAfterStableCluster() {
144144
assertEquals(currentTerm, newTerm);
145145
}
146146

147-
public void testLeaderDisconnectionDetectedQuickly() {
147+
public void testLeaderDisconnectionWithDisconnectEventDetectedQuickly() {
148148
final Cluster cluster = new Cluster(randomIntBetween(3, 5));
149149
cluster.runRandomly();
150150
cluster.stabilise();
151151

152152
final ClusterNode originalLeader = cluster.getAnyLeader();
153153
logger.info("--> disconnecting leader {}", originalLeader);
154154
originalLeader.disconnect();
155-
boolean followersGetDisconnectEvent = randomBoolean();
156-
if (followersGetDisconnectEvent) {
157-
logger.info("--> followers get disconnect event for leader {} ", originalLeader);
158-
cluster.getAllNodesExcept(originalLeader).forEach(cn -> cn.onDisconnectEventFrom(originalLeader));
159-
// turn leader into candidate, which stabilisation asserts at the end
160-
cluster.getAllNodesExcept(originalLeader).forEach(cn -> originalLeader.onDisconnectEventFrom(cn));
161-
cluster.stabilise(DEFAULT_DELAY_VARIABILITY // disconnect is scheduled
155+
logger.info("--> followers get disconnect event for leader {} ", originalLeader);
156+
cluster.getAllNodesExcept(originalLeader).forEach(cn -> cn.onDisconnectEventFrom(originalLeader));
157+
// turn leader into candidate, which stabilisation asserts at the end
158+
cluster.getAllNodesExcept(originalLeader).forEach(cn -> originalLeader.onDisconnectEventFrom(cn));
159+
cluster.stabilise(DEFAULT_DELAY_VARIABILITY // disconnect is scheduled
160+
+ DEFAULT_ELECTION_DELAY
161+
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
162+
assertThat(cluster.getAnyLeader().getId(), not(equalTo(originalLeader.getId())));
163+
}
164+
165+
public void testLeaderDisconnectionWithoutDisconnectEventDetectedQuickly() {
166+
final Cluster cluster = new Cluster(randomIntBetween(3, 5));
167+
cluster.runRandomly();
168+
cluster.stabilise();
169+
170+
final ClusterNode originalLeader = cluster.getAnyLeader();
171+
logger.info("--> disconnecting leader {}", originalLeader);
172+
originalLeader.disconnect();
173+
cluster.stabilise(Math.max(
174+
// Each follower may have just sent a leader check, which receives no response
175+
defaultMillis(LEADER_CHECK_TIMEOUT_SETTING)
176+
// then wait for the follower to check the leader
177+
+ defaultMillis(LEADER_CHECK_INTERVAL_SETTING)
178+
// then wait for the exception response
179+
+ DEFAULT_DELAY_VARIABILITY
180+
// then wait for a new election
162181
+ DEFAULT_ELECTION_DELAY
163-
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
164-
} else {
165-
cluster.stabilise(Math.max(
166-
// Each follower may have just sent a leader check, which receives no response
167-
defaultMillis(LEADER_CHECK_TIMEOUT_SETTING)
168-
// then wait for the follower to check the leader
169-
+ defaultMillis(LEADER_CHECK_INTERVAL_SETTING)
170-
// then wait for the exception response
171-
+ DEFAULT_DELAY_VARIABILITY
172-
// then wait for a new election
173-
+ DEFAULT_ELECTION_DELAY
174-
// then wait for the old leader's removal to be committed
175-
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY,
176-
177-
// ALSO the leader may have just sent a follower check, which receives no response
178-
defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING)
179-
// wait for the leader to check its followers
180-
+ defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING)
181-
// then wait for the exception response
182-
+ DEFAULT_DELAY_VARIABILITY
183-
// then wait for the removal to be committed
184-
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY
185-
));
186-
}
182+
// then wait for the old leader's removal to be committed
183+
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY,
184+
185+
// ALSO the leader may have just sent a follower check, which receives no response
186+
defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING)
187+
// wait for the leader to check its followers
188+
+ defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING)
189+
// then wait for the exception response
190+
+ DEFAULT_DELAY_VARIABILITY
191+
// then wait for the removal to be committed
192+
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY
193+
));
187194
assertThat(cluster.getAnyLeader().getId(), not(equalTo(originalLeader.getId())));
188195
}
189196

@@ -229,7 +236,7 @@ public void testUnresponsiveLeaderDetectedEventually() {
229236
assertThat(cluster.getAnyLeader().getId(), not(equalTo(originalLeader.getId())));
230237
}
231238

232-
public void testFollowerDisconnectionDetectedQuickly() {
239+
public void testFollowerDisconnectionWithDisconnectEventDetectedQuickly() {
233240
final Cluster cluster = new Cluster(randomIntBetween(3, 5));
234241
cluster.runRandomly();
235242
cluster.stabilise();
@@ -238,32 +245,40 @@ public void testFollowerDisconnectionDetectedQuickly() {
238245
final ClusterNode follower = cluster.getAnyNodeExcept(leader);
239246
logger.info("--> disconnecting follower {}", follower);
240247
follower.disconnect();
241-
boolean leaderGetsDisconnectEvent = randomBoolean();
242-
if (leaderGetsDisconnectEvent) {
243-
logger.info("--> leader {} and follower {} get disconnect event", leader, follower);
244-
leader.onDisconnectEventFrom(follower);
245-
follower.onDisconnectEventFrom(leader); // to turn follower into candidate, which stabilisation asserts at the end
246-
cluster.stabilise(DEFAULT_DELAY_VARIABILITY // disconnect is scheduled
247-
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
248-
} else {
249-
cluster.stabilise(Math.max(
250-
// the leader may have just sent a follower check, which receives no response
251-
defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING)
252-
// wait for the leader to check the follower
253-
+ defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING)
254-
// then wait for the exception response
255-
+ DEFAULT_DELAY_VARIABILITY
256-
// then wait for the removal to be committed
257-
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY,
258-
259-
// ALSO the follower may have just sent a leader check, which receives no response
260-
defaultMillis(LEADER_CHECK_TIMEOUT_SETTING)
261-
// then wait for the follower to check the leader
262-
+ defaultMillis(LEADER_CHECK_INTERVAL_SETTING)
263-
// then wait for the exception response, causing the follower to become a candidate
264-
+ DEFAULT_DELAY_VARIABILITY
265-
));
266-
}
248+
logger.info("--> leader {} and follower {} get disconnect event", leader, follower);
249+
leader.onDisconnectEventFrom(follower);
250+
follower.onDisconnectEventFrom(leader); // to turn follower into candidate, which stabilisation asserts at the end
251+
cluster.stabilise(DEFAULT_DELAY_VARIABILITY // disconnect is scheduled
252+
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
253+
assertThat(cluster.getAnyLeader().getId(), equalTo(leader.getId()));
254+
}
255+
256+
public void testFollowerDisconnectionWithoutDisconnectEventDetectedQuickly() {
257+
final Cluster cluster = new Cluster(randomIntBetween(3, 5));
258+
cluster.runRandomly();
259+
cluster.stabilise();
260+
261+
final ClusterNode leader = cluster.getAnyLeader();
262+
final ClusterNode follower = cluster.getAnyNodeExcept(leader);
263+
logger.info("--> disconnecting follower {}", follower);
264+
follower.disconnect();
265+
cluster.stabilise(Math.max(
266+
// the leader may have just sent a follower check, which receives no response
267+
defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING)
268+
// wait for the leader to check the follower
269+
+ defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING)
270+
// then wait for the exception response
271+
+ DEFAULT_DELAY_VARIABILITY
272+
// then wait for the removal to be committed
273+
+ DEFAULT_CLUSTER_STATE_UPDATE_DELAY,
274+
275+
// ALSO the follower may have just sent a leader check, which receives no response
276+
defaultMillis(LEADER_CHECK_TIMEOUT_SETTING)
277+
// then wait for the follower to check the leader
278+
+ defaultMillis(LEADER_CHECK_INTERVAL_SETTING)
279+
// then wait for the exception response, causing the follower to become a candidate
280+
+ DEFAULT_DELAY_VARIABILITY
281+
));
267282
assertThat(cluster.getAnyLeader().getId(), equalTo(leader.getId()));
268283
}
269284

0 commit comments

Comments
 (0)