Procházet zdrojové kódy

ZOOKEEPER-985. Test BookieRecoveryTest fails on trunk. (fpj via breed)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1072085 13f79535-47bb-0310-9956-ffa450edef68
Benjamin Reed před 14 roky
rodič
revize
575c53253b

+ 2 - 0
CHANGES.txt

@@ -174,6 +174,8 @@ BUGFIXES:
   ZOOKEEPER-902. Fix findbug issue in trunk "Malicious code vulnerability"
   (flavio and phunt via phunt)
 
+  ZOOKEEPER-985. Test BookieRecoveryTest fails on trunk. (fpj via breed)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

+ 9 - 0
src/contrib/bookkeeper/src/java/org/apache/bookkeeper/bookie/Bookie.java

@@ -66,6 +66,9 @@ public class Bookie extends Thread {
 
     // ZooKeeper client instance for the Bookie
     ZooKeeper zk;
+    
+    // Running flag
+    private volatile boolean running = false;
 
     public static class NoLedgerException extends IOException {
         private static final long serialVersionUID = 1L;
@@ -378,6 +381,10 @@ public class Bookie extends Thread {
     
     private LastLogMark lastLogMark = new LastLogMark(0, 0);
     
+    public boolean isRunning(){
+        return running;
+    }
+    
     @Override
     public void run() {
         LinkedList<QueueEntry> toFlush = new LinkedList<QueueEntry>();
@@ -390,6 +397,7 @@ public class Bookie extends Thread {
             long nextPrealloc = preAllocSize;
             long lastFlushPosition = 0;
             logFile.write(zeros, nextPrealloc);
+            running = true;
             // TODO: Currently, when we roll over the journal logs, the older
             // ones are never garbage collected. We should remove a journal log
             // once all of its entries have been synced with the entry logs.
@@ -432,6 +440,7 @@ public class Bookie extends Thread {
         } catch (Exception e) {
             LOG.fatal("Bookie thread exiting", e);
         }
+        running = false;
     }
 
     private FileChannel openChannel(long logId) throws FileNotFoundException {

+ 5 - 4
src/contrib/bookkeeper/src/java/org/apache/bookkeeper/proto/BookieServer.java

@@ -38,7 +38,7 @@ import org.apache.log4j.Logger;
 public class BookieServer implements NIOServerFactory.PacketProcessor, BookkeeperInternalCallbacks.WriteCallback {
     int port;
     NIOServerFactory nioServerFactory;
-    volatile boolean down = false;
+    private volatile boolean running = false;
     Bookie bookie;
     static Logger LOG = Logger.getLogger(BookieServer.class);
 
@@ -49,16 +49,17 @@ public class BookieServer implements NIOServerFactory.PacketProcessor, Bookkeepe
 
     public void start() throws IOException {
         nioServerFactory = new NIOServerFactory(port, this);
+        running = true;
     }
 
     public void shutdown() throws InterruptedException {
-        down = true;
+        running = false;
         nioServerFactory.shutdown();
         bookie.shutdown();
     }
 
-    public boolean isDown() {
-        return down;
+    public boolean isRunning(){
+        return bookie.isRunning() && nioServerFactory.isRunning() && running;
     }
 
     public void join() throws InterruptedException {

+ 4 - 0
src/contrib/bookkeeper/src/java/org/apache/bookkeeper/proto/NIOServerFactory.java

@@ -90,6 +90,10 @@ public class NIOServerFactory extends Thread {
         }
     }
 
+    public boolean isRunning() {
+        return !ss.socket().isClosed();
+    }
+    
     @Override
     public void run() {
         while (!ss.socket().isClosed()) {

+ 5 - 1
src/contrib/bookkeeper/test/org/apache/bookkeeper/test/BookieRecoveryTest.java

@@ -154,7 +154,8 @@ public class BookieRecoveryTest extends BaseTestCase {
      *            Port to start the new bookie server on
      * @throws IOException
      */
-    private void startNewBookie(int port) throws IOException {
+    private void startNewBookie(int port)
+    throws IOException, InterruptedException {
         File f = File.createTempFile("bookie", "test");
         tmpDirs.add(f);
         f.delete();
@@ -162,6 +163,9 @@ public class BookieRecoveryTest extends BaseTestCase {
         BookieServer server = new BookieServer(port, HOSTPORT, f, new File[] { f });
         server.start();
         bs.add(server);
+        while(!server.isRunning()){
+            Thread.sleep(500);
+        }
         LOG.info("New bookie on port " + port + " has been created.");
     }