Return-Path: X-Original-To: apmail-zookeeper-commits-archive@www.apache.org Delivered-To: apmail-zookeeper-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 95775910B for ; Mon, 6 Feb 2012 08:52:42 +0000 (UTC) Received: (qmail 35571 invoked by uid 500); 6 Feb 2012 08:52:42 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 34649 invoked by uid 500); 6 Feb 2012 08:52:33 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 34640 invoked by uid 99); 6 Feb 2012 08:52:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Feb 2012 08:52:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Feb 2012 08:52:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 52406238889B for ; Mon, 6 Feb 2012 08:52:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1240927 - in /zookeeper/branches/branch-3.3: CHANGES.txt src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java src/java/test/org/apache/zookeeper/test/ClientBase.java Date: Mon, 06 Feb 2012 08:52:06 -0000 To: commits@zookeeper.apache.org From: mahadev@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120206085206.52406238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mahadev Date: Mon Feb 6 08:52:05 2012 New Revision: 1240927 URL: http://svn.apache.org/viewvc?rev=1240927&view=rev Log: ZOOKEEPER-1352. server.InvalidSnapshotTest is using connection timeouts that are too short. (phunt via mahadev) Modified: zookeeper/branches/branch-3.3/CHANGES.txt zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/ClientBase.java Modified: zookeeper/branches/branch-3.3/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/CHANGES.txt?rev=1240927&r1=1240926&r2=1240927&view=diff ============================================================================== --- zookeeper/branches/branch-3.3/CHANGES.txt (original) +++ zookeeper/branches/branch-3.3/CHANGES.txt Mon Feb 6 08:52:05 2012 @@ -18,6 +18,9 @@ BUGFIXES: ZOOKEEPER-1353. C client test suite fails consistently. (Clint Byrum via mahadev) + ZOOKEEPER-1352. server.InvalidSnapshotTest is using connection timeouts + that are too short. (phunt via mahadev) + Release 3.3.4 - 2011-11-16 Backward compatible changes: Modified: zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java?rev=1240927&r1=1240926&r2=1240927&view=diff ============================================================================== --- zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java (original) +++ zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java Mon Feb 6 08:52:05 2012 @@ -20,94 +20,61 @@ package org.apache.zookeeper.server; import java.io.File; import java.io.RandomAccessFile; -import java.net.InetSocketAddress; - -import junit.framework.TestCase; import org.apache.log4j.Logger; import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.PortAssignment; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -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.Test; /** - * 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 TestCase implements Watcher { - private static final Logger LOG = - Logger.getLogger(InvalidSnapshotTest.class); - - private static final String HOSTPORT = - "127.0.0.1:" + PortAssignment.unique(); - private static final int CONNECTION_TIMEOUT = 3000; +public class InvalidSnapshotTest extends ClientBase { + private static final Logger LOG = Logger.getLogger(InvalidSnapshotTest.class); + + 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]); - NIOServerCnxn.Factory f = new NIOServerCnxn.Factory( - new InetSocketAddress(PORT)); - f.startup(zks); - 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(); - 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 = new NIOServerCnxn.Factory(new InetSocketAddress(PORT)); - f.startup(zks); - assertTrue("waiting for server being up ", - ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT)); - // the server should come up - zk = new ZooKeeper(HOSTPORT, 20000, this); - try { - assertTrue("the node should exist", - (zk.exists("/invalidsnap-1999", false) != null)); - f.shutdown(); - assertTrue("waiting for server to shutdown", - ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); - } finally { - zk.close(); - } - - f.shutdown(); - assertTrue("waiting for server to shutdown", - ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); - } - - public void process(WatchedEvent event) { - // do nothing for now + 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(); + } + NIOServerCnxn.Factory factory = serverFactory; + stopServer(); + + // now corrupt the snapshot + File snapFile = factory.zks.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(); + } } - } \ No newline at end of file Modified: zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/ClientBase.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=1240927&r1=1240926&r2=1240927&view=diff ============================================================================== --- zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/ClientBase.java (original) +++ zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/ClientBase.java Mon Feb 6 08:52:05 2012 @@ -291,7 +291,7 @@ public abstract class ClientBase extends return Integer.parseInt(portstr); } - static NIOServerCnxn.Factory createNewServerInstance(File dataDir, + public static NIOServerCnxn.Factory createNewServerInstance(File dataDir, NIOServerCnxn.Factory factory, String hostPort, int maxCnxns) throws IOException, InterruptedException {