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#243 - asyncAddEntry fails with NPE with LedgerHandlerAdv
Date Mon, 24 Jul 2017 14:03:07 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 96d8210  Issue#243 - asyncAddEntry fails with NPE with LedgerHandlerAdv
96d8210 is described below

commit 96d82102bef3152934f564db16373b12b1689ead
Author: Enrico Olivelli <eolivelli@apache.org>
AuthorDate: Mon Jul 24 16:03:02 2017 +0200

    Issue#243 - asyncAddEntry fails with NPE with LedgerHandlerAdv
    
    Fix asyncAddEntry on LedgerHandleAdv and clean up the asyncAddEntry API, drops BKException
which is never thrown in asynch functions
    
    Author: Enrico Olivelli <eolivelli@apache.org>
    
    Reviewers: Sijie Guo
    
    This closes #244 from eolivelli/asyncadd-adv, closes #243
---
 .../org/apache/bookkeeper/client/LedgerHandle.java |  3 +-
 .../apache/bookkeeper/client/LedgerHandleAdv.java  | 19 +++++-
 .../bookkeeper/client/BookieWriteLedgerTest.java   | 73 ++++++++++++++++++++++
 3 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
index a056043..e77342b 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
@@ -720,8 +720,7 @@ public class LedgerHandle implements AutoCloseable {
      * @param ctx
      *            some control object
      */
-    public void asyncAddEntry(final long entryId, final byte[] data, final AddCallback cb,
final Object ctx)
-            throws BKException {
+    public void asyncAddEntry(final long entryId, final byte[] data, final AddCallback cb,
final Object ctx) {
         LOG.error("To use this feature Ledger must be created with createLedgerAdv() interface.");
         cb.addComplete(BKException.Code.IllegalOpException, LedgerHandle.this, entryId, ctx);
     }
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
index da10da4..527d084 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
@@ -121,7 +121,7 @@ public class LedgerHandleAdv extends LedgerHandle {
      *            some control object
      */
     @Override
-    public void asyncAddEntry(long entryId, byte[] data, AddCallback cb, Object ctx) throws
BKException {
+    public void asyncAddEntry(long entryId, byte[] data, AddCallback cb, Object ctx) {
         asyncAddEntry(entryId, data, 0, data.length, cb, ctx);
     }
 
@@ -225,4 +225,21 @@ public class LedgerHandleAdv extends LedgerHandle {
         }
     }
 
+    /**
+     * LedgerHandleAdv will not allow addEntry without providing an entryId
+     */
+    @Override
+    public void asyncAddEntry(ByteBuf data, AddCallback cb, Object ctx) {
+        cb.addComplete(BKException.Code.IllegalOpException, this, LedgerHandle.INVALID_ENTRY_ID,
ctx);
+    }
+
+    /**
+     * LedgerHandleAdv will not allow addEntry without providing an entryId
+     */
+    @Override
+    public void asyncAddEntry(final byte[] data, final int offset, final int length,
+                              final AddCallback cb, final Object ctx) {
+        cb.addComplete(BKException.Code.IllegalOpException, this, LedgerHandle.INVALID_ENTRY_ID,
ctx);
+    }
+
 }
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieWriteLedgerTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieWriteLedgerTest.java
index 69ac921..e226bb0 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieWriteLedgerTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieWriteLedgerTest.java
@@ -20,6 +20,7 @@
  */
 package org.apache.bookkeeper.client;
 
+import io.netty.buffer.Unpooled;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -31,6 +32,8 @@ import java.util.Random;
 import java.util.Map;
 import java.util.UUID;
 import java.util.HashMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
 
 import org.apache.bookkeeper.client.AsyncCallback.AddCallback;
 import org.apache.bookkeeper.client.BookKeeper.DigestType;
@@ -179,6 +182,76 @@ public class BookieWriteLedgerTest extends
     }
 
     /**
+     * Verify that LedgerHandleAdv cannnot handle addEntry without the entryId
+     *
+     * @throws Exception
+     */
+    @Test(timeout = 60000)
+    public void testNoAddEntryLedgerCreateAdv() throws Exception {
+
+        ByteBuffer entry = ByteBuffer.allocate(4);
+        entry.putInt(rng.nextInt(maxInt));
+        entry.position(0);
+
+        lh = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
+        assertTrue(lh instanceof LedgerHandleAdv);
+
+        try {
+            lh.addEntry(entry.array());
+            fail("using LedgerHandleAdv addEntry without entryId is forbidden");
+        } catch (BKException e) {
+            assertEquals(e.getCode(), BKException.Code.IllegalOpException);
+        }
+
+        try {
+            lh.addEntry(entry.array(), 0, 4);
+            fail("using LedgerHandleAdv addEntry without entryId is forbidden");
+        } catch (BKException e) {
+            assertEquals(e.getCode(), BKException.Code.IllegalOpException);
+        }
+
+        try {
+            CompletableFuture<Object> done = new CompletableFuture<>();
+            lh.asyncAddEntry(Unpooled.wrappedBuffer(entry.array()),
+                (int rc, LedgerHandle lh1, long entryId, Object ctx) -> {
+                SynchCallbackUtils.finish(rc, null, done);
+            }, null);
+            done.get();
+        } catch (ExecutionException ee) {
+            assertTrue(ee.getCause() instanceof BKException);
+            BKException e = (BKException) ee.getCause();
+            assertEquals(e.getCode(), BKException.Code.IllegalOpException);
+        }
+
+        try {
+            CompletableFuture<Object> done = new CompletableFuture<>();
+            lh.asyncAddEntry(entry.array(),
+                (int rc, LedgerHandle lh1, long entryId, Object ctx) -> {
+                SynchCallbackUtils.finish(rc, null, done);
+            }, null);
+            done.get();
+        } catch (ExecutionException ee) {
+            assertTrue(ee.getCause() instanceof BKException);
+            BKException e = (BKException) ee.getCause();
+            assertEquals(e.getCode(), BKException.Code.IllegalOpException);
+        }
+
+        try {
+            CompletableFuture<Object> done = new CompletableFuture<>();
+            lh.asyncAddEntry(entry.array(),0, 4,
+                (int rc, LedgerHandle lh1, long entryId, Object ctx) -> {
+                SynchCallbackUtils.finish(rc, null, done);
+            }, null);
+            done.get();
+        } catch (ExecutionException ee) {
+            assertTrue(ee.getCause() instanceof BKException);
+            BKException e = (BKException) ee.getCause();
+            assertEquals(e.getCode(), BKException.Code.IllegalOpException);
+        }
+        lh.close();
+    }
+
+    /**
      * Verify the functionality of Advanced Ledger which accepts ledgerId as input and returns
      * LedgerHandleAdv. LedgerHandleAdv takes entryId for addEntry, and let
      * user manage entryId allocation.

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

Mime
View raw message