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

 ##########
 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:
   if it is expected to "IndexOutOfBoundsException", can you just catch 
"IndexOutOfBoundsException"?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to