Skip to content

Commit e232c55

Browse files
symatMate Szalay-Beko
authored andcommitted
ZOOKEEPER-3188: fix flaky unit MultiAddress unit test
1 parent e892d8d commit e232c55

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainMultiAddressTest.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void shouldReconfigIncrementallyByAddingMoreAddresses() throws Exception
140140

141141
ZooKeeperAdmin zkAdmin = newZooKeeperAdmin(initialQuorumConfig);
142142

143-
// initiating a new incremental reconfig, by adding new ports to each server
143+
// initiating a new incremental reconfig, by using the updated ports
144144
ReconfigTest.reconfig(zkAdmin, newQuorumConfig.buildAsStringList(), null, null, -1);
145145

146146
checkIfZooKeeperQuorumWorks(newQuorumConfig);
@@ -166,14 +166,14 @@ public void shouldReconfigIncrementallyByDeletingSomeAddresses() throws Exceptio
166166

167167
ZooKeeperAdmin zkAdmin = newZooKeeperAdmin(initialQuorumConfig);
168168

169-
// initiating a new incremental reconfig, by adding new ports to each server
169+
// initiating a new incremental reconfig, by using the updated ports
170170
ReconfigTest.reconfig(zkAdmin, newQuorumConfig.buildAsStringList(), null, null, -1);
171171

172172
checkIfZooKeeperQuorumWorks(newQuorumConfig);
173173
}
174174

175175
@Test
176-
public void shouldReconfigNonIncrementallyByChangingAllAddresses() throws Exception {
176+
public void shouldReconfigNonIncrementally() throws Exception {
177177
// we have three ZK servers, each server has two quorumPort and two electionPort registered
178178
QuorumServerConfigBuilder initialQuorumConfig = new QuorumServerConfigBuilder(hostName, 3, 2);
179179

@@ -182,14 +182,18 @@ public void shouldReconfigNonIncrementallyByChangingAllAddresses() throws Except
182182

183183
checkIfZooKeeperQuorumWorks(initialQuorumConfig);
184184

185-
// we create a new config where no ports are the same
186-
// each server will have two new quorumPorts and two new electionPorts
187-
QuorumServerConfigBuilder newQuorumConfig = new QuorumServerConfigBuilder(hostName, 3, 2);
188-
185+
// we create a new config where we delete and add a few address for each server
186+
QuorumServerConfigBuilder newQuorumConfig = new QuorumServerConfigBuilder(initialQuorumConfig)
187+
.deleteLastServerAddress(FIRST_SERVER)
188+
.deleteLastServerAddress(SECOND_SERVER)
189+
.deleteLastServerAddress(SECOND_SERVER)
190+
.deleteLastServerAddress(THIRD_SERVER)
191+
.addNewServerAddress(SECOND_SERVER)
192+
.addNewServerAddress(THIRD_SERVER);
189193

190194
ZooKeeperAdmin zkAdmin = newZooKeeperAdmin(initialQuorumConfig);
191195

192-
// initiating a new non-incremental reconfig, by adding new ports to each server
196+
// initiating a new non-incremental reconfig, by using the updated ports
193197
ReconfigTest.reconfig(zkAdmin, null, null, newQuorumConfig.buildAsStringList(), -1);
194198

195199
checkIfZooKeeperQuorumWorks(newQuorumConfig);
@@ -220,7 +224,7 @@ public void shouldReconfigIncrementally_IPv6() throws Exception {
220224

221225
ZooKeeperAdmin zkAdmin = newZooKeeperAdmin(initialQuorumConfig);
222226

223-
// initiating a new incremental reconfig, by adding new ports to each server
227+
// initiating a new incremental reconfig, by using the updated ports
224228
ReconfigTest.reconfig(zkAdmin, newQuorumConfig.buildAsStringList(), null, null, -1);
225229

226230
checkIfZooKeeperQuorumWorks(newQuorumConfig);
@@ -256,6 +260,7 @@ private void launchServers(List<QuorumServerConfigBuilder> builders) throws IOEx
256260
private void checkIfZooKeeperQuorumWorks(QuorumServerConfigBuilder builder) throws IOException,
257261
InterruptedException, KeeperException {
258262

263+
LOG.info("starting to verify if Quorum works");
259264
zNodeId += 1;
260265
String zNodePath = "/foo_" + zNodeId;
261266
ZooKeeper zk = connectToZkServer(builder, FIRST_SERVER);
@@ -272,6 +277,8 @@ private void checkIfZooKeeperQuorumWorks(QuorumServerConfigBuilder builder) thro
272277
assertEquals(new String(zk.getData(zNodePath, null, null)), "foobar1");
273278
zk.close(1000);
274279

280+
LOG.info("Quorum verification finished successfully");
281+
275282
}
276283

277284
private ZooKeeper connectToZkServer(QuorumServerConfigBuilder builder, int serverId) throws IOException, InterruptedException {

zookeeper-server/src/test/java/org/apache/zookeeper/test/ReconfigTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static String reconfig(
9494
long fromConfig) throws KeeperException, InterruptedException {
9595
byte[] config = null;
9696
String failure = null;
97+
LOG.info("reconfig initiated by the test");
9798
for (int j = 0; j < 30; j++) {
9899
try {
99100
config = zkAdmin.reconfigure(joiningServers, leavingServers, newMembers, fromConfig, new Stat());

0 commit comments

Comments
 (0)