You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2016/06/15 17:15:07 UTC
svn commit: r1748610 - in /zookeeper/branches/branch-3.5: CHANGES.txt
src/java/test/org/apache/zookeeper/test/ReconfigTest.java
Author: phunt
Date: Wed Jun 15 17:15:07 2016
New Revision: 1748610
URL: http://svn.apache.org/viewvc?rev=1748610&view=rev
Log:
ZOOKEEPER-2137: Make testPortChange() less flaky (Michael Han via phunt)
Modified:
zookeeper/branches/branch-3.5/CHANGES.txt
zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ReconfigTest.java
Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1748610&r1=1748609&r2=1748610&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Wed Jun 15 17:15:07 2016
@@ -156,6 +156,9 @@ BUGFIXES:
ZOOKEEPER-2405: getTGT() in Login.java mishandles confidential
information (Michael Han via phunt)
+ ZOOKEEPER-2137: Make testPortChange() less flaky
+ (Michael Han via phunt)
+
IMPROVEMENTS:
ZOOKEEPER-2270: Allow MBeanRegistry to be overridden for better unit tests
Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ReconfigTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ReconfigTest.java?rev=1748610&r1=1748609&r2=1748610&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ReconfigTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/ReconfigTest.java Wed Jun 15 17:15:07 2016
@@ -98,10 +98,17 @@ public class ReconfigTest extends ZKTest
public static String testServerHasConfig(ZooKeeper zk,
List<String> joiningServers, List<String> leavingServers)
throws KeeperException, InterruptedException {
+ boolean testNodeExists = false;
byte[] config = null;
for (int j = 0; j < 30; j++) {
try {
- zk.sync("/", null, null);
+ if (!testNodeExists) {
+ createZNode(zk, "/dummy", "dummy");
+ testNodeExists = true;
+ }
+ // Use setData instead of sync API to force a view update.
+ // Check ZOOKEEPER-2137 for details.
+ zk.setData("/dummy", "dummy".getBytes(), -1);
config = zk.getConfig(false, new Stat());
break;
} catch (KeeperException.ConnectionLossException e) {
@@ -113,8 +120,8 @@ public class ReconfigTest extends ZKTest
Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds.");
}
}
-
}
+
String configStr = new String(config);
if (joiningServers != null) {
for (String joiner : joiningServers) {
@@ -128,24 +135,29 @@ public class ReconfigTest extends ZKTest
return configStr;
}
-
+
public static void testNormalOperation(ZooKeeper writer, ZooKeeper reader)
throws KeeperException, InterruptedException {
- boolean testNodeExists = false;
-
- for (int j = 0; j < 30; j++) {
+ boolean testReaderNodeExists = false;
+ boolean testWriterNodeExists = false;
+
+ for (int j = 0; j < 30; j++) {
try {
- if (!testNodeExists) {
- try{
- writer.create("/test", "test".getBytes(),
- ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- } catch (KeeperException.NodeExistsException e) {
- }
- testNodeExists = true;
- }
+ if (!testWriterNodeExists) {
+ createZNode(writer, "/test", "test");
+ testWriterNodeExists = true;
+ }
+
+ if (!testReaderNodeExists) {
+ createZNode(reader, "/dummy", "dummy");
+ testReaderNodeExists = true;
+ }
+
String data = "test" + j;
writer.setData("/test", data.getBytes(), -1);
- reader.sync("/", null, null);
+ // Use setData instead of sync API to force a view update.
+ // Check ZOOKEEPER-2137 for details.
+ reader.setData("/dummy", "dummy".getBytes(), -1);
byte[] res = reader.getData("/test", null, new Stat());
Assert.assertEquals(data, new String(res));
break;
@@ -158,10 +170,17 @@ public class ReconfigTest extends ZKTest
Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds.");
}
}
-
}
+ }
- }
+ private static void createZNode(ZooKeeper zk, String path, String data)
+ throws KeeperException, InterruptedException {
+ try{
+ zk.create(path, data.getBytes(),
+ ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ } catch (KeeperException.NodeExistsException e) {
+ }
+ }
private int getLeaderId(QuorumUtil qu) {
int leaderId = 1;