zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1300862 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/ bookkeeper-server/src/test/java/org/apache/bookkeeper/client/ bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/ bookkeeper...
Date Thu, 15 Mar 2012 09:37:43 GMT
Author: ivank
Date: Thu Mar 15 09:37:43 2012
New Revision: 1300862

URL: http://svn.apache.org/viewvc?rev=1300862&view=rev
Log:
BOOKKEEPER-184: CompactionTest failing on Jenkins (sijie via ivank)

Added:
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
      - copied, changed from r1300616, zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java
Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestReadTimeout.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/HierarchicalLedgerDeleteTest.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/LedgerLayoutTest.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLedgerManager.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieJournalRollingTest.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/IndexCorruptionTest.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Thu Mar 15 09:37:43 2012
@@ -54,6 +54,8 @@ Trunk (unreleased changes)
 
         BOOKKEEPER-185: Remove bookkeeper-server dependency on hadoop-common (ivank)
 
+        BOOKKEEPER-184: CompactionTest failing on Jenkins (sijie via ivank)
+
       hedwig-server/
       
         BOOKKEEPER-140: Hub server doesn't subscribe remote region correctly when a region
is down. (Sijie Gou via ivank)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CompactionTest.java
Thu Mar 15 09:37:43 2012
@@ -27,7 +27,7 @@ import java.util.Enumeration;
 import org.apache.bookkeeper.client.LedgerEntry;
 import org.apache.bookkeeper.client.LedgerHandle;
 import org.apache.bookkeeper.client.BookKeeper.DigestType;
-import org.apache.bookkeeper.test.BaseTestCase;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,11 +38,12 @@ import org.junit.Test;
 /**
  * This class tests the entry log compaction functionality.
  */
