You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/01/23 08:58:37 UTC

[GitHub] reddycharan commented on a change in pull request #1042: ISSUE #1041: Adding new testcases

reddycharan commented on a change in pull request #1042: ISSUE #1041: Adding new testcases
URL: https://github.com/apache/bookkeeper/pull/1042#discussion_r163177817
 
 

 ##########
 File path: bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookieWriteLedgerTest.java
 ##########
 @@ -344,6 +347,88 @@ public void testLedgerCreateWithCustomMetadata() throws Exception {
     }
 
     /*
+     * 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.
+     * This testcase is mainly added for covering missing code coverage branches
+     * in LedgerHandleAdv
+     *
+     * @throws Exception
+     */
+    @Test(timeout = 60000)
+    public void testLedgerHandleAdvFunctionality() throws Exception {
+        // Create a ledger
+        long ledgerId = 0xABCDEF;
+        lh = bkc.createLedgerAdv(ledgerId, 5, 3, 2, digestType, ledgerPassword, null);
+        numEntriesToWrite = 3;
+
+        ByteBuffer entry = ByteBuffer.allocate(4);
+        entry.putInt(rng.nextInt(maxInt));
+        entry.position(0);
+        entries1.add(entry.array());
+        lh.addEntry(0, entry.array());
+
+        // here asyncAddEntry(final long entryId, final byte[] data, final
+        // AddCallback cb, final Object ctx) method is
+        // called which is not covered in any other testcase
+        entry = ByteBuffer.allocate(4);
+        entry.putInt(rng.nextInt(maxInt));
+        entry.position(0);
+        entries1.add(entry.array());
+        CountDownLatch latch = new CountDownLatch(1);
+        final int[] returnedRC = new int[1];
+        lh.asyncAddEntry(1, entry.array(), new AddCallback() {
+            @Override
+            public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
+                CountDownLatch latch = (CountDownLatch) ctx;
+                returnedRC[0] = rc;
+                latch.countDown();
+            }
+        }, latch);
+        latch.await();
+        assertTrue("Returned code is expected to be OK", returnedRC[0] == BKException.Code.OK);
+
+        // here addEntry is called with incorrect offset and length
+        entry = ByteBuffer.allocate(4);
+        entry.putInt(rng.nextInt(maxInt));
+        entry.position(0);
+        try {
+            lh.addEntry(2, entry.array(), -3, 9);
+            fail("AddEntry is called with negative offset and incorrect length,"
+                    + "so it is expected to throw IndexOutOfBoundsException");
+        } catch (RuntimeException exception) {
+            // expected IndexOutOfBoundsException
 
 Review comment:
   actually with the old code it was throwing ArrayIndexOutOfBoundsException, but with the recent changes (ByteBuffer getting replaced with ByteBuf in the internal class implementations) it is throwing IndexOutOfBoundsException. So to keep this oblivious to the internal implementation, I'm catching RuntimeException.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services