bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eolive...@apache.org
Subject [bookkeeper] branch master updated: ISSUE #258: BookieInitializationTest.testRegNodeExistsAfterSessionTimeOut failed
Date Wed, 19 Jul 2017 07:31:10 GMT
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 11fdac3  ISSUE #258: BookieInitializationTest.testRegNodeExistsAfterSessionTimeOut
failed
11fdac3 is described below

commit 11fdac3cfdfe0900db994b45aa17500974ba3907
Author: Sijie Guo <sijie@apache.org>
AuthorDate: Wed Jul 19 09:31:04 2017 +0200

    ISSUE #258: BookieInitializationTest.testRegNodeExistsAfterSessionTimeOut failed
    
    Descriptions of the changes in this PR:
    
    Construct new zookeeper client to ensure the tests get new zookeeper session.
    
    (this change is based on 77c7721 )
    
    Author: Sijie Guo <sijie@apache.org>
    
    Reviewers: Enrico Olivelli <eolivelli@apache.org>
    
    This closes #259 from sijie/issue_258, closes #258
---
 .../bookie/BookieInitializationTest.java           | 66 ++++++++++------------
 1 file changed, 29 insertions(+), 37 deletions(-)

diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
index 41e58ab..34681fa 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
@@ -47,7 +47,6 @@ import org.apache.bookkeeper.test.PortManager;
 import org.apache.bookkeeper.util.DiskChecker;
 import org.apache.bookkeeper.zookeeper.ZooKeeperClient;
 import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.junit.Assert;
 import org.junit.Test;
@@ -61,20 +60,10 @@ public class BookieInitializationTest extends BookKeeperClusterTestCase
{
     private static final Logger LOG = LoggerFactory
             .getLogger(BookieInitializationTest.class);
 
-    ZooKeeper newzk = null;
-
     public BookieInitializationTest() {
         super(0);
     }
 
-    @Override
-    public void tearDown() throws Exception {
-        if (null != newzk) {
-            newzk.close();
-        }
-        super.tearDown();
-    }
-
     private static class MockBookie extends Bookie {
         MockBookie(ServerConfiguration conf) throws IOException,
                 KeeperException, InterruptedException, BookieException {
@@ -166,14 +155,13 @@ public class BookieInitializationTest extends BookKeeperClusterTestCase
{
 
         // simulating bookie restart, on restart bookie will create new
         // zkclient and doing the registration.
-        createNewZKClient();
-        b.zk = newzk;
+        ZooKeeperClient newZk = createNewZKClient();
+        b.zk = newZk;
 
-        // deleting the znode, so that the bookie registration should
-        // continue successfully on NodeDeleted event
-        new Thread() {
-            @Override
-            public void run() {
+        try {
+            // deleting the znode, so that the bookie registration should
+            // continue successfully on NodeDeleted event
+            new Thread(() -> {
                 try {
                     Thread.sleep(conf.getZkTimeout() / 3);
                     zkc.delete(bkRegPath, -1);
@@ -181,27 +169,29 @@ public class BookieInitializationTest extends BookKeeperClusterTestCase
{
                     // Not handling, since the testRegisterBookie will fail
                     LOG.error("Failed to delete the znode :" + bkRegPath, e);
                 }
-            }
-        }.start();
-        try {
-            b.testRegisterBookie(conf);
-        } catch (IOException e) {
-            Throwable t = e.getCause();
-            if (t instanceof KeeperException) {
-                KeeperException ke = (KeeperException) t;
-                Assert.assertTrue("ErrorCode:" + ke.code()
-                        + ", Registration node exists",
+            }).start();
+            try {
+                b.testRegisterBookie(conf);
+            } catch (IOException e) {
+                Throwable t = e.getCause();
+                if (t instanceof KeeperException) {
+                    KeeperException ke = (KeeperException) t;
+                    Assert.assertTrue("ErrorCode:" + ke.code()
+                            + ", Registration node exists",
                         ke.code() != KeeperException.Code.NODEEXISTS);
+                }
+                throw e;
             }
-            throw e;
-        }
 
-        // verify ephemeral owner of the bkReg znode
-        Stat bkRegNode2 = newzk.exists(bkRegPath, false);
-        Assert.assertNotNull("Bookie registration has been failed", bkRegNode2);
-        Assert.assertTrue("Bookie is referring to old registration znode:"
+            // verify ephemeral owner of the bkReg znode
+            Stat bkRegNode2 = newZk.exists(bkRegPath, false);
+            Assert.assertNotNull("Bookie registration has been failed", bkRegNode2);
+            Assert.assertTrue("Bookie is referring to old registration znode:"
                 + bkRegNode1 + ", New ZNode:" + bkRegNode2, bkRegNode1
                 .getEphemeralOwner() != bkRegNode2.getEphemeralOwner());
+        } finally {
+            newZk.close();
+        }
     }
 
     /**
@@ -230,7 +220,7 @@ public class BookieInitializationTest extends BookKeeperClusterTestCase
{
 
         // simulating bookie restart, on restart bookie will create new
         // zkclient and doing the registration.
-        createNewZKClient();
+        ZooKeeperClient newzk = createNewZKClient();
         b.zk = newzk;
         try {
             b.testRegisterBookie(conf);
@@ -255,6 +245,8 @@ public class BookieInitializationTest extends BookKeeperClusterTestCase
{
                 return;
             }
             throw e;
+        } finally {
+            newzk.close();
         }
     }
 
@@ -633,10 +625,10 @@ public class BookieInitializationTest extends BookKeeperClusterTestCase
{
         }
     }
     
-    private void createNewZKClient() throws Exception {
+    private ZooKeeperClient createNewZKClient() throws Exception {
         // create a zookeeper client
         LOG.debug("Instantiate ZK Client");
-        newzk = ZooKeeperClient.newBuilder()
+        return ZooKeeperClient.newBuilder()
                 .connectString(zkUtil.getZooKeeperConnectString())
                 .build();
     }

-- 
To stop receiving notification emails like this one, please contact
['"commits@bookkeeper.apache.org" <commits@bookkeeper.apache.org>'].

Mime
View raw message