-public class CompactionTest extends BaseTestCase {
+public class CompactionTest extends BookKeeperClusterTestCase {
     static Logger LOG = LoggerFactory.getLogger(CompactionTest.class);
     DigestType digestType;
 
     static int ENTRY_SIZE = 1024;
+    static int NUM_BOOKIES = 1;
 
     int numEntries;
     int gcWaitTime;
@@ -53,11 +54,12 @@ public class CompactionTest extends Base
 
     String msg;
 
-    public CompactionTest(DigestType digestType) {
-        super(3);
-        this.digestType = digestType;
+    public CompactionTest() {
+        super(NUM_BOOKIES);
 
-        numEntries = 2048;
+        this.digestType = DigestType.CRC32;
+
+        numEntries = 100;
         gcWaitTime = 1000;
         minorCompactionThreshold = 0.1f;
         majorCompactionThreshold = 0.5f;
@@ -88,7 +90,7 @@ public class CompactionTest extends Base
 
     LedgerHandle[] prepareData(int numEntryLogs, boolean changeNum)
         throws Exception {
-        // since an entry log file can hold at most 2048 entries
+        // since an entry log file can hold at most 100 entries
         // first ledger write 2 entries, which is less than low water mark
         int num1 = 2;
         // third ledger write more than high water mark entries
@@ -99,7 +101,7 @@ public class CompactionTest extends Base
 
         LedgerHandle[] lhs = new LedgerHandle[3];
         for (int i=0; i<3; ++i) {
-            lhs[i] = bkc.createLedger(3, 3, digestType, "".getBytes());
+            lhs[i] = bkc.createLedger(NUM_BOOKIES, NUM_BOOKIES, digestType, "".getBytes());
         }
 
         for (int n = 0; n < numEntryLogs; n++) {
@@ -161,7 +163,7 @@ public class CompactionTest extends Base
         baseConf.setMajorCompactionThreshold(0.0f);
 
         // restart bookies
-        restartBookies();
+        restartBookies(baseConf);
 
         // remove ledger2 and ledger3
         // so entry log 1 and 2 would have ledger1 entries left
@@ -191,7 +193,7 @@ public class CompactionTest extends Base
         baseConf.setMajorCompactionThreshold(0.0f);
 
         // restart bookies
-        restartBookies();
+        restartBookies(baseConf);
 
         // remove ledger2 and ledger3
         bkc.deleteLedger(lhs[1].getId());
@@ -226,7 +228,7 @@ public class CompactionTest extends Base
         baseConf.setMinorCompactionThreshold(0.0f);
 
         // restart bookies
-        restartBookies();
+        restartBookies(baseConf);
 
         // remove ledger1 and ledger3
         bkc.deleteLedger(lhs[0].getId());
@@ -276,7 +278,7 @@ public class CompactionTest extends Base
     public void testCompactionSmallEntryLogs() throws Exception {
 
         // create a ledger to write a few entries
-        LedgerHandle alh = bkc.createLedger(3, 3, digestType, "".getBytes());
+        LedgerHandle alh = bkc.createLedger(NUM_BOOKIES, NUM_BOOKIES, digestType, "".getBytes());
         for (int i=0; i<3; i++) {
            alh.addEntry(msg.getBytes());
         }

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestReadTimeout.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestReadTimeout.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestReadTimeout.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestReadTimeout.java
Thu Mar 15 09:37:43 2012
@@ -36,7 +36,7 @@ import org.apache.bookkeeper.client.Book
 import org.apache.bookkeeper.client.BookKeeperAdmin;
 import org.apache.bookkeeper.client.BKException;
 import org.apache.bookkeeper.client.BookKeeper.DigestType;
-import org.apache.bookkeeper.test.BaseTestCase;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -47,14 +47,14 @@ import org.slf4j.LoggerFactory;
  * This unit test tests ledger fencing;
  *
  */
-public class TestReadTimeout extends BaseTestCase {
+public class TestReadTimeout extends BookKeeperClusterTestCase {
     static Logger LOG = LoggerFactory.getLogger(TestReadTimeout.class);
 
     DigestType digestType;
 
-    public TestReadTimeout(DigestType digestType) {
+    public TestReadTimeout() {
         super(10);
-        this.digestType = digestType;
+        this.digestType = DigestType.CRC32;
     }
 
     @Test

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/HierarchicalLedgerDeleteTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/HierarchicalLedgerDeleteTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/HierarchicalLedgerDeleteTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/HierarchicalLedgerDeleteTest.java
Thu Mar 15 09:37:43 2012
@@ -32,10 +32,6 @@ import org.junit.Before;
  */
 public class HierarchicalLedgerDeleteTest extends LedgerDeleteTest {
 
-    public HierarchicalLedgerDeleteTest(DigestType digestType) {
-        super(digestType);
-    }
-
     @Before
     @Override
     public void setUp() throws Exception {

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/LedgerLayoutTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/LedgerLayoutTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/LedgerLayoutTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/LedgerLayoutTest.java
Thu Mar 15 09:37:43 2012
@@ -30,18 +30,16 @@ import org.apache.bookkeeper.conf.Client
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.bookkeeper.test.BaseTestCase;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.Assert.*;
 
-public class LedgerLayoutTest extends BaseTestCase {
-    DigestType digestType;
+public class LedgerLayoutTest extends BookKeeperClusterTestCase {
 
-    public LedgerLayoutTest(DigestType digestType) {
+    public LedgerLayoutTest() {
         super(0);
-        this.digestType = digestType;
     }
 
     @Test

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLedgerManager.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLedgerManager.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLedgerManager.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/meta/TestLedgerManager.java
Thu Mar 15 09:37:43 2012
@@ -33,7 +33,7 @@ import java.util.concurrent.CountDownLat
 import java.util.List;
 import java.util.ArrayList;
 
-import org.apache.bookkeeper.test.BaseTestCase;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -42,10 +42,10 @@ import org.junit.Assert.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TestLedgerManager extends BaseTestCase {
+public class TestLedgerManager extends BookKeeperClusterTestCase {
     static Logger LOG = LoggerFactory.getLogger(TestLedgerManager.class);
 
-    public TestLedgerManager(DigestType digestType) {
+    public TestLedgerManager() {
         super(0);
     }
 
@@ -258,4 +258,4 @@ public class TestLedgerManager extends B
         assertEquals("Incorrect number of successes", numThreadsEach, numSuccess);
         assertEquals("Incorrect number of failures", numThreadsEach, numFails);
     }
-}
\ No newline at end of file
+}

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java
Thu Mar 15 09:37:43 2012
@@ -21,59 +21,24 @@
 
 package org.apache.bookkeeper.test;
 
-import org.apache.commons.io.FileUtils;
-
-import java.io.IOException;
-import java.io.File;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
 
-import org.apache.bookkeeper.client.BookKeeperTestClient;
 import org.apache.bookkeeper.client.BookKeeper.DigestType;
-import org.apache.bookkeeper.conf.ClientConfiguration;
-import org.apache.bookkeeper.conf.ServerConfiguration;
-import org.apache.bookkeeper.proto.BookieServer;
-import org.apache.bookkeeper.bookie.BookieException;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.KeeperException;
-
-import org.junit.After;
-import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import junit.framework.TestCase;
-
 @RunWith(Parameterized.class)
-public abstract class BaseTestCase extends TestCase {
+public abstract class BaseTestCase extends BookKeeperClusterTestCase {
     static final Logger LOG = LoggerFactory.getLogger(BaseTestCase.class);
 
-    protected ZooKeeperUtil zkUtil = new ZooKeeperUtil();
-    protected ZooKeeper zkc;
-
-    // BookKeeper
-    protected List<File> tmpDirs = new ArrayList<File>();
-    protected List<BookieServer> bs = new ArrayList<BookieServer>();
-    protected List<ServerConfiguration> bsConfs = new ArrayList<ServerConfiguration>();
-    protected Integer initialPort = 5000;
-    private Integer nextPort = initialPort;
-    protected int numBookies;
-    protected BookKeeperTestClient bkc;
-
-    protected ServerConfiguration baseConf = new ServerConfiguration();
-    protected ClientConfiguration baseClientConf = new ClientConfiguration();
-
     public BaseTestCase(int numBookies) {
-        this.numBookies = numBookies;
+        super(numBookies);
     }
 
     @Parameters
@@ -81,198 +46,4 @@ public abstract class BaseTestCase exten
         return Arrays.asList(new Object[][] { {DigestType.MAC }, {DigestType.CRC32}});
     }
 
-    protected ServerConfiguration newServerConfiguration(int port, String zkServers, File
journalDir, File[] ledgerDirs) {
-        ServerConfiguration conf = new ServerConfiguration(baseConf);
-        conf.setBookiePort(port);
-        conf.setZkServers(zkServers);
-        conf.setJournalDirName(journalDir.getPath());
-        String[] ledgerDirNames = new String[ledgerDirs.length];
-        for (int i=0; i<ledgerDirs.length; i++) {
-            ledgerDirNames[i] = ledgerDirs[i].getPath();
-        }
-        conf.setLedgerDirNames(ledgerDirNames);
-        return conf;
-    }
-
-    @Before
-    @Override
-    public void setUp() throws Exception {
-        try {
-            zkUtil.startServer();
-            zkc = zkUtil.getZooKeeperClient();
-
-            baseClientConf.setZkServers(zkUtil.getZooKeeperConnectString());
-            if (numBookies > 0) {
-                bkc = new BookKeeperTestClient(baseClientConf);
-            }
-
-            // Create Bookie Servers (B1, B2, B3)
-            for (int i = 0; i < numBookies; i++) {
-                File f = File.createTempFile("bookie", "test");
-                tmpDirs.add(f);
-                f.delete();
-                f.mkdir();
-
-                ServerConfiguration conf = newServerConfiguration(
-                        nextPort++, zkUtil.getZooKeeperConnectString(), f, new File[] { f
});
-                bsConfs.add(conf);
-
-                bs.add(startBookie(conf));
-            }
-        } catch(Exception e) {
-            LOG.error("Error setting up", e);
-            throw e;
-        }
-    }
-
-    public void killBookie(InetSocketAddress addr) throws InterruptedException {
-        BookieServer toRemove = null;
-        for (BookieServer server : bs) {
-            if (server.getLocalAddress().equals(addr)) {
-                server.shutdown();
-                toRemove = server;
-            }
-        }
-        if (toRemove != null) {
-            bs.remove(toRemove);
-        }
-    }
-
-    public void killBookie(int index) throws InterruptedException, IOException {
-        if (index >= bs.size()) {
-            throw new IOException("Bookie does not exist");
-        }
-        BookieServer server = bs.get(index);
-        server.shutdown();
-        bs.remove(server);
-    }
-
-    public void sleepBookie(InetSocketAddress addr, final int seconds,
-                            final CountDownLatch l)
-            throws InterruptedException, IOException {
-        final String name = "Bookie-" + addr.getPort();
-        Thread[] allthreads = new Thread[Thread.activeCount()];
-        Thread.enumerate(allthreads);
-        for (final Thread t : allthreads) {
-            if (t.getName().equals(name)) {
-                Thread sleeper = new Thread() {
-                    public void run() {
-                        try {
-                            t.suspend();
-                            l.countDown();
-                            Thread.sleep(seconds*1000);
-                            t.resume();
-                        } catch (Exception e) {
-                            LOG.error("Error suspending thread", e);
-                        }
-                    }
-                };
-                sleeper.start();
-                return;
-            }
-        }
-        throw new IOException("Bookie thread not found");
-    }
-
-    /**
-     * Restart bookie servers
-     *
-     * @throws InterruptedException
-     * @throws IOException
-     */
-    protected void restartBookies() 
-            throws InterruptedException, IOException, KeeperException, BookieException {
-        restartBookies(null);
-    }
-
-    /**
-     * Restart bookie servers add new configuration settings
-     */
-    protected void restartBookies(ServerConfiguration newConf)
-            throws InterruptedException, IOException, KeeperException, BookieException {
-        // shut down bookie server
-        for (BookieServer server : bs) {
-            server.shutdown();
-        }
-        bs.clear();
-        Thread.sleep(1000);
-        // restart them to ensure we can't 
-        int j = 0;
-        for (File f : tmpDirs) {
-            ServerConfiguration conf = bsConfs.get(j);
-            if (null != newConf) {
-                conf.loadConf(newConf);
-            }
-            bs.add(startBookie(conf));
-            j++;
-        }
-    }
-
-    /**
-     * Helper method to startup a new bookie server with the indicated port
-     * number
-     *
-     * @param port
-     *            Port to start the new bookie server on
-     * @throws IOException
-     */
-    protected int startNewBookie()
-            throws IOException, InterruptedException, KeeperException, BookieException {
-        File f = File.createTempFile("bookie", "test");
-        tmpDirs.add(f);
-        f.delete();
-        f.mkdir();
-
-        int port = nextPort++;
-        ServerConfiguration conf = newServerConfiguration(port, zkUtil.getZooKeeperConnectString(),
-                                                          f, new File[] { f });
-
-        bs.add(startBookie(conf));
-
-        return port;
-    }
-
-    /**
-     * Helper method to startup a bookie server using a configuration object
-     *
-     * @param conf
-     *            Server Configuration Object
-     *
-     */
-    private BookieServer startBookie(ServerConfiguration conf)
-            throws IOException, InterruptedException, KeeperException, BookieException {
-        BookieServer server = new BookieServer(conf);
-        server.start();
-
-        int port = conf.getBookiePort();
-        while(bkc.getZkHandle().exists("/ledgers/available/" + InetAddress.getLocalHost().getHostAddress()
+ ":" + port, false) == null) {
-            Thread.sleep(500);
-        }
-
-        bkc.readBookiesBlocking();
-        LOG.info("New bookie on port " + port + " has been created.");
-
-        return server;
-    }
-
-    @After
-    @Override
-    public void tearDown() throws Exception {
-        LOG.info("TearDown");
-
-        if (bkc != null) {
-            bkc.close();;
-        }
-
-        for (BookieServer server : bs) {
-            server.shutdown();
-        }
-
-        for (File f : tmpDirs) {
-            FileUtils.deleteDirectory(f);
-        }
-
-        zkUtil.killServer();
-    }
-
 }

Copied: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
(from r1300616, zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java)
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java?p2=zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java&p1=zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java&r1=1300616&r2=1300862&rev=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BaseTestCase.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
Thu Mar 15 09:37:43 2012
@@ -21,49 +21,45 @@
 
 package org.apache.bookkeeper.test;
 
-import org.apache.commons.io.FileUtils;
-
 import java.io.IOException;
 import java.io.File;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import org.apache.bookkeeper.client.BookKeeperTestClient;
-import org.apache.bookkeeper.client.BookKeeper.DigestType;
 import org.apache.bookkeeper.conf.ClientConfiguration;
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.proto.BookieServer;
 import org.apache.bookkeeper.bookie.BookieException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.zookeeper.ZooKeeper;
+import org.apache.commons.io.FileUtils;
 import org.apache.zookeeper.KeeperException;
-
+import org.apache.zookeeper.ZooKeeper;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import junit.framework.TestCase;
 
-@RunWith(Parameterized.class)
-public abstract class BaseTestCase extends TestCase {
-    static final Logger LOG = LoggerFactory.getLogger(BaseTestCase.class);
+/**
+ * A class runs several bookie servers for testing.
+ */
+public abstract class BookKeeperClusterTestCase extends TestCase {
 
+    static final Logger LOG = LoggerFactory.getLogger(BookKeeperClusterTestCase.class);
+
+    // ZooKeeper related variables
     protected ZooKeeperUtil zkUtil = new ZooKeeperUtil();
     protected ZooKeeper zkc;
 
-    // BookKeeper
-    protected List<File> tmpDirs = new ArrayList<File>();
-    protected List<BookieServer> bs = new ArrayList<BookieServer>();
-    protected List<ServerConfiguration> bsConfs = new ArrayList<ServerConfiguration>();
+    // BookKeeper related variables
+    protected List<File> tmpDirs = new LinkedList<File>();
+    protected List<BookieServer> bs = new LinkedList<BookieServer>();
+    protected List<ServerConfiguration> bsConfs = new LinkedList<ServerConfiguration>();
     protected Integer initialPort = 5000;
     private Integer nextPort = initialPort;
     protected int numBookies;
@@ -72,13 +68,87 @@ public abstract class BaseTestCase exten
     protected ServerConfiguration baseConf = new ServerConfiguration();
     protected ClientConfiguration baseClientConf = new ClientConfiguration();
 
-    public BaseTestCase(int numBookies) {
+    public BookKeeperClusterTestCase(int numBookies) {
         this.numBookies = numBookies;
     }
 
-    @Parameters
-    public static Collection<Object[]> configs() {
-        return Arrays.asList(new Object[][] { {DigestType.MAC }, {DigestType.CRC32}});
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        try {
+            // start zookeeper service
+            startZKCluster();
+            // start bookkeeper service
+            startBKCluster();
+        } catch (Exception e) {
+            LOG.error("Error setting up", e);
+            throw e;
+        }
+    }
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        LOG.info("TearDown");
+        // stop bookkeeper service
+        stopBKCluster();
+        // stop zookeeper service
+        stopZKCluster();
+    }
+
+    /**
+     * Start zookeeper cluster
+     *
+     * @throws Exception
+     */
+    protected void startZKCluster() throws Exception {
+        zkUtil.startServer();
+        zkc = zkUtil.getZooKeeperClient();
+    }
+
+    /**
+     * Stop zookeeper cluster
+     *
+     * @throws Exception
+     */
+    protected void stopZKCluster() throws Exception {
+        zkUtil.killServer();
+    }
+
+    /**
+     * Start cluster
+     *
+     * @throws Exception
+     */
+    protected void startBKCluster() throws Exception {
+        baseClientConf.setZkServers(zkUtil.getZooKeeperConnectString());
+        if (numBookies > 0) {
+            bkc = new BookKeeperTestClient(baseClientConf);
+        }
+
+        // Create Bookie Servers (B1, B2, B3)
+        for (int i = 0; i < numBookies; i++) {
+            startNewBookie();
+        }
+    }
+
+    /**
+     * Stop cluster
+     *
+     * @throws Exception
+     */
+    protected void stopBKCluster() throws Exception {
+        if (bkc != null) {
+            bkc.close();;
+        }
+
+        for (BookieServer server : bs) {
+            server.shutdown();
+        }
+
+        for (File f : tmpDirs) {
+            FileUtils.deleteDirectory(f);
+        }
     }
 
     protected ServerConfiguration newServerConfiguration(int port, String zkServers, File
journalDir, File[] ledgerDirs) {
@@ -94,50 +164,38 @@ public abstract class BaseTestCase exten
         return conf;
     }
 
-    @Before
-    @Override
-    public void setUp() throws Exception {
-        try {
-            zkUtil.startServer();
-            zkc = zkUtil.getZooKeeperClient();
-
-            baseClientConf.setZkServers(zkUtil.getZooKeeperConnectString());
-            if (numBookies > 0) {
-                bkc = new BookKeeperTestClient(baseClientConf);
-            }
-
-            // Create Bookie Servers (B1, B2, B3)
-            for (int i = 0; i < numBookies; i++) {
-                File f = File.createTempFile("bookie", "test");
-                tmpDirs.add(f);
-                f.delete();
-                f.mkdir();
-
-                ServerConfiguration conf = newServerConfiguration(
-                        nextPort++, zkUtil.getZooKeeperConnectString(), f, new File[] { f
});
-                bsConfs.add(conf);
-
-                bs.add(startBookie(conf));
-            }
-        } catch(Exception e) {
-            LOG.error("Error setting up", e);
-            throw e;
-        }
-    }
-
+    /**
+     * Kill a bookie by its socket address
+     *
+     * @param addr
+     *          Socket Address
+     * @throws InterruptedException
+     */
     public void killBookie(InetSocketAddress addr) throws InterruptedException {
         BookieServer toRemove = null;
+        int toRemoveIndex = 0;
         for (BookieServer server : bs) {
             if (server.getLocalAddress().equals(addr)) {
                 server.shutdown();
                 toRemove = server;
+                break;
             }
+            ++toRemoveIndex;
         }
         if (toRemove != null) {
             bs.remove(toRemove);
+            bsConfs.remove(toRemoveIndex);
         }
     }
 
+    /**
+     * Kill a bookie by index
+     *
+     * @param index
+     *          Bookie Index
+     * @throws InterruptedException
+     * @throws IOException
+     */
     public void killBookie(int index) throws InterruptedException, IOException {
         if (index >= bs.size()) {
             throw new IOException("Bookie does not exist");
@@ -145,8 +203,21 @@ public abstract class BaseTestCase exten
         BookieServer server = bs.get(index);
         server.shutdown();
         bs.remove(server);
+        bsConfs.remove(index);
     }
 
+    /**
+     * Sleep a bookie
+     *
+     * @param addr
+     *          Socket Address
+     * @param seconds
+     *          Sleep seconds
+     * @param l
+     *          Count Down Latch
+     * @throws InterruptedException
+     * @throws IOException
+     */
     public void sleepBookie(InetSocketAddress addr, final int seconds,
                             final CountDownLatch l)
             throws InterruptedException, IOException {
@@ -179,27 +250,35 @@ public abstract class BaseTestCase exten
      *
      * @throws InterruptedException
      * @throws IOException
+     * @throws KeeperException
+     * @throws BookieException
      */
-    protected void restartBookies() 
+    public void restartBookies()
             throws InterruptedException, IOException, KeeperException, BookieException {
         restartBookies(null);
     }
 
     /**
-     * Restart bookie servers add new configuration settings
+     * Restart bookie servers using new configuration settings
+     *
+     * @param newConf
+     *          New Configuration Settings
+     * @throws InterruptedException
+     * @throws IOException
+     * @throws KeeperException
+     * @throws BookieException
      */
-    protected void restartBookies(ServerConfiguration newConf)
-            throws InterruptedException, IOException, KeeperException, BookieException {
+    public void restartBookies(ServerConfiguration newConf)
+        throws InterruptedException, IOException, KeeperException, BookieException {
         // shut down bookie server
         for (BookieServer server : bs) {
             server.shutdown();
         }
         bs.clear();
         Thread.sleep(1000);
-        // restart them to ensure we can't 
+        // restart them to ensure we can't
         int j = 0;
-        for (File f : tmpDirs) {
-            ServerConfiguration conf = bsConfs.get(j);
+        for (ServerConfiguration conf : bsConfs) {
             if (null != newConf) {
                 conf.loadConf(newConf);
             }
@@ -216,7 +295,7 @@ public abstract class BaseTestCase exten
      *            Port to start the new bookie server on
      * @throws IOException
      */
-    protected int startNewBookie()
+    public int startNewBookie()
             throws IOException, InterruptedException, KeeperException, BookieException {
         File f = File.createTempFile("bookie", "test");
         tmpDirs.add(f);
@@ -226,7 +305,7 @@ public abstract class BaseTestCase exten
         int port = nextPort++;
         ServerConfiguration conf = newServerConfiguration(port, zkUtil.getZooKeeperConnectString(),
                                                           f, new File[] { f });
-
+        bsConfs.add(conf);
         bs.add(startBookie(conf));
 
         return port;
@@ -254,25 +333,4 @@ public abstract class BaseTestCase exten
 
         return server;
     }
-
-    @After
-    @Override
-    public void tearDown() throws Exception {
-        LOG.info("TearDown");
-
-        if (bkc != null) {
-            bkc.close();;
-        }
-
-        for (BookieServer server : bs) {
-            server.shutdown();
-        }
-
-        for (File f : tmpDirs) {
-            FileUtils.deleteDirectory(f);
-        }
-
-        zkUtil.killServer();
-    }
-
 }

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieJournalRollingTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieJournalRollingTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieJournalRollingTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieJournalRollingTest.java
Thu Mar 15 09:37:43 2012
@@ -43,14 +43,14 @@ import org.junit.Test;
 /**
  * This class tests that bookie rolling journals
  */
-public class BookieJournalRollingTest extends BaseTestCase {
+public class BookieJournalRollingTest extends BookKeeperClusterTestCase {
     static Logger LOG = LoggerFactory.getLogger(BookieJournalRollingTest.class);
 
     DigestType digestType;
 
-    public BookieJournalRollingTest(DigestType digestType) {
+    public BookieJournalRollingTest() {
         super(3);
-        this.digestType = digestType;
+        this.digestType = DigestType.CRC32;
     }
 
     @Before

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java
Thu Mar 15 09:37:43 2012
@@ -28,20 +28,19 @@ import org.junit.After;
 import static org.junit.Assert.*;
 
 import org.apache.bookkeeper.conf.ServerConfiguration;
-import org.apache.bookkeeper.client.BookKeeper.DigestType;
 import java.util.HashSet;
 import junit.framework.TestCase;
 import org.apache.bookkeeper.proto.BookieServer;
 import org.apache.bookkeeper.bookie.Bookie;
 
-public class BookieZKExpireTest extends BaseTestCase {
+public class BookieZKExpireTest extends BookKeeperClusterTestCase {
 
-    public BookieZKExpireTest(DigestType digestType) {
+    public BookieZKExpireTest() {
         super(0);
     }
 
     @Test
-    public void runBookieServerZKExpireBehaviourTest() throws Exception {
+    public void testBookieServerZKExpireBehaviour() throws Exception {
         BookieServer server = null;
         try {
             File f = File.createTempFile("bookieserver", "test");

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/IndexCorruptionTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/IndexCorruptionTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/IndexCorruptionTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/IndexCorruptionTest.java
Thu Mar 15 09:37:43 2012
@@ -38,16 +38,16 @@ import org.junit.Test;
 /**
  * This class tests that index corruption cases
  */
-public class IndexCorruptionTest extends BaseTestCase {
+public class IndexCorruptionTest extends BookKeeperClusterTestCase {
     static Logger LOG = LoggerFactory.getLogger(IndexCorruptionTest.class);
 
     DigestType digestType;
 
     int pageSize = 1024;
 
-    public IndexCorruptionTest(DigestType digestType) {
+    public IndexCorruptionTest() {
         super(1);
-        this.digestType = digestType;
+        this.digestType = DigestType.CRC32;
         baseConf.setPageSize(pageSize);
     }
 

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java?rev=1300862&r1=1300861&r2=1300862&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LedgerDeleteTest.java
Thu Mar 15 09:37:43 2012
@@ -35,13 +35,13 @@ import org.junit.Test;
  * This class tests the ledger delete functionality both from the BookKeeper
  * client and the server side.
  */
-public class LedgerDeleteTest extends BaseTestCase {
+public class LedgerDeleteTest extends BookKeeperClusterTestCase {
     static Logger LOG = LoggerFactory.getLogger(LedgerDeleteTest.class);
     DigestType digestType;
 
-    public LedgerDeleteTest(DigestType digestType) {
+    public LedgerDeleteTest() {
         super(3);
-        this.digestType = digestType;
+        this.digestType = DigestType.CRC32;
     }
 
     @Before



Mime
View raw message