Search in sources :

Example 11 with ManagedLedgerConfig

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

the class ManagedCursorTest method testNumberOfEntriesInBacklog.

@Test(timeOut = 20000)
void testNumberOfEntriesInBacklog() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    ManagedCursor c1 = ledger.openCursor("c1");
    Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ManagedCursor c2 = ledger.openCursor("c2");
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    ManagedCursor c3 = ledger.openCursor("c3");
    Position p3 = ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    ManagedCursor c4 = ledger.openCursor("c4");
    Position p4 = ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    ManagedCursor c5 = ledger.openCursor("c5");
    assertEquals(c1.getNumberOfEntriesInBacklog(), 4);
    assertEquals(c2.getNumberOfEntriesInBacklog(), 3);
    assertEquals(c3.getNumberOfEntriesInBacklog(), 2);
    assertEquals(c4.getNumberOfEntriesInBacklog(), 1);
    assertEquals(c5.getNumberOfEntriesInBacklog(), 0);
    List<Entry> entries = c1.readEntries(2);
    assertEquals(entries.size(), 2);
    entries.forEach(e -> e.release());
    assertEquals(c1.getNumberOfEntries(), 2);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 4);
    c1.markDelete(p1);
    assertEquals(c1.getNumberOfEntries(), 2);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
    c1.delete(p3);
    assertEquals(c1.getNumberOfEntries(), 1);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
    c1.markDelete(p4);
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 12 with ManagedLedgerConfig

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

the class ManagedCursorTest method readFromClosedLedger.

@Test(timeOut = 20000)
void readFromClosedLedger() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
    ManagedCursor c1 = ledger.openCursor("c1");
    ledger.close();
    try {
        c1.readEntries(2);
        fail("ledger is closed, should fail");
    } catch (ManagedLedgerException e) {
    // ok
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 13 with ManagedLedgerConfig

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

the class ManagedCursorTest method testSingleDelete.

@Test(timeOut = 20000)
void testSingleDelete() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(3));
    ManagedCursor cursor = ledger.openCursor("c1");
    Position p1 = ledger.addEntry("entry1".getBytes());
    Position p2 = ledger.addEntry("entry2".getBytes());
    Position p3 = ledger.addEntry("entry3".getBytes());
    Position p4 = ledger.addEntry("entry4".getBytes());
    Position p5 = ledger.addEntry("entry5".getBytes());
    Position p6 = ledger.addEntry("entry6".getBytes());
    Position p0 = cursor.getMarkDeletedPosition();
    cursor.delete(p4);
    assertEquals(cursor.getMarkDeletedPosition(), p0);
    cursor.delete(p1);
    assertEquals(cursor.getMarkDeletedPosition(), p1);
    cursor.delete(p3);
    // Delete will silently succeed
    cursor.delete(p3);
    assertEquals(cursor.getMarkDeletedPosition(), p1);
    cursor.delete(p2);
    assertEquals(cursor.getMarkDeletedPosition(), p4);
    cursor.delete(p5);
    assertEquals(cursor.getMarkDeletedPosition(), p5);
    cursor.close();
    try {
        cursor.delete(p6);
    } catch (ManagedLedgerException e) {
    // Ok
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 14 with ManagedLedgerConfig

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

the class ManagedCursorTest method testReadingAllFilteredEntries.

@Test(timeOut = 20000)
void testReadingAllFilteredEntries() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(3));
    ledger.openCursor("c1");
    ManagedCursor c2 = ledger.openCursor("c2");
    ledger.addEntry("entry1".getBytes());
    Position p2 = ledger.addEntry("entry2".getBytes());
    Position p3 = ledger.addEntry("entry3".getBytes());
    Position p4 = ledger.addEntry("entry4".getBytes());
    Position p5 = ledger.addEntry("entry5".getBytes());
    c2.readEntries(1).get(0).release();
    c2.delete(p2);
    c2.delete(p3);
    List<Entry> entries = c2.readEntries(2);
    assertEquals(entries.size(), 2);
    assertEquals(entries.get(0).getPosition(), p4);
    assertEquals(entries.get(1).getPosition(), p5);
    entries.forEach(e -> e.release());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 15 with ManagedLedgerConfig

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

the class ManagedCursorTest method testOutOfOrderDeletePersistenceWithClose.

@Test(timeOut = 20000)
public void testOutOfOrderDeletePersistenceWithClose() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig());
    ManagedCursor c1 = ledger.openCursor("c1");
    List<Position> addedPositions = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        Position p = ledger.addEntry(("dummy-entry-" + i).getBytes(Encoding));
        addedPositions.add(p);
    }
    // Acknowledge few messages leaving holes
    c1.delete(addedPositions.get(2));
    c1.delete(addedPositions.get(5));
    c1.delete(addedPositions.get(7));
    c1.delete(addedPositions.get(8));
    c1.delete(addedPositions.get(9));
    assertEquals(c1.getNumberOfEntriesInBacklog(), 20 - 5);
    ledger.close();
    factory.shutdown();
    // Re-Open
    factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ledger = factory.open("my_test_ledger", new ManagedLedgerConfig());
    c1 = ledger.openCursor("c1");
    assertEquals(c1.getNumberOfEntriesInBacklog(), 20 - 5);
    List<Entry> entries = c1.readEntries(20);
    assertEquals(entries.size(), 20 - 5);
    List<String> entriesStr = entries.stream().map(e -> new String(e.getDataAndRelease(), Encoding)).collect(Collectors.toList());
    assertEquals(entriesStr.get(0), "dummy-entry-0");
    assertEquals(entriesStr.get(1), "dummy-entry-1");
    // Entry-2 was deleted
    assertEquals(entriesStr.get(2), "dummy-entry-3");
    assertEquals(entriesStr.get(3), "dummy-entry-4");
    // Entry-6 was deleted
    assertEquals(entriesStr.get(4), "dummy-entry-6");
    assertFalse(c1.hasMoreEntries());
}
Also used : ZNodeProtobufFormat(org.apache.bookkeeper.mledger.impl.MetaStoreImplZookeeper.ZNodeProtobufFormat) Arrays(java.util.Arrays) Assert.assertNull(org.testng.Assert.assertNull) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) MockedBookKeeperTestCase(org.apache.bookkeeper.test.MockedBookKeeperTestCase) Entry(org.apache.bookkeeper.mledger.Entry) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertEquals(org.testng.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Assert.assertFalse(org.testng.Assert.assertFalse) ExecutorService(java.util.concurrent.ExecutorService) Charsets(com.google.common.base.Charsets) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) CyclicBarrier(java.util.concurrent.CyclicBarrier) Logger(org.slf4j.Logger) Factory(org.testng.annotations.Factory) Assert.fail(org.testng.Assert.fail) Set(java.util.Set) Position(org.apache.bookkeeper.mledger.Position) IndividualDeletedEntries(org.apache.bookkeeper.mledger.ManagedCursor.IndividualDeletedEntries) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) Sets(com.google.common.collect.Sets) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) TimeUnit(java.util.concurrent.TimeUnit) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) MarkDeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ArrayList(java.util.ArrayList) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)82 Test (org.testng.annotations.Test)77 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)69 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)63 Position (org.apache.bookkeeper.mledger.Position)35 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)32 Entry (org.apache.bookkeeper.mledger.Entry)27 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)24 CountDownLatch (java.util.concurrent.CountDownLatch)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 CyclicBarrier (java.util.concurrent.CyclicBarrier)10 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)8 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)7 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)7 List (java.util.List)6 TimeUnit (java.util.concurrent.TimeUnit)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 BKException (org.apache.bookkeeper.client.BKException)6 Lists (com.google.common.collect.Lists)5 Executors (java.util.concurrent.Executors)5