bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-1022: Make BookKeeperAdmin implement AutoCloseable
Date Tue, 11 Apr 2017 18:19:28 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 0f155f38b -> 12bb13cdb


BOOKKEEPER-1022: Make BookKeeperAdmin implement AutoCloseable

Author: eolivelli <eolivelli@apache.org>

Reviewers: Robert (Bobby) Evans <None>, Sijie Guo <sijie@apache.org>, Matteo Merli
<mmerli@apache.org>

Closes #128 from eolivelli/BOOKKEEPER-1022-bkadmin-autocloseable


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/12bb13cd
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/12bb13cd
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/12bb13cd

Branch: refs/heads/master
Commit: 12bb13cdb1feca0fa6739f8e6287c326fb5fdb94
Parents: 0f155f3
Author: eolivelli <eolivelli@apache.org>
Authored: Tue Apr 11 11:19:22 2017 -0700
Committer: Sijie Guo <sijie@apache.org>
Committed: Tue Apr 11 11:19:22 2017 -0700

----------------------------------------------------------------------
 .../bookkeeper/client/BookKeeperAdmin.java      |   3 +-
 .../bookkeeper/client/BookKeeperCloseTest.java  | 103 ++++++++++---------
 2 files changed, 54 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/12bb13cd/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
index d4d8d1f..e7e9cf4 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
@@ -67,7 +67,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Admin client for BookKeeper clusters
  */
-public class BookKeeperAdmin {
+public class BookKeeperAdmin implements AutoCloseable {
     private final static Logger LOG = LoggerFactory.getLogger(BookKeeperAdmin.class);
     // ZK client instance
     private ZooKeeper zk;
@@ -175,6 +175,7 @@ public class BookKeeperAdmin {
      *             if there is an error shutting down the clients that this
      *             class uses.
      */
+    @Override
     public void close() throws InterruptedException, BKException {
         if (ownsBK) {
             bkc.close();

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/12bb13cd/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
index 13ccfe5..d781d5d 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
@@ -467,60 +467,61 @@ public class BookKeeperCloseTest extends BookKeeperClusterTestCase {
     @Test(timeout = 60000)
     public void testBookKeeperAdmin() throws Exception {
         BookKeeper bk = new BookKeeper(baseClientConf, zkc);
-        BookKeeperAdmin bkadmin = new BookKeeperAdmin(bk);
-
-        LOG.info("Create ledger and add entries to it");
-        LedgerHandle lh1 = createLedgerWithEntries(bk, 100);
-        LedgerHandle lh2 = createLedgerWithEntries(bk, 100);
-        LedgerHandle lh3 = createLedgerWithEntries(bk, 100);
-        lh3.close();
-
-        BookieSocketAddress bookieToKill = getBookie(0);
-        killBookie(bookieToKill);
-        startNewBookie();
-        BookieSocketAddress newBookie = getBookie(2);
-
-        CheckerCb checkercb = new CheckerCb();
-        LedgerChecker lc = new LedgerChecker(bk);
-        lc.checkLedger(lh3, checkercb);
-        assertEquals("Should have completed",
-                     checkercb.getRc(30, TimeUnit.SECONDS), BKException.Code.OK);
-        assertEquals("Should have a missing fragment",
-                     1, checkercb.getResult(30, TimeUnit.SECONDS).size());
-
-        // make sure a bookie in each quorum is slow
-        restartBookieSlow();
-        restartBookieSlow();
-
-        bk.close();
-
-        try {
-            bkadmin.openLedger(lh1.getId());
-            fail("Shouldn't be able to open with a closed client");
-        } catch (BKException.BKClientClosedException cce) {
-            // correct behaviour
-        }
+        try (BookKeeperAdmin bkadmin = new BookKeeperAdmin(bk);) {
+
+            LOG.info("Create ledger and add entries to it");
+            LedgerHandle lh1 = createLedgerWithEntries(bk, 100);
+            LedgerHandle lh2 = createLedgerWithEntries(bk, 100);
+            LedgerHandle lh3 = createLedgerWithEntries(bk, 100);
+            lh3.close();
+
+            BookieSocketAddress bookieToKill = getBookie(0);
+            killBookie(bookieToKill);
+            startNewBookie();
+            BookieSocketAddress newBookie = getBookie(2);
+
+            CheckerCb checkercb = new CheckerCb();
+            LedgerChecker lc = new LedgerChecker(bk);
+            lc.checkLedger(lh3, checkercb);
+            assertEquals("Should have completed",
+                         checkercb.getRc(30, TimeUnit.SECONDS), BKException.Code.OK);
+            assertEquals("Should have a missing fragment",
+                         1, checkercb.getResult(30, TimeUnit.SECONDS).size());
+
+            // make sure a bookie in each quorum is slow
+            restartBookieSlow();
+            restartBookieSlow();
+
+            bk.close();
+
+            try {
+                bkadmin.openLedger(lh1.getId());
+                fail("Shouldn't be able to open with a closed client");
+            } catch (BKException.BKClientClosedException cce) {
+                // correct behaviour
+            }
 
-        try {
-            bkadmin.openLedgerNoRecovery(lh1.getId());
-            fail("Shouldn't be able to open with a closed client");
-        } catch (BKException.BKClientClosedException cce) {
-            // correct behaviour
-        }
+            try {
+                bkadmin.openLedgerNoRecovery(lh1.getId());
+                fail("Shouldn't be able to open with a closed client");
+            } catch (BKException.BKClientClosedException cce) {
+                // correct behaviour
+            }
 
-        try {
-            bkadmin.recoverBookieData(bookieToKill, newBookie);
-            fail("Shouldn't be able to recover with a closed client");
-        } catch (BKException.BKClientClosedException cce) {
-            // correct behaviour
-        }
+            try {
+                bkadmin.recoverBookieData(bookieToKill, newBookie);
+                fail("Shouldn't be able to recover with a closed client");
+            } catch (BKException.BKClientClosedException cce) {
+                // correct behaviour
+            }
 
-        try {
-            bkadmin.replicateLedgerFragment(lh3,
-                    checkercb.getResult(10, TimeUnit.SECONDS).iterator().next(), newBookie);
-            fail("Shouldn't be able to replicate with a closed client");
-        } catch (BKException.BKClientClosedException cce) {
-            // correct behaviour
+            try {
+                bkadmin.replicateLedgerFragment(lh3,
+                        checkercb.getResult(10, TimeUnit.SECONDS).iterator().next(), newBookie);
+                fail("Shouldn't be able to replicate with a closed client");
+            } catch (BKException.BKClientClosedException cce) {
+                // correct behaviour
+            }
         }
     }
 


Mime
View raw message