You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ma...@apache.org on 2012/02/06 09:49:52 UTC
svn commit: r1240925 - in /zookeeper/branches/branch-3.4: CHANGES.txt
src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
src/java/test/org/apache/zookeeper/test/ClientBase.java
Author: mahadev
Date: Mon Feb 6 08:49:51 2012
New Revision: 1240925
URL: http://svn.apache.org/viewvc?rev=1240925&view=rev
Log:
ZOOKEEPER-1352. server.InvalidSnapshotTest is using connection timeouts that are too short. (phunt via mahadev)
Modified:
zookeeper/branches/branch-3.4/CHANGES.txt
zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1240925&r1=1240924&r2=1240925&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Mon Feb 6 08:49:51 2012
@@ -29,6 +29,9 @@ BUGFIXES:
ZOOKEEPER-1373. Hardcoded SASL login context name clashes with Hadoop security
configuration override. (Eugene Koontz and Thomas Weise via mahadev)
+ ZOOKEEPER-1352. server.InvalidSnapshotTest is using connection timeouts that
+ are too short. (phunt via mahadev)
+
IMPROVEMENTS:
ZOOKEEPER-1322. Cleanup/fix logging in Quorum code. (phunt via mahadev)
Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java?rev=1240925&r1=1240924&r2=1240925&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java Mon Feb 6 08:49:51 2012
@@ -18,95 +18,67 @@
package org.apache.zookeeper.server;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.RandomAccessFile;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.test.ClientBase;
-import org.junit.Assert;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * this test checks that the server works
- * even if the last snapshot is invalidated
- * by corruption or if the server crashes
- * while generating the snapshot.
+ * This test checks that the server works even if the last snapshot is
+ * invalidated by corruption or if the server crashes while generating the
+ * snapshot.
*/
-public class InvalidSnapshotTest extends ZKTestCase implements Watcher {
+public class InvalidSnapshotTest extends ClientBase {
private static final Logger LOG =
- LoggerFactory.getLogger(InvalidSnapshotTest.class);
+ LoggerFactory.getLogger(InvalidSnapshotTest.class);
- private static final String HOSTPORT =
- "127.0.0.1:" + PortAssignment.unique();
- private static final int CONNECTION_TIMEOUT = 3000;
+ public InvalidSnapshotTest() {
+ SyncRequestProcessor.setSnapCount(100);
+ }
/**
- * this test does the main work of testing
- * an invalid snapshot
- * @throws Exception
+ * Validate that the server can come up on an invalid snapshot - by
+ * reverting to a prior snapshot + associated logs.
*/
@Test
public void testInvalidSnapshot() throws Exception {
- File tmpDir = ClientBase.createTmpDir();
- ClientBase.setupTestEnv();
- ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
- SyncRequestProcessor.setSnapCount(100);
- final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
- ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
- f.startup(zks);
- Assert.assertTrue("waiting for server being up ",
- ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
- ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
- try {
- for (int i=0; i< 2000; i++) {
- zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
- }
- } finally {
- zk.close();
- }
- f.shutdown();
- Assert.assertTrue("waiting for server to shutdown",
- ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
- // now corrupt the snapshot
- File snapFile = zks.getTxnLogFactory().findMostRecentSnapshot();
- RandomAccessFile raf = new RandomAccessFile(snapFile, "rws");
- raf.setLength(3);
- raf.close();
- // now restart the server and see if it starts
- zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
- SyncRequestProcessor.setSnapCount(100);
- f = ServerCnxnFactory.createFactory(PORT, -1);
- f.startup(zks);
- Assert.assertTrue("waiting for server being up ",
- ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
- // the server should come up
- zk = new ZooKeeper(HOSTPORT, 20000, this);
- try {
- Assert.assertTrue("the node should exist",
- (zk.exists("/invalidsnap-1999", false) != null));
- f.shutdown();
- Assert.assertTrue("waiting for server to shutdown",
- ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
- } finally {
- zk.close();
- }
-
- f.shutdown();
- Assert.assertTrue("waiting for server to shutdown",
- ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
+ ZooKeeper zk = createClient();
+ try {
+ for (int i = 0; i < 2000; i++) {
+ zk.create("/invalidsnap-" + i, new byte[0],
+ Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
+ } finally {
+ zk.close();
+ }
+ NIOServerCnxnFactory factory = (NIOServerCnxnFactory)serverFactory;
+ stopServer();
+
+ // now corrupt the snapshot
+ File snapFile = factory.zkServer.getTxnLogFactory().findMostRecentSnapshot();
+ LOG.info("Corrupting " + snapFile);
+ RandomAccessFile raf = new RandomAccessFile(snapFile, "rws");
+ raf.setLength(3);
+ raf.close();
+
+ // now restart the server
+ startServer();
+
+ // verify that the expected data exists and wasn't lost
+ zk = createClient();
+ try {
+ assertTrue("the node should exist",
+ (zk.exists("/invalidsnap-1999", false) != null));
+ } finally {
+ zk.close();
+ }
}
-
- public void process(WatchedEvent event) {
- // do nothing for now
- }
-
}
Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=1240925&r1=1240924&r2=1240925&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java Mon Feb 6 08:49:51 2012
@@ -18,14 +18,12 @@
package org.apache.zookeeper.test;
-import java.io.BufferedReader;
+import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
+
import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
-import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
@@ -38,8 +36,6 @@ import java.util.concurrent.TimeoutExcep
import javax.management.MBeanServerConnection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.PortAssignment;
import org.apache.zookeeper.TestableZooKeeper;
@@ -53,10 +49,11 @@ import org.apache.zookeeper.server.Serve
import org.apache.zookeeper.server.ZKDatabase;
import org.apache.zookeeper.server.ZooKeeperServer;
import org.apache.zookeeper.server.persistence.FileTxnLog;
-import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.sun.management.UnixOperatingSystemMXBean;
@@ -299,7 +296,7 @@ public abstract class ClientBase extends
return Integer.parseInt(portstr);
}
- static ServerCnxnFactory createNewServerInstance(File dataDir,
+ public static ServerCnxnFactory createNewServerInstance(File dataDir,
ServerCnxnFactory factory, String hostPort, int maxCnxns)
throws IOException, InterruptedException
{