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 06:48:51 UTC

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

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

 ##########
 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:
   This name is really generic.
   
   another, more important piint, I think it would be better to use mockito based suite, you so not need a real cluster to test this methods

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