Search in sources :

Example 56 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerTest method fenceManagedLedger.

@Test(enabled = false)
public void fenceManagedLedger() throws Exception {
    ManagedLedgerFactory factory1 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedger ledger1 = factory1.open("my_test_ledger");
    ManagedCursor cursor1 = ledger1.openCursor("c1");
    ledger1.addEntry("entry-1".getBytes(Encoding));
    ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedger ledger2 = factory2.open("my_test_ledger");
    ManagedCursor cursor2 = ledger2.openCursor("c1");
    // At this point ledger1 must have been fenced
    try {
        ledger1.addEntry("entry-1".getBytes(Encoding));
        fail("Expecting exception");
    } catch (ManagedLedgerFencedException e) {
    }
    try {
        ledger1.addEntry("entry-2".getBytes(Encoding));
        fail("Expecting exception");
    } catch (ManagedLedgerFencedException e) {
    }
    try {
        cursor1.readEntries(10);
        fail("Expecting exception");
    } catch (ManagedLedgerFencedException e) {
    }
    try {
        ledger1.openCursor("new cursor");
        fail("Expecting exception");
    } catch (ManagedLedgerFencedException e) {
    }
    ledger2.addEntry("entry-2".getBytes(Encoding));
    assertEquals(cursor2.getNumberOfEntries(), 2);
    factory1.shutdown();
    factory2.shutdown();
}
Also used : ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerFencedException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerFencedException) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 57 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerTest method triggerLedgerDeletion.

@Test(timeOut = 20000)
public void triggerLedgerDeletion() throws Exception {
    ManagedLedgerConfig config = new ManagedLedgerConfig().setMaxEntriesPerLedger(1);
    ManagedLedger ledger = factory.open("my_test_ledger", config);
    ManagedCursor cursor = ledger.openCursor("test");
    ledger.addEntry("entry-1".getBytes(Encoding));
    ledger.addEntry("entry-2".getBytes(Encoding));
    ledger.addEntry("entry-3".getBytes(Encoding));
    assertEquals(cursor.hasMoreEntries(), true);
    List<Entry> entries = cursor.readEntries(1);
    assertEquals(entries.size(), 1);
    assertEquals(ledger.getNumberOfEntries(), 3);
    entries.forEach(e -> e.release());
    assertEquals(cursor.hasMoreEntries(), true);
    entries = cursor.readEntries(1);
    assertEquals(cursor.hasMoreEntries(), true);
    cursor.markDelete(entries.get(0).getPosition());
    entries.forEach(e -> e.release());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 58 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerTest method testEmptyManagedLedgerContent.

@Test(timeOut = 20000)
public void testEmptyManagedLedgerContent() throws Exception {
    ZooKeeper zk = bkc.getZkHandle();
    zk.create("/managed-ledger", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/managed-ledger/my_test_ledger", " ".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.openCursor("test");
    ledger.addEntry("entry-1".getBytes(Encoding));
    assertEquals(ledger.getNumberOfEntries(), 1);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 59 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerTest method acknowledge1.

@Test(timeOut = 20000)
public void acknowledge1() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor cursor = ledger.openCursor("c1");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    assertEquals(cursor.hasMoreEntries(), true);
    List<Entry> entries = cursor.readEntries(2);
    assertEquals(entries.size(), 2);
    entries.forEach(e -> e.release());
    assertEquals(cursor.getNumberOfEntries(), 0);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 2);
    assertEquals(cursor.hasMoreEntries(), false);
    assertEquals(ledger.getNumberOfEntries(), 2);
    assertEquals(ledger.getNumberOfActiveEntries(), 2);
    cursor.markDelete(entries.get(0).getPosition());
    assertEquals(cursor.getNumberOfEntries(), 0);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
    assertEquals(cursor.hasMoreEntries(), false);
    assertEquals(ledger.getNumberOfActiveEntries(), 1);
    ledger.close();
    // / Reopen the same managed-ledger
    ledger = factory.open("my_test_ledger");
    cursor = ledger.openCursor("c1");
    assertEquals(ledger.getNumberOfEntries(), 2);
    assertEquals(ledger.getTotalSize(), "dummy-entry-1".getBytes(Encoding).length * 2);
    assertEquals(cursor.getNumberOfEntries(), 1);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 1);
    assertEquals(cursor.hasMoreEntries(), true);
    entries = cursor.readEntries(100);
    assertEquals(entries.size(), 1);
    entries.forEach(e -> e.release());
    ledger.close();
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 60 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger in project pulsar by yahoo.

the class ManagedLedgerTest method deleteWithErrors2.

@Test(timeOut = 20000)
public void deleteWithErrors2() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    stopZooKeeper();
    try {
        ledger.delete();
        fail("should have failed");
    } catch (ManagedLedgerException e) {
    // ok
    } catch (RejectedExecutionException e) {
    // ok
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.testng.annotations.Test)

Aggregations

ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)363 Test (org.testng.annotations.Test)354 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)262 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)198 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)180 Position (org.apache.bookkeeper.mledger.Position)167 Entry (org.apache.bookkeeper.mledger.Entry)151 CountDownLatch (java.util.concurrent.CountDownLatch)117 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)98 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)74 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)68 CyclicBarrier (java.util.concurrent.CyclicBarrier)66 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)59 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)58 ArrayList (java.util.ArrayList)57 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)57 Future (java.util.concurrent.Future)56 AtomicReference (java.util.concurrent.atomic.AtomicReference)55 ExecutorService (java.util.concurrent.ExecutorService)54 BKException (org.apache.bookkeeper.client.BKException)54