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/24 08:59:38 UTC

[GitHub] sijie commented on a change in pull request #1045: More testcases for LedgerHandle

sijie commented on a change in pull request #1045: More testcases for LedgerHandle
URL: https://github.com/apache/bookkeeper/pull/1045#discussion_r163485822
 
 

 ##########
 File path: bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieReadWriteTest.java
 ##########
 @@ -953,13 +957,139 @@ public void testReadFromOpenLedgerZeroAndOne() throws Exception {
         }
     }
 
+    @Test
+    public void testWriteUsingReadOnlyHandle() throws Exception {
+        // Create a ledger
+        lh = bkc.createLedger(digestType, ledgerPassword);
+        ledgerId = lh.getId();
+        LOG.info("Ledger ID: " + lh.getId());
+
+        long lac = writeNEntriesLastWriteSync(lh, numEntriesToWrite);
+        LedgerHandle lhOpen = bkc.openLedgerNoRecovery(ledgerId, digestType, ledgerPassword);
+
+        // addEntry on ReadOnlyHandle should fail
+        CountDownLatch latch = new CountDownLatch(1);
+        final int[] rcArray = { 0 };
+        lhOpen.asyncAddEntry("".getBytes(), new AddCallback() {
+            @Override
+            public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
+                CountDownLatch latch = (CountDownLatch) ctx;
+                rcArray[0] = rc;
+                latch.countDown();
+            }
+        }, latch);
+        latch.await();
+        if (rcArray[0] != BKException.Code.IllegalOpException) {
+            Assert.fail("Test1 - asyncAddOperation is supposed to be failed, but it got following rc - "
+                    + KeeperException.Code.get(rcArray[0]));
+        }
+
+        // addEntry on ReadOnlyHandle should fail
+        latch = new CountDownLatch(1);
+        rcArray[0] = 0;
+        lhOpen.asyncAddEntry("".getBytes(), 0, 0, new AddCallback() {
+            @Override
+            public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
+                CountDownLatch latch = (CountDownLatch) ctx;
+                rcArray[0] = rc;
+                latch.countDown();
+            }
+        }, latch);
+        latch.await();
+        if (rcArray[0] != BKException.Code.IllegalOpException) {
+            Assert.fail(
+                    "Test2 - asyncAddOperation is supposed to fail with IllegalOpException, but it got following rc - "
+                            + KeeperException.Code.get(rcArray[0]));
+        }
+
+        // close readonlyhandle
+        latch = new CountDownLatch(1);
+        rcArray[0] = 0;
+        lhOpen.asyncClose(new CloseCallback() {
+            @Override
+            public void closeComplete(int rc, LedgerHandle lh, Object ctx) {
+                CountDownLatch latch = (CountDownLatch) ctx;
+                rcArray[0] = rc;
+                latch.countDown();
+            }
+        }, latch);
+        latch.await();
+        if (rcArray[0] != KeeperException.Code.OK.intValue()) {
+            Assert.fail("Test3 - asyncClose failed because of exception - " + KeeperException.Code.get(rcArray[0]));
+        }
+
+        // close of readonlyhandle should not affect the writehandle
+        writeNEntriesLastWriteSync(lh, 5);
+        lh.close();
+    }
+
+    @Test
+    public void testLedgerHandle() throws Exception {
 
 Review comment:
   @eolivelli I believe these are ported back from salesforce. I would suggest not bringing mockito in the context, because mock based suite is a totally different direction than this PR. We can have follow up tasks to improve them using mocks if you like.

----------------------------------------------------------------
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