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 2011/09/17 02:13:31 UTC
svn commit: r1171869 - in /zookeeper/trunk: ./
src/java/test/org/apache/zookeeper/
src/java/test/org/apache/zookeeper/server/quorum/
src/java/test/org/apache/zookeeper/test/
Author: phunt
Date: Sat Sep 17 00:13:30 2011
New Revision: 1171869
URL: http://svn.apache.org/viewvc?rev=1171869&view=rev
Log:
ZOOKEEPER-1182. Make findbugs usable in Eclipse (Thomas Koch via phunt)
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ChrootTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java
zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Sat Sep 17 00:13:30 2011
@@ -25,6 +25,8 @@ IMPROVEMENTS:
ZOOKEEPER-899. Update Netty version in trunk to 3.2.2
(Thomas Koch via phunt)
+ ZOOKEEPER-1182. Make findbugs usable in Eclipse (Thomas Koch via phunt)
+
Release 3.4.0 -
Non-backward compatible changes:
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java Sat Sep 17 00:13:30 2011
@@ -37,7 +37,7 @@ public class JUnit4ZKTestRunner extends
super(klass);
}
- public class LoggedInvokeMethod extends InvokeMethod {
+ public static class LoggedInvokeMethod extends InvokeMethod {
private String name;
public LoggedInvokeMethod(FrameworkMethod method, Object target) {
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java Sat Sep 17 00:13:30 2011
@@ -29,104 +29,96 @@ import java.util.ArrayList;
import org.apache.jute.BinaryInputArchive;
import org.apache.jute.BinaryOutputArchive;
-import org.apache.jute.Index;
-import org.apache.jute.InputArchive;
-import org.apache.jute.Record;
import org.apache.zookeeper.ZKTestCase;
import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.server.ZKDatabase;
-import org.apache.zookeeper.server.ZooKeeperServer;
import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
-import org.apache.zookeeper.server.quorum.Learner;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
import org.apache.zookeeper.txn.CreateTxn;
import org.apache.zookeeper.txn.TxnHeader;
import org.junit.Assert;
import org.junit.Test;
public class LearnerTest extends ZKTestCase {
- class SimpleLearnerZooKeeperServer extends LearnerZooKeeperServer {
- boolean startupCalled;
-
- public SimpleLearnerZooKeeperServer(FileTxnSnapLog ftsl) throws IOException {
- super(ftsl, 2000, 2000, 2000, null, new ZKDatabase(ftsl), null);
- }
- Learner learner;
- @Override
- public Learner getLearner() {
- return learner;
- }
-
- @Override
- public void startup() {
- startupCalled = true;
- }
- }
- class SimpleLearner extends Learner {
- SimpleLearner(FileTxnSnapLog ftsl) throws IOException {
- self = new QuorumPeer();
- zk = new SimpleLearnerZooKeeperServer(ftsl);
- ((SimpleLearnerZooKeeperServer)zk).learner = this;
- }
- }
- static private void recursiveDelete(File dir) {
- if (dir == null || !dir.exists()) {
- return;
- }
- if (!dir.isDirectory()) {
- dir.delete();
- }
- for(File child: dir.listFiles()) {
- recursiveDelete(child);
- }
- }
- @Test
- public void syncTest() throws Exception {
- File tmpFile = File.createTempFile("test", ".dir");
- tmpFile.delete();
- try {
- FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
- SimpleLearner sl = new SimpleLearner(ftsl);
- long startZxid = sl.zk.getLastProcessedZxid();
-
- // Set up bogus streams
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
- sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
-
- // make streams and socket do something innocuous
- sl.bufferedOutput = new BufferedOutputStream(System.out);
- sl.sock = new Socket();
-
- // fake messages from the server
- QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
- oa.writeRecord(qp, null);
- sl.zk.getZKDatabase().serializeSnapshot(oa);
- oa.writeString("BenWasHere", "signature");
- TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
- CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
- ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
- BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
- hdr.serialize(boa, "hdr");
- txn.serialize(boa, "txn");
- tbaos.close();
- qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
- oa.writeRecord(qp, null);
-
- // setup the messages to be streamed to follower
- sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
-
- try {
- sl.syncWithLeader(3);
- } catch(EOFException e) {}
-
- sl.zk.shutdown();
- sl = new SimpleLearner(ftsl);
- Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid());
- } finally {
- recursiveDelete(tmpFile);
- }
- }
+ static class SimpleLearnerZooKeeperServer extends LearnerZooKeeperServer {
+
+ Learner learner;
+
+ public SimpleLearnerZooKeeperServer(FileTxnSnapLog ftsl) throws IOException {
+ super(ftsl, 2000, 2000, 2000, null, new ZKDatabase(ftsl), null);
+ }
+
+ @Override
+ public Learner getLearner() {
+ return learner;
+ }
+ }
+
+ static class SimpleLearner extends Learner {
+ SimpleLearner(FileTxnSnapLog ftsl) throws IOException {
+ self = new QuorumPeer();
+ zk = new SimpleLearnerZooKeeperServer(ftsl);
+ ((SimpleLearnerZooKeeperServer) zk).learner = this;
+ }
+ }
+
+ static private void recursiveDelete(File dir) {
+ if (dir == null || !dir.exists()) {
+ return;
+ }
+ if (!dir.isDirectory()) {
+ dir.delete();
+ }
+ for (File child : dir.listFiles()) {
+ recursiveDelete(child);
+ }
+ }
+
+ @Test
+ public void syncTest() throws Exception {
+ File tmpFile = File.createTempFile("test", ".dir");
+ tmpFile.delete();
+ try {
+ FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
+ SimpleLearner sl = new SimpleLearner(ftsl);
+ long startZxid = sl.zk.getLastProcessedZxid();
+
+ // Set up bogus streams
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
+ sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
+
+ // make streams and socket do something innocuous
+ sl.bufferedOutput = new BufferedOutputStream(System.out);
+ sl.sock = new Socket();
+
+ // fake messages from the server
+ QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
+ oa.writeRecord(qp, null);
+ sl.zk.getZKDatabase().serializeSnapshot(oa);
+ oa.writeString("BenWasHere", "signature");
+ TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
+ CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
+ ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
+ BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
+ hdr.serialize(boa, "hdr");
+ txn.serialize(boa, "txn");
+ tbaos.close();
+ qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
+ oa.writeRecord(qp, null);
+
+ // setup the messages to be streamed to follower
+ sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
+
+ try {
+ sl.syncWithLeader(3);
+ } catch (EOFException e) {}
+
+ sl.zk.shutdown();
+ sl = new SimpleLearner(ftsl);
+ Assert.assertEquals(startZxid, sl.zk.getLastProcessedZxid());
+ } finally {
+ recursiveDelete(tmpFile);
+ }
+ }
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java Sat Sep 17 00:13:30 2011
@@ -37,25 +37,21 @@ import org.apache.log4j.WriterAppender;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooDefs.OpCode;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper.States;
import org.apache.zookeeper.server.quorum.Leader.Proposal;
-import org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread;
import org.apache.zookeeper.test.ClientBase;
import org.junit.Assert;
import org.junit.Test;
-
/**
* Test stand-alone server.
*
*/
public class QuorumPeerMainTest extends QuorumPeerTestBase {
- /**
+ /**
* Verify the ability to start a cluster.
*/
@Test
@@ -66,10 +62,10 @@ public class QuorumPeerMainTest extends
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
- "server.1=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique()
- + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique();
+ "server.1=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique()
+ + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
@@ -77,13 +73,12 @@ public class QuorumPeerMainTest extends
q2.start();
Assert.assertTrue("waiting for server 1 being up",
- ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
+ ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 being up",
- ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
+ ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
CONNECTION_TIMEOUT));
-
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT, this);
@@ -121,133 +116,133 @@ public class QuorumPeerMainTest extends
final int SERVER_COUNT = 3;
final int clientPorts[] = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
- for(int i = 0; i < SERVER_COUNT; i++) {
- clientPorts[i] = PortAssignment.unique();
- sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+"\n");
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ clientPorts[i] = PortAssignment.unique();
+ sb.append("server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + "\n");
}
String quorumCfgSection = sb.toString();
MainThread mt[] = new MainThread[SERVER_COUNT];
ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
- for(int i = 0; i < SERVER_COUNT; i++) {
- mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
- mt[i].start();
- zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
+ mt[i].start();
+ zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
}
-
+
waitForAll(zk, States.CONNECTED);
-
+
// we need to shutdown and start back up to make sure that the create session isn't the first transaction since
// that is rather innocuous.
- for(int i = 0; i < SERVER_COUNT; i++) {
- mt[i].shutdown();
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ mt[i].shutdown();
}
-
+
waitForAll(zk, States.CONNECTING);
-
- for(int i = 0; i < SERVER_COUNT; i++) {
- mt[i].start();
+
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ mt[i].start();
}
-
+
waitForAll(zk, States.CONNECTED);
-
+
// ok lets find the leader and kill everything else, we have a few
// seconds, so it should be plenty of time
int leader = -1;
Map<Long, Proposal> outstanding = null;
- for(int i = 0; i < SERVER_COUNT; i++) {
- if (mt[i].main.quorumPeer.leader == null) {
- mt[i].shutdown();
- } else {
- leader = i;
- outstanding = mt[leader].main.quorumPeer.leader.outstandingProposals;
- }
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ if (mt[i].main.quorumPeer.leader == null) {
+ mt[i].shutdown();
+ } else {
+ leader = i;
+ outstanding = mt[leader].main.quorumPeer.leader.outstandingProposals;
+ }
}
-
+
try {
- zk[leader].create("/zk"+leader, "zk".getBytes(), Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
- Assert.fail("create /zk" + leader + " should have failed");
- } catch(KeeperException e) {}
-
- // just make sure that we actually did get it in process at the
+ zk[leader].create("/zk" + leader, "zk".getBytes(), Ids.OPEN_ACL_UNSAFE,
+ CreateMode.PERSISTENT);
+ Assert.fail("create /zk" + leader + " should have failed");
+ } catch (KeeperException e) {}
+
+ // just make sure that we actually did get it in process at the
// leader
Assert.assertTrue(outstanding.size() == 1);
- Assert.assertTrue(((Proposal)outstanding.values().iterator().next()).request.hdr.getType() == OpCode.create);
+ Assert.assertTrue(((Proposal) outstanding.values().iterator().next()).request.hdr.getType() == OpCode.create);
// make sure it has a chance to write it to disk
Thread.sleep(1000);
mt[leader].shutdown();
waitForAll(zk, States.CONNECTING);
- for(int i = 0; i < SERVER_COUNT; i++) {
- if (i != leader) {
- mt[i].start();
- }
- }
- for(int i = 0; i < SERVER_COUNT; i++) {
- if (i != leader) {
- waitForOne(zk[i], States.CONNECTED);
- zk[i].create("/zk" + i, "zk".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- }
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ if (i != leader) {
+ mt[i].start();
+ }
}
-
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ if (i != leader) {
+ waitForOne(zk[i], States.CONNECTED);
+ zk[i].create("/zk" + i, "zk".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
+ }
+
mt[leader].start();
waitForAll(zk, States.CONNECTED);
// make sure everything is consistent
- for(int i = 0; i < SERVER_COUNT; i++) {
- for(int j = 0; j < SERVER_COUNT; j++) {
- if (i == leader) {
- Assert.assertTrue((j==leader?("Leader ("+leader+")"):("Follower "+j))+" should not have /zk" + i, zk[j].exists("/zk"+i, false) == null);
- } else {
- Assert.assertTrue((j==leader?("Leader ("+leader+")"):("Follower "+j))+" does not have /zk" + i, zk[j].exists("/zk"+i, false) != null);
- }
- }
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ for (int j = 0; j < SERVER_COUNT; j++) {
+ if (i == leader) {
+ Assert.assertTrue((j == leader ? ("Leader (" + leader + ")") : ("Follower " + j)) + " should not have /zk" + i, zk[j].exists("/zk" + i, false) == null);
+ } else {
+ Assert.assertTrue((j == leader ? ("Leader (" + leader + ")") : ("Follower " + j)) + " does not have /zk" + i, zk[j].exists("/zk" + i, false) != null);
+ }
+ }
}
- for(int i = 0; i < SERVER_COUNT; i++) {
- zk[i].close();
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ zk[i].close();
}
- for(int i = 0; i < SERVER_COUNT; i++) {
- mt[i].shutdown();
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ mt[i].shutdown();
}
}
-
+
/**
* Test the case of server with highest zxid not present at leader election and joining later.
- * This test case is for reproducing the issue and fixing the bug mentioned in ZOOKEEPER-1154
- * and ZOOKEEPER-1156.
+ * This test case is for reproducing the issue and fixing the bug mentioned in ZOOKEEPER-1154
+ * and ZOOKEEPER-1156.
*/
@Test
public void testHighestZxidJoinLate() throws Exception {
int numServers = 3;
Servers svrs = LaunchServers(numServers);
String path = "/hzxidtest";
- int leader=-1;
+ int leader = -1;
// find the leader
- for (int i=0; i < numServers; i++) {
+ for (int i = 0; i < numServers; i++) {
if (svrs.mt[i].main.quorumPeer.leader != null) {
leader = i;
}
}
-
+
// make sure there is a leader
- Assert.assertTrue("There should be a leader", leader >=0);
+ Assert.assertTrue("There should be a leader", leader >= 0);
- int nonleader = (leader+1)%numServers;
+ int nonleader = (leader + 1) % numServers;
byte[] input = new byte[1];
input[0] = 1;
byte[] output;
// Create a couple of nodes
- svrs.zk[leader].create(path+leader, input, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- svrs.zk[leader].create(path+nonleader, input, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
+ svrs.zk[leader].create(path + leader, input, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ svrs.zk[leader].create(path + nonleader, input, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+
// make sure the updates indeed committed. If it is not
// the following statement will throw.
- output = svrs.zk[leader].getData(path+nonleader, false, null);
-
+ output = svrs.zk[leader].getData(path + nonleader, false, null);
+
// Shutdown every one else but the leader
- for (int i=0; i < numServers; i++) {
+ for (int i = 0; i < numServers; i++) {
if (i != leader) {
svrs.mt[i].shutdown();
}
@@ -256,8 +251,8 @@ public class QuorumPeerMainTest extends
input[0] = 2;
// Update the node on the leader
- svrs.zk[leader].setData(path+leader, input, -1, null, null);
-
+ svrs.zk[leader].setData(path + leader, input, -1, null, null);
+
// wait some time to let this get written to disk
Thread.sleep(500);
@@ -269,7 +264,7 @@ public class QuorumPeerMainTest extends
waitForAll(svrs.zk, States.CONNECTING);
// Start everyone but the leader
- for (int i=0; i < numServers; i++) {
+ for (int i = 0; i < numServers; i++) {
if (i != leader) {
svrs.mt[i].start();
}
@@ -279,7 +274,7 @@ public class QuorumPeerMainTest extends
waitForOne(svrs.zk[nonleader], States.CONNECTED);
// validate that the old value is there and not the new one
- output = svrs.zk[nonleader].getData(path+leader, false, null);
+ output = svrs.zk[nonleader].getData(path + leader, false, null);
Assert.assertEquals(
"Expecting old value 1 since 2 isn't committed yet",
@@ -287,91 +282,90 @@ public class QuorumPeerMainTest extends
// Do some other update, so we bump the maxCommttedZxid
// by setting the value to 2
- svrs.zk[nonleader].setData(path+nonleader, input, -1);
+ svrs.zk[nonleader].setData(path + nonleader, input, -1);
- // start the old leader
+ // start the old leader
svrs.mt[leader].start();
// connect to it
waitForOne(svrs.zk[leader], States.CONNECTED);
// make sure it doesn't have the new value that it alone had logged
- output = svrs.zk[leader].getData(path+leader, false, null);
+ output = svrs.zk[leader].getData(path + leader, false, null);
Assert.assertEquals(
"Validating that the deposed leader has rolled back that change it had written",
output[0], 1);
-
+
// make sure the leader has the subsequent changes that were made while it was offline
- output = svrs.zk[leader].getData(path+nonleader, false, null);
+ output = svrs.zk[leader].getData(path + nonleader, false, null);
Assert.assertEquals(
"Validating that the deposed leader caught up on changes it missed",
output[0], 2);
}
private void waitForOne(ZooKeeper zk, States state) throws InterruptedException {
- while(zk.getState() != state) {
- Thread.sleep(500);
- }
- }
-
- private void waitForAll(ZooKeeper[] zks, States state) throws InterruptedException {
- int iterations = 10;
- boolean someoneNotConnected = true;
- while(someoneNotConnected) {
- if (iterations-- == 0) {
- throw new RuntimeException("Waiting too long");
- }
-
- someoneNotConnected = false;
- for(ZooKeeper zk: zks) {
- if (zk.getState() != state) {
- someoneNotConnected = true;
- }
- }
- Thread.sleep(1000);
+ while (zk.getState() != state) {
+ Thread.sleep(500);
+ }
+ }
+
+ private void waitForAll(ZooKeeper[] zks, States state) throws InterruptedException {
+ int iterations = 10;
+ boolean someoneNotConnected = true;
+ while (someoneNotConnected) {
+ if (iterations-- == 0) {
+ throw new RuntimeException("Waiting too long");
+ }
+
+ someoneNotConnected = false;
+ for (ZooKeeper zk : zks) {
+ if (zk.getState() != state) {
+ someoneNotConnected = true;
+ }
+ }
+ Thread.sleep(1000);
}
- }
+ }
// This class holds the servers and clients for those servers
- private class Servers {
- MainThread mt[];
- ZooKeeper zk[];
- }
-
- /**
- * This is a helper function for launching a set of servers
- *
- * @param numServers
- * @return
- * @throws IOException
- * @throws InterruptedException
- */
- private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
- int SERVER_COUNT = numServers;
- Servers svrs = new Servers();
- final int clientPorts[] = new int[SERVER_COUNT];
- StringBuilder sb = new StringBuilder();
- for(int i = 0; i < SERVER_COUNT; i++) {
- clientPorts[i] = PortAssignment.unique();
- sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+"\n");
- }
- String quorumCfgSection = sb.toString();
-
- MainThread mt[] = new MainThread[SERVER_COUNT];
- ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
- for(int i = 0; i < SERVER_COUNT; i++) {
- mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
- mt[i].start();
- zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
- }
-
- waitForAll(zk, States.CONNECTED);
-
- svrs.mt = mt;
- svrs.zk = zk;
- return svrs;
- }
+ private static class Servers {
+ MainThread mt[];
+ ZooKeeper zk[];
+ }
+ /**
+ * This is a helper function for launching a set of servers
+ *
+ * @param numServers
+ * @return
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
+ int SERVER_COUNT = numServers;
+ Servers svrs = new Servers();
+ final int clientPorts[] = new int[SERVER_COUNT];
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ clientPorts[i] = PortAssignment.unique();
+ sb.append("server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + "\n");
+ }
+ String quorumCfgSection = sb.toString();
+
+ MainThread mt[] = new MainThread[SERVER_COUNT];
+ ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
+ for (int i = 0; i < SERVER_COUNT; i++) {
+ mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
+ mt[i].start();
+ zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
+ }
+
+ waitForAll(zk, States.CONNECTED);
+
+ svrs.mt = mt;
+ svrs.zk = zk;
+ return svrs;
+ }
/**
* Verify handling of bad quorum address
@@ -382,7 +376,7 @@ public class QuorumPeerMainTest extends
// setup the logger to capture all logs
Layout layout =
- Logger.getRootLogger().getAppender("CONSOLE").getLayout();
+ Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setThreshold(Level.WARN);
@@ -394,17 +388,17 @@ public class QuorumPeerMainTest extends
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
- "server.1=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique()
- + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique()
- + ":" + PortAssignment.unique();
+ "server.1=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique()
+ + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
boolean isup =
- ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
- 5000);
+ ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
+ 5000);
Assert.assertFalse("Server never came up", isup);
@@ -422,7 +416,7 @@ public class QuorumPeerMainTest extends
String line;
boolean found = false;
Pattern p =
- Pattern.compile(".*Cannot open channel to .* at election address .*");
+ Pattern.compile(".*Cannot open channel to .* at election address .*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
@@ -441,14 +435,14 @@ public class QuorumPeerMainTest extends
// setup the logger to capture all logs
Layout layout =
- Logger.getRootLogger().getAppender("CONSOLE").getLayout();
+ Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setThreshold(Level.INFO);
Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
qlogger.addAppender(appender);
- // test the most likely situation only: server is stated as observer in
+ // test the most likely situation only: server is stated as observer in
// servers list, but there's no "peerType=observer" token in config
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
@@ -456,12 +450,12 @@ public class QuorumPeerMainTest extends
final int CLIENT_PORT_QP3 = PortAssignment.unique();
String quorumCfgSection =
- "server.1=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique()
- + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique()
- + "\nserver.3=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique() + ":observer";
+ "server.1=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique()
+ + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique()
+ + "\nserver.3=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique() + ":observer";
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
@@ -503,10 +497,10 @@ public class QuorumPeerMainTest extends
boolean warningPresent = false;
boolean defaultedToObserver = false;
Pattern pWarn =
- Pattern.compile(".*Peer type from servers list.* doesn't match peerType.*");
+ Pattern.compile(".*Peer type from servers list.* doesn't match peerType.*");
Pattern pObserve = Pattern.compile(".*OBSERVING.*");
while ((line = r.readLine()) != null) {
- if (pWarn.matcher(line).matches()) {
+ if (pWarn.matcher(line).matches()) {
warningPresent = true;
}
if (pObserve.matcher(line).matches()) {
@@ -516,12 +510,12 @@ public class QuorumPeerMainTest extends
break;
}
}
- Assert.assertTrue("Should warn about inconsistent peer type",
+ Assert.assertTrue("Should warn about inconsistent peer type",
warningPresent && defaultedToObserver);
}
/**
- * verify if bad packets are being handled properly
+ * verify if bad packets are being handled properly
* at the quorum port
* @throws Exception
*/
@@ -533,25 +527,25 @@ public class QuorumPeerMainTest extends
int electionPort1 = PortAssignment.unique();
int electionPort2 = PortAssignment.unique();
String quorumCfgSection =
- "server.1=127.0.0.1:" + PortAssignment.unique()
- + ":" + electionPort1
- + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
- + ":" + electionPort2;
-
+ "server.1=127.0.0.1:" + PortAssignment.unique()
+ + ":" + electionPort1
+ + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ + ":" + electionPort2;
+
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
q1.start();
q2.start();
-
+
Assert.assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 being up",
- ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
- CONNECTION_TIMEOUT));
-
+ ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
+ CONNECTION_TIMEOUT));
+
byte[] b = new byte[4];
- int length = 1024*1024*1024;
+ int length = 1024 * 1024 * 1024;
ByteBuffer buff = ByteBuffer.wrap(b);
buff.putInt(length);
buff.position(0);
@@ -562,7 +556,7 @@ public class QuorumPeerMainTest extends
s = SocketChannel.open(new InetSocketAddress("127.0.0.1", electionPort2));
s.write(buff);
s.close();
-
+
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT, this);
@@ -574,7 +568,6 @@ public class QuorumPeerMainTest extends
q2.shutdown();
}
-
/**
* Verify handling of quorum defaults
* * default electionAlg is fast leader election
@@ -585,7 +578,7 @@ public class QuorumPeerMainTest extends
// setup the logger to capture all logs
Layout layout =
- Logger.getRootLogger().getAppender("CONSOLE").getLayout();
+ Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
@@ -598,10 +591,10 @@ public class QuorumPeerMainTest extends
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection =
- "server.1=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique()
- + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique();
+ "server.1=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique()
+ + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
@@ -633,7 +626,7 @@ public class QuorumPeerMainTest extends
String line;
boolean found = false;
Pattern p =
- Pattern.compile(".*FastLeaderElection.*");
+ Pattern.compile(".*FastLeaderElection.*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
@@ -651,10 +644,10 @@ public class QuorumPeerMainTest extends
long maxwait = 3000;
final int CLIENT_PORT_QP1 = PortAssignment.unique();
String quorumCfgSection =
- "server.1=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique()
- + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
- + ":" + PortAssignment.unique();
+ "server.1=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique()
+ + "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ + ":" + PortAssignment.unique();
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
// Let the notifications timeout
@@ -663,7 +656,7 @@ public class QuorumPeerMainTest extends
q1.shutdown();
long end = System.currentTimeMillis();
if ((end - start) > maxwait) {
- Assert.fail("QuorumPeer took " + (end -start) +
+ Assert.fail("QuorumPeer took " + (end - start) +
" to shutdown, expected " + maxwait);
}
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ChrootTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ChrootTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ChrootTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ChrootTest.java Sat Sep 17 00:13:30 2011
@@ -33,7 +33,7 @@ import org.junit.Assert;
import org.junit.Test;
public class ChrootTest extends ClientBase {
- private class MyWatcher implements Watcher {
+ private static class MyWatcher implements Watcher {
private final String path;
private String eventPath;
private CountDownLatch latch = new CountDownLatch(1);
@@ -87,7 +87,7 @@ public class ChrootTest extends ClientBa
MyWatcher w3 = new MyWatcher("/ch2");
Assert.assertNotNull(zk2.exists("/ch2", w3));
-
+
// set watches on child
MyWatcher w4 = new MyWatcher("/ch1");
zk1.getChildren("/ch1",w4);
@@ -121,7 +121,7 @@ public class ChrootTest extends ClientBa
zk2.delete("/ch2", -1);
Assert.assertTrue(w4.matches());
Assert.assertTrue(w5.matches());
-
+
zk1.delete("/ch1", -1);
Assert.assertNull(zk1.exists("/ch1", false));
Assert.assertNull(zk1.exists("/ch1/ch2", false));
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java Sat Sep 17 00:13:30 2011
@@ -70,9 +70,9 @@ public abstract class ClientBase extends
protected int maxCnxns = 0;
protected ServerCnxnFactory serverFactory = null;
protected File tmpDir = null;
-
+
long initialFdCount;
-
+
public ClientBase() {
super();
}
@@ -83,7 +83,7 @@ public abstract class ClientBase extends
* use empty watchers in real code!
*
*/
- protected class NullWatcher implements Watcher {
+ protected static class NullWatcher implements Watcher {
public void process(WatchedEvent event) { /* nada */ }
}
@@ -360,7 +360,7 @@ public abstract class ClientBase extends
ZKDatabase zkDb;
{
ZooKeeperServer zs = getServer(factory);
-
+
zkDb = zs.getZKDatabase();
}
factory.shutdown();
@@ -579,7 +579,7 @@ public abstract class ClientBase extends
// verify all the servers reporting same number of nodes
String logmsg = "node count not consistent{} {}";
for (int i = 1; i < parts.length; i++) {
- if (counts[i-1] != counts[i]) {
+ if (counts[i-1] != counts[i]) {
LOG.error(logmsg, Integer.valueOf(counts[i-1]), Integer.valueOf(counts[i]));
} else {
LOG.info(logmsg, Integer.valueOf(counts[i-1]), Integer.valueOf(counts[i]));
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientHammerTest.java Sat Sep 17 00:13:30 2011
@@ -214,8 +214,8 @@ public class ClientHammerTest extends Cl
for (HammerThread h : threads) {
final int safetyFactor = 3;
verifyThreadTerminated(h,
- threads.length * childCount
- * HAMMERTHREAD_LATENCY * safetyFactor);
+ (long)threads.length * (long)childCount
+ * HAMMERTHREAD_LATENCY * (long)safetyFactor);
}
LOG.info(new Date() + " Total time "
+ (System.currentTimeMillis() - start));
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java Sat Sep 17 00:13:30 2011
@@ -55,11 +55,11 @@ public class CnxManagerTest extends ZKTe
public void setUp() throws Exception {
this.count = 3;
- this.peers = new HashMap<Long,QuorumServer>(count);
+ this.peers = new HashMap<Long,QuorumServer>(count);
peerTmpdir = new File[count];
peerQuorumPort = new int[count];
peerClientPort = new int[count];
-
+
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
@@ -140,7 +140,7 @@ public class CnxManagerTest extends ZKTe
CnxManagerThread thread = new CnxManagerThread();
thread.start();
-
+
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
QuorumCnxManager.Listener listener = cnxManager.listener;
@@ -150,7 +150,7 @@ public class CnxManagerTest extends ZKTe
LOG.error("Null listener when initializing cnx manager");
}
- cnxManager.toSend(new Long(0), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
+ cnxManager.toSend(0L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
Message m = null;
int numRetries = 1;
@@ -158,7 +158,7 @@ public class CnxManagerTest extends ZKTe
m = cnxManager.pollRecvQueue(3000, TimeUnit.MILLISECONDS);
if(m == null) cnxManager.connectAll();
}
-
+
Assert.assertTrue("Exceeded number of retries", numRetries <= THRESHOLD);
thread.join(5000);
@@ -168,7 +168,7 @@ public class CnxManagerTest extends ZKTe
if(thread.failed)
Assert.fail("Did not receive expected message");
}
-
+
}
@Test
@@ -176,16 +176,16 @@ public class CnxManagerTest extends ZKTe
Random rand = new Random();
byte b = (byte) rand.nextInt();
int deadPort = PortAssignment.unique();
- String deadAddress = new String("10.1.1." + b);
-
+ String deadAddress = "10.1.1." + b;
+
LOG.info("This is the dead address I'm trying: " + deadAddress);
-
+
peers.put(Long.valueOf(2),
new QuorumServer(2,
new InetSocketAddress(deadAddress, deadPort),
new InetSocketAddress(deadAddress, PortAssignment.unique())));
peerTmpdir[2] = ClientBase.createTmpDir();
-
+
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
QuorumCnxManager.Listener listener = cnxManager.listener;
@@ -196,23 +196,23 @@ public class CnxManagerTest extends ZKTe
}
long begin = System.currentTimeMillis();
- cnxManager.toSend(new Long(2), createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
+ cnxManager.toSend(2L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
long end = System.currentTimeMillis();
-
+
if((end - begin) > 6000) Assert.fail("Waited more than necessary");
-
- }
-
+
+ }
+
/**
* Tests a bug in QuorumCnxManager that causes a spin lock
- * when a negative value is sent. This test checks if the
+ * when a negative value is sent. This test checks if the
* connection is being closed upon a message with negative
* length.
- *
+ *
* @throws Exception
*/
@Test
- public void testCnxManagerSpinLock() throws Exception {
+ public void testCnxManagerSpinLock() throws Exception {
QuorumPeer peer = new QuorumPeer(peers, peerTmpdir[1], peerTmpdir[1], peerClientPort[1], 3, 1, 1000, 2, 2);
QuorumCnxManager cnxManager = new QuorumCnxManager(peer);
QuorumCnxManager.Listener listener = cnxManager.listener;
@@ -221,32 +221,31 @@ public class CnxManagerTest extends ZKTe
} else {
LOG.error("Null listener when initializing cnx manager");
}
-
+
int port = peers.get(peer.getId()).electionAddr.getPort();
LOG.info("Election port: " + port);
- InetSocketAddress addr = new InetSocketAddress(port);
-
+
Thread.sleep(1000);
-
+
SocketChannel sc = SocketChannel.open();
- sc.socket().connect(peers.get(new Long(1)).electionAddr, 5000);
-
+ sc.socket().connect(peers.get(1L).electionAddr, 5000);
+
/*
* Write id first then negative length.
*/
byte[] msgBytes = new byte[8];
ByteBuffer msgBuffer = ByteBuffer.wrap(msgBytes);
- msgBuffer.putLong(new Long(2));
+ msgBuffer.putLong(2L);
msgBuffer.position(0);
sc.write(msgBuffer);
-
+
msgBuffer = ByteBuffer.wrap(new byte[4]);
msgBuffer.putInt(-20);
msgBuffer.position(0);
sc.write(msgBuffer);
-
+
Thread.sleep(1000);
-
+
try{
/*
* Write a number of times until it
@@ -262,7 +261,7 @@ public class CnxManagerTest extends ZKTe
}
peer.shutdown();
cnxManager.halt();
- }
+ }
/*
* Test if a receiveConnection is able to timeout on socket errors
@@ -279,11 +278,10 @@ public class CnxManagerTest extends ZKTe
}
int port = peers.get(peer.getId()).electionAddr.getPort();
LOG.info("Election port: " + port);
- InetSocketAddress addr = new InetSocketAddress(port);
Thread.sleep(1000);
-
+
Socket sock = new Socket();
- sock.connect(peers.get(new Long(1)).electionAddr, 5000);
+ sock.connect(peers.get(1L).electionAddr, 5000);
long begin = System.currentTimeMillis();
// Read without sending data. Verify timeout.
cnxManager.receiveConnection(sock);
@@ -336,7 +334,7 @@ public class CnxManagerTest extends ZKTe
}
/**
- * Returns null on success, otw the message assoc with the failure
+ * Returns null on success, otw the message assoc with the failure
* @throws InterruptedException
*/
public String verifyThreadCount(ArrayList<QuorumPeer> peerList, long ecnt)
@@ -359,9 +357,9 @@ public class CnxManagerTest extends ZKTe
QuorumCnxManager cnxManager = peer.getQuorumCnxManager();
long cnt = cnxManager.getThreadCount();
if (cnt != ecnt) {
- return new String(new Date()
+ return new Date()
+ " Incorrect number of Worker threads for sid=" + myid
- + " expected " + ecnt + " found " + cnt);
+ + " expected " + ecnt + " found " + cnt;
}
}
return null;
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLELostMessageTest.java Sat Sep 17 00:13:30 2011
@@ -42,14 +42,14 @@ import org.junit.Test;
public class FLELostMessageTest extends ZKTestCase {
protected static final Logger LOG = LoggerFactory.getLogger(FLELostMessageTest.class);
-
+
int count;
HashMap<Long,QuorumServer> peers;
File tmpdir[];
int port[];
-
+
QuorumCnxManager cnxManager;
-
+
@Before
public void setUp() throws Exception {
count = 3;
@@ -65,9 +65,9 @@ public class FLELostMessageTest extends
}
- class LEThread extends Thread {
- int i;
- QuorumPeer peer;
+ static class LEThread extends Thread {
+ private int i;
+ private QuorumPeer peer;
LEThread(QuorumPeer peer, int i) {
this.i = i;
@@ -95,7 +95,7 @@ public class FLELostMessageTest extends
peer.setCurrentVote(v);
LOG.info("Finished election: " + i + ", " + v.getId());
-
+
Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING);
} catch (Exception e) {
e.printStackTrace();
@@ -105,8 +105,7 @@ public class FLELostMessageTest extends
}
@Test
public void testLostMessage() throws Exception {
- FastLeaderElection le[] = new FastLeaderElection[count];
-
+
LOG.info("TestLE: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
int clientport = PortAssignment.unique();
@@ -117,16 +116,16 @@ public class FLELostMessageTest extends
tmpdir[i] = ClientBase.createTmpDir();
port[i] = clientport;
}
-
+
/*
* Start server 0
*/
-
+
QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2);
peer.startLeaderElection();
LEThread thread = new LEThread(peer, 1);
thread.start();
-
+
/*
* Start mock server 1
*/
@@ -136,24 +135,24 @@ public class FLELostMessageTest extends
Assert.fail("Threads didn't join");
}
}
-
+
ByteBuffer createMsg(int state, long leader, long zxid, long epoch){
byte requestBytes[] = new byte[28];
- ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);
-
+ ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);
+
/*
* Building notification packet to send
*/
-
+
requestBuffer.clear();
requestBuffer.putInt(state);
requestBuffer.putLong(leader);
requestBuffer.putLong(zxid);
requestBuffer.putLong(epoch);
-
+
return requestBuffer;
}
-
+
void mockServer() throws InterruptedException, IOException {
/*
* Create an instance of the connection manager
@@ -166,9 +165,9 @@ public class FLELostMessageTest extends
} else {
LOG.error("Null listener when initializing cnx manager");
}
-
- cnxManager.toSend(new Long(1), createMsg(ServerState.LOOKING.ordinal(), 0, 0, 1));
+
+ cnxManager.toSend(1l, createMsg(ServerState.LOOKING.ordinal(), 0, 0, 1));
cnxManager.recvQueue.take();
- cnxManager.toSend(new Long(1), createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 1));
+ cnxManager.toSend(1L, createMsg(ServerState.FOLLOWING.ordinal(), 1, 0, 1));
}
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLERestartTest.java Sat Sep 17 00:13:30 2011
@@ -23,7 +23,6 @@ import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Random;
import java.util.concurrent.Semaphore;
import org.slf4j.Logger;
@@ -43,12 +42,19 @@ import org.junit.Test;
public class FLERestartTest extends ZKTestCase {
protected static final Logger LOG = LoggerFactory.getLogger(FLETest.class);
+ private int count;
+ private HashMap<Long,QuorumServer> peers;
+ private ArrayList<FLERestartThread> restartThreads;
+ private File tmpdir[];
+ private int port[];
+ private Semaphore finish;
+
static class TestVote {
+ long leader;
+
TestVote(int id, long leader) {
this.leader = leader;
}
-
- long leader;
}
int countVotes(HashSet<TestVote> hs, long id) {
@@ -60,34 +66,13 @@ public class FLERestartTest extends ZKTe
return counter;
}
- int count;
- // int baseport;
- // int baseLEport;
- HashMap<Long,QuorumServer> peers;
- ArrayList<FLERestartThread> restartThreads;
- HashMap<Integer, HashSet<TestVote> > voteMap;
- File tmpdir[];
- int port[];
- int successCount;
- Semaphore finish;
-
- volatile Vote votes[];
- volatile boolean leaderDies;
- volatile long leader = -1;
- //volatile int round = 1;
- Random rand = new Random();
-
@Before
public void setUp() throws Exception {
count = 3;
-
peers = new HashMap<Long,QuorumServer>(count);
restartThreads = new ArrayList<FLERestartThread>(count);
- voteMap = new HashMap<Integer, HashSet<TestVote> >();
- votes = new Vote[count];
tmpdir = new File[count];
port = new int[count];
- successCount = 0;
finish = new Semaphore(0);
}
@@ -171,10 +156,6 @@ public class FLERestartTest extends ZKTe
@Test
public void testLERestart() throws Exception {
- FastLeaderElection le[] = new FastLeaderElection[count];
- leaderDies = true;
- boolean allowOneBadLeader = leaderDies;
-
LOG.info("TestLE: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
peers.put(Long.valueOf(i),
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java Sat Sep 17 00:13:30 2011
@@ -317,9 +317,9 @@ public class FLETest extends ZKTestCase
/*
* Class to verify of the thread has become a follower
*/
- class VerifyState extends Thread {
+ static class VerifyState extends Thread {
volatile private boolean success = false;
- QuorumPeer peer;
+ private QuorumPeer peer;
public VerifyState(QuorumPeer peer) {
this.peer = peer;
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLEZeroWeightTest.java Sat Sep 17 00:13:30 2011
@@ -50,13 +50,8 @@ public class FLEZeroWeightTest extends Z
ArrayList<LEThread> threads;
File tmpdir[];
int port[];
- Object finalObj;
volatile Vote votes[];
- volatile boolean leaderDies;
- volatile long leader = -1;
- Random rand = new Random();
-
@Before
public void setUp() throws Exception {
@@ -67,7 +62,6 @@ public class FLEZeroWeightTest extends Z
votes = new Vote[count];
tmpdir = new File[count];
port = new int[count];
- finalObj = new Object();
String config = "group.1=0:1:2\n" +
"group.2=3:4:5\n" +
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java Sat Sep 17 00:13:30 2011
@@ -50,22 +50,22 @@ import org.junit.Before;
import org.junit.Test;
public class LENonTerminateTest extends ZKTestCase {
- public class MockLeaderElection extends LeaderElection {
+ public static class MockLeaderElection extends LeaderElection {
public MockLeaderElection(QuorumPeer self) {
- super(self);
+ super(self);
}
/**
* Temporary for 3.3.0 - we want to ensure that a round of voting happens
* before any of the peers update their votes. The easiest way to do that
- * is to add a latch that all wait on after counting their votes.
- *
+ * is to add a latch that all wait on after counting their votes.
+ *
* In 3.4.0 we intend to make this class more testable, and therefore
* there should be much less duplicated code.
- *
+ *
* JMX bean method calls are removed to reduce noise.
*/
- public Vote lookForLeader() throws InterruptedException {
+ public Vote lookForLeader() throws InterruptedException {
self.setCurrentVote(new Vote(self.getId(),
self.getLastLoggedZxid()));
// We are going to look for a leader by casting a vote for ourself
@@ -146,7 +146,7 @@ public class LENonTerminateTest extends
}
ElectionResult result = countVotes(votes, heardFrom);
-
+
/**
* This is the only difference from LeaderElection - wait for
* this latch on the first time through this method. This ensures
@@ -157,11 +157,11 @@ public class LENonTerminateTest extends
latch.countDown();
Assert.assertTrue("Thread timed out waiting for latch",
latch.await(10000, TimeUnit.MILLISECONDS));
-
+
// ZOOKEEPER-569:
- // If no votes are received for live peers, reset to voting
- // for ourselves as otherwise we may hang on to a vote
- // for a dead peer
+ // If no votes are received for live peers, reset to voting
+ // for ourselves as otherwise we may hang on to a vote
+ // for a dead peer
if (result.numValidVotes == 0) {
self.setCurrentVote(new Vote(self.getId(),
self.getLastLoggedZxid()));
@@ -177,7 +177,7 @@ public class LENonTerminateTest extends
/*
* We want to make sure we implement the state machine
* correctly. If we are a PARTICIPANT, once a leader
- * is elected we can move either to LEADING or
+ * is elected we can move either to LEADING or
* FOLLOWING. However if we are an OBSERVER, it is an
* error to be elected as a Leader.
*/
@@ -197,7 +197,7 @@ public class LENonTerminateTest extends
? ServerState.LEADING: ServerState.FOLLOWING);
if (self.getPeerState() == ServerState.FOLLOWING) {
Thread.sleep(100);
- }
+ }
return current;
}
}
@@ -206,10 +206,10 @@ public class LENonTerminateTest extends
Thread.sleep(1000);
}
return null;
- }
+ }
}
-
- public class MockQuorumPeer extends QuorumPeer {
+
+ public static class MockQuorumPeer extends QuorumPeer {
public MockQuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
File logDir, int clientPort, int electionAlg,
long myid, int tickTime, int initLimit, int syncLimit)
@@ -220,21 +220,21 @@ public class LENonTerminateTest extends
ServerCnxnFactory.createFactory(clientPort, -1),
new QuorumMaj(countParticipants(quorumPeers)));
}
-
+
protected Election createElectionAlgorithm(int electionAlgorithm){
LOG.info("Returning mocked leader election");
return new MockLeaderElection(this);
}
}
-
-
+
+
protected static final Logger LOG = LoggerFactory.getLogger(FLELostMessageTest.class);
-
+
int count;
HashMap<Long,QuorumServer> peers;
File tmpdir[];
- int port[];
-
+ int port[];
+
@Before
public void setUp() throws Exception {
count = 3;
@@ -247,10 +247,9 @@ public class LENonTerminateTest extends
static final CountDownLatch latch = new CountDownLatch(2);
static final CountDownLatch mockLatch = new CountDownLatch(1);
- class LEThread extends Thread {
- int i;
- QuorumPeer peer;
-
+ private static class LEThread extends Thread {
+ private int i;
+ private QuorumPeer peer;
LEThread(QuorumPeer peer, int i) {
this.i = i;
@@ -259,7 +258,7 @@ public class LENonTerminateTest extends
}
- public void run(){
+ public void run(){
try{
Vote v = null;
peer.setPeerState(ServerState.LOOKING);
@@ -268,7 +267,7 @@ public class LENonTerminateTest extends
if (v == null){
Assert.fail("Thread " + i + " got a null vote");
- }
+ }
/*
* A real zookeeper would take care of setting the current vote. Here
@@ -283,7 +282,7 @@ public class LENonTerminateTest extends
LOG.info("Joining");
}
}
-
+
/**
* This tests ZK-569.
* With three peers A, B and C, the following could happen:
@@ -294,7 +293,7 @@ public class LENonTerminateTest extends
* resetting votes to themselves if the set of votes for live peers is null.
*/
@Test
- public void testNonTermination() throws Exception {
+ public void testNonTermination() throws Exception {
LOG.info("TestNonTermination: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
int clientport = PortAssignment.unique();
@@ -305,22 +304,22 @@ public class LENonTerminateTest extends
tmpdir[i] = ClientBase.createTmpDir();
port[i] = clientport;
}
-
+
/*
- * peer1 and peer2 are A and B in the above example.
+ * peer1 and peer2 are A and B in the above example.
*/
QuorumPeer peer1 = new MockQuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 0, 0, 2, 2, 2);
peer1.startLeaderElection();
LEThread thread1 = new LEThread(peer1, 0);
-
+
QuorumPeer peer2 = new MockQuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 0, 1, 2, 2, 2);
- peer2.startLeaderElection();
+ peer2.startLeaderElection();
LEThread thread2 = new LEThread(peer2, 1);
-
+
/*
* Start mock server.
*/
- Thread thread3 = new Thread() {
+ Thread thread3 = new Thread() {
public void run() {
try {
mockServer();
@@ -329,8 +328,8 @@ public class LENonTerminateTest extends
Assert.fail("Exception when running mocked server " + e);
}
}
- };
-
+ };
+
thread3.start();
Assert.assertTrue("mockServer did not start in 5s",
mockLatch.await(5000, TimeUnit.MILLISECONDS));
@@ -346,12 +345,12 @@ public class LENonTerminateTest extends
Assert.fail("Threads didn't join");
}
}
-
+
/**
* MockServer plays the role of peer C. Respond to two requests for votes
- * with vote for self and then Assert.fail.
+ * with vote for self and then Assert.fail.
*/
- void mockServer() throws InterruptedException, IOException {
+ void mockServer() throws InterruptedException, IOException {
byte b[] = new byte[36];
ByteBuffer responseBuffer = ByteBuffer.wrap(b);
DatagramPacket packet = new DatagramPacket(b, b.length);
@@ -368,11 +367,11 @@ public class LENonTerminateTest extends
responseBuffer.clear();
responseBuffer.getInt(); // Skip the xid
responseBuffer.putLong(2);
-
+
responseBuffer.putLong(current.getId());
responseBuffer.putLong(current.getZxid());
packet.setData(b);
udpSocket.send(packet);
}
- }
+ }
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java Sat Sep 17 00:13:30 2011
@@ -175,13 +175,13 @@ public class LoadFromLogTest extends ZKT
int prevCversion = parent.stat.getCversion();
long prevPzxid = parent.stat.getPzxid();
List<String> child = dt.getChildren(parentName, null, null);
- String childStr = "";
+ StringBuilder childStr = new StringBuilder();
for (String s : child) {
- childStr += s + " ";
+ childStr.append(s).append(" ");
}
LOG.info("Children: " + childStr + " for " + parentName);
LOG.info("(cverions, pzxid): " + prevCversion + ", " + prevPzxid);
-
+
Record txn = null;
TxnHeader txnHeader = null;
if (type == OpCode.delete) {
@@ -198,9 +198,9 @@ public class LoadFromLogTest extends ZKT
int newCversion = parent.stat.getCversion();
long newPzxid = parent.stat.getPzxid();
child = dt.getChildren(parentName, null, null);
- childStr = "";
+ childStr = new StringBuilder();
for (String s : child) {
- childStr += s + " ";
+ childStr.append(s).append(" ");
}
LOG.info("Children: " + childStr + " for " + parentName);
LOG.info("(cverions, pzxid): " +newCversion + ", " + newPzxid);
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MaxCnxnsTest.java Sat Sep 17 00:13:30 2011
@@ -31,7 +31,7 @@ import org.junit.Assert;
import org.junit.Test;
public class MaxCnxnsTest extends ClientBase {
- final private int numCnxns = 30;
+ final private static int numCnxns = 30;
AtomicInteger numConnected = new AtomicInteger(0);
String host;
int port;
@@ -43,11 +43,9 @@ public class MaxCnxnsTest extends Client
}
class CnxnThread extends Thread {
- int i;
- SocketChannel socket;
+
public CnxnThread(int i) {
super("CnxnThread-"+i);
- this.i = i;
}
public void run() {
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java Sat Sep 17 00:13:30 2011
@@ -75,9 +75,7 @@ public class MultiTransactionTest extend
@Test
public void testCreate() throws Exception {
- List<OpResult> results = new ArrayList<OpResult>();
-
- results = zk.multi(Arrays.asList(
+ zk.multi(Arrays.asList(
Op.create("/multi0", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create("/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
@@ -86,7 +84,7 @@ public class MultiTransactionTest extend
zk.getData("/multi1", false, null);
zk.getData("/multi2", false, null);
}
-
+
@Test
public void testCreateDelete() throws Exception {
@@ -154,9 +152,9 @@ public class MultiTransactionTest extend
@Test
public void testUpdateConflict() throws Exception {
-
+
Assert.assertNull(zk.exists("/multi", null));
-
+
try {
zk.multi(Arrays.asList(
Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
@@ -182,7 +180,7 @@ public class MultiTransactionTest extend
}
@Test
- public void TestDeleteUpdateConflict() throws Exception {
+ public void testDeleteUpdateConflict() throws Exception {
/* Delete of a node folowed by an update of the (now) deleted node */
try {
@@ -201,7 +199,7 @@ public class MultiTransactionTest extend
}
@Test
- public void TestGetResults() throws Exception {
+ public void testGetResults() throws Exception {
/* Delete of a node folowed by an update of the (now) deleted node */
try {
zk.multi(Arrays.asList(
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java Sat Sep 17 00:13:30 2011
@@ -301,16 +301,16 @@ public class QuorumTest extends ZKTestCa
QuorumUtil qu = new QuorumUtil(1);
CountdownWatcher watcher = new CountdownWatcher();
qu.startQuorum();
-
+
int index = 1;
while(qu.getPeer(index).peer.leader == null)
index++;
-
+
ZooKeeper zk = new ZooKeeper(
"127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(),
ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
-
+
// break the quorum
qu.shutdown(index);
@@ -360,30 +360,29 @@ public class QuorumTest extends ZKTestCa
public void testNoLogBeforeLeaderEstablishment ()
throws IOException, InterruptedException, KeeperException{
final Semaphore sem = new Semaphore(0);
-
+
QuorumUtil qu = new QuorumUtil(2);
qu.startQuorum();
-
-
+
int index = 1;
while(qu.getPeer(index).peer.leader == null)
index++;
-
+
Leader leader = qu.getPeer(index).peer.leader;
-
+
Assert.assertNotNull(leader);
-
+
/*
* Reusing the index variable to select a follower to connect to
*/
index = (index == 1) ? 2 : 1;
-
+
ZooKeeper zk = new DisconnectableZooKeeper("127.0.0.1:" + qu.getPeer(index).peer.getClientPort(), 1000, new Watcher() {
public void process(WatchedEvent event) {
}});
zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
+
for(int i = 0; i < 50000; i++) {
zk.setData("/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
public void processResult(int rc, String path, Object ctx,
@@ -397,7 +396,7 @@ public class QuorumTest extends ZKTestCa
}
}
}, null);
-
+
if(i == 5000){
qu.shutdown(index);
LOG.info("Shutting down s1");
@@ -413,18 +412,18 @@ public class QuorumTest extends ZKTestCa
// Wait until all updates return
sem.tryAcquire(15000, TimeUnit.MILLISECONDS);
-
+
// Verify that server is following and has the same epoch as the leader
Assert.assertTrue("Not following", qu.getPeer(index).peer.follower != null);
long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L);
long epochL = (leader.getEpoch() >> 32L);
Assert.assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZxid() +
"Current epoch: " + epochF, epochF == epochL);
-
+
}
// skip superhammer and clientcleanup as they are too expensive for quorum
-
+
/**
* Tests if a multiop submitted to a non-leader propagates to the leader properly
* (see ZOOKEEPER-1124).
@@ -439,19 +438,17 @@ public class QuorumTest extends ZKTestCa
QuorumUtil qu = new QuorumUtil(1);
CountdownWatcher watcher = new CountdownWatcher();
qu.startQuorum();
-
+
int index = 1;
while(qu.getPeer(index).peer.leader == null)
index++;
-
+
ZooKeeper zk = new ZooKeeper(
"127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(),
ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
-
- List<OpResult> results = new ArrayList<OpResult>();
- results = zk.multi(Arrays.asList(
+ zk.multi(Arrays.asList(
Op.create("/multi0", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create("/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumUtil.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumUtil.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumUtil.java Sat Sep 17 00:13:30 2011
@@ -51,7 +51,7 @@ public class QuorumUtil {
private static final Logger LOG = LoggerFactory.getLogger(QuorumUtil.class);
- public class PeerStruct {
+ public static class PeerStruct {
public int id;
public QuorumPeer peer;
public File dataDir;
@@ -184,15 +184,15 @@ public class QuorumUtil {
ps.id, tickTime, initLimit, syncLimit);
Assert.assertEquals(ps.clientPort, ps.peer.getClientPort());
- ps.peer.start();
+ ps.peer.start();
}
-
+
public void restart(int id) throws IOException {
start(id);
Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:"
+ getPeer(id).clientPort, ClientBase.CONNECTION_TIMEOUT));
}
-
+
public void startThenShutdown(int id) throws IOException {
PeerStruct ps = getPeer(id);
LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort);
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java Sat Sep 17 00:13:30 2011
@@ -82,7 +82,11 @@ public class SledgeHammer extends Thread
}
System.out.println();
zk.close();
- } catch (Exception e) {
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (KeeperException e) {
e.printStackTrace();
}
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java Sat Sep 17 00:13:30 2011
@@ -36,7 +36,7 @@ public class StaticHostProviderTest exte
public void testNextGoesRound() throws UnknownHostException {
HostProvider hostProvider = getHostProvider(2);
InetSocketAddress first = hostProvider.next(0);
- assertTrue(first instanceof InetSocketAddress);
+ assertTrue(first != null);
hostProvider.next(0);
assertEquals(first, hostProvider.next(0));
}
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java Sat Sep 17 00:13:30 2011
@@ -69,7 +69,7 @@ public class UpgradeTest extends ZKTestC
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
- Stat stat = zk.exists("/", false);
+ zk.exists("/", false);
List<String> children = zk.getChildren("/", false);
Collections.sort(children);
for (int i = 0; i < 10; i++) {
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatchedEventTest.java Sat Sep 17 00:13:30 2011
@@ -29,7 +29,7 @@ import org.junit.Assert;
import org.junit.Test;
public class WatchedEventTest extends ZKTestCase {
-
+
@Test
public void testCreatingWatchedEvent() {
// EventWatch is a simple, immutable type, so all we need to do
@@ -46,7 +46,6 @@ public class WatchedEventTest extends ZK
Assert.assertEquals(ks, we.getState());
Assert.assertEquals("blah", we.getPath());
}
-
}
}
@@ -76,7 +75,7 @@ public class WatchedEventTest extends ZK
try {
WatcherEvent wep = new WatcherEvent(-2342, -252352, "foo");
- WatchedEvent we = new WatchedEvent(wep);
+ new WatchedEvent(wep);
Assert.fail("Was able to create WatchedEvent from bad wrapper");
} catch (RuntimeException re) {
// we're good
@@ -87,7 +86,7 @@ public class WatchedEventTest extends ZK
public void testConvertingToEventWrapper() {
WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
WatcherEvent wew = we.getWrapper();
-
+
Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
Assert.assertEquals("blah", wew.getPath());
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java Sat Sep 17 00:13:30 2011
@@ -44,7 +44,7 @@ import org.junit.Test;
public class WatcherTest extends ClientBase {
protected static final Logger LOG = LoggerFactory.getLogger(WatcherTest.class);
- private final class MyStatCallback implements StatCallback {
+ private final static class MyStatCallback implements StatCallback {
int rc;
public void processResult(int rc, String path, Object ctx, Stat stat) {
((int[])ctx)[0]++;
@@ -131,7 +131,7 @@ public class WatcherTest extends ClientB
}
@Test
- public void testWatcherCount()
+ public void testWatcherCount()
throws IOException, InterruptedException, KeeperException {
ZooKeeper zk1 = null, zk2 = null;
try {
@@ -213,7 +213,7 @@ public class WatcherTest extends ClientB
Assert.assertEquals(COUNT, count[0]);
zk.close();
}
-
+
final int TIMEOUT = 5000;
@Test
Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java?rev=1171869&r1=1171868&r2=1171869&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java Sat Sep 17 00:13:30 2011
@@ -288,7 +288,7 @@ public class ZooKeeperTestClient extends
System.out.println("session id of zk_1: " + zk_1.getSessionId());
zk.close();
- Stat no_stat = zk_1.exists("nosuchnode", false);
+ zk_1.exists("nosuchnode", false);
event = this.getEvent(10);
if (event == null) {