Search in sources :

Example 71 with Position

use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.

the class ManagedCursorListAckTest method testMultiPositionDelete.

@Test(timeOut = 20000)
void testMultiPositionDelete() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    ManagedCursor c1 = ledger.openCursor("c1");
    Position p0 = c1.getMarkDeletedPosition();
    Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    Position p2 = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    Position p3 = ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    Position p4 = ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    Position p5 = ledger.addEntry("dummy-entry-5".getBytes(Encoding));
    Position p6 = ledger.addEntry("dummy-entry-6".getBytes(Encoding));
    Position p7 = ledger.addEntry("dummy-entry-7".getBytes(Encoding));
    assertEquals(c1.getNumberOfEntries(), 7);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 7);
    c1.delete(Lists.newArrayList(p2, p3, p5, p7));
    assertEquals(c1.getNumberOfEntries(), 3);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
    assertEquals(c1.getMarkDeletedPosition(), p0);
    c1.delete(Lists.newArrayList(p1));
    assertEquals(c1.getNumberOfEntries(), 2);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
    assertEquals(c1.getMarkDeletedPosition(), p3);
    c1.delete(Lists.newArrayList(p4, p6, p7));
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
    assertEquals(c1.getMarkDeletedPosition(), p7);
}
Also used : 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 72 with Position

use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.

the class ManagedCursorTest method testCountingWithDeletedEntries.

@Test(timeOut = 20000)
void testCountingWithDeletedEntries() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    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 p7 = ledger.addEntry("entry7".getBytes());
    Position p8 = ledger.addEntry("entry8".getBytes());
    assertEquals(cursor.getNumberOfEntries(), 8);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 8);
    cursor.delete(p8);
    assertEquals(cursor.getNumberOfEntries(), 7);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 7);
    cursor.delete(p1);
    assertEquals(cursor.getNumberOfEntries(), 6);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 6);
    cursor.delete(p7);
    cursor.delete(p6);
    cursor.delete(p5);
    assertEquals(cursor.getNumberOfEntries(), 3);
    assertEquals(cursor.getNumberOfEntriesInBacklog(), 3);
}
Also used : 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 73 with Position

use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.

the class ManagedCursorTest method testFindNewestMatchingEven3.

@Test(timeOut = 20000)
void testFindNewestMatchingEven3() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
    ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("expired".getBytes(Encoding));
    Position p3 = ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("not-expired".getBytes(Encoding));
    assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), p3);
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) Future(java.util.concurrent.Future) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) CyclicBarrier(java.util.concurrent.CyclicBarrier) DigestType(org.apache.bookkeeper.client.BookKeeper.DigestType) Set(java.util.Set) Position(org.apache.bookkeeper.mledger.Position) IndividualDeletedEntries(org.apache.bookkeeper.mledger.ManagedCursor.IndividualDeletedEntries) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Code(org.apache.zookeeper.KeeperException.Code) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) MockedBookKeeperTestCase(org.apache.bookkeeper.test.MockedBookKeeperTestCase) Entry(org.apache.bookkeeper.mledger.Entry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Assert(org.testng.Assert) Charset(java.nio.charset.Charset) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) ExecutorService(java.util.concurrent.ExecutorService) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) PositionInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.PositionInfo) MarkDeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback) VoidCallback(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.VoidCallback) Collections(java.util.Collections) ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 74 with Position

use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.

the class ManagedCursorTest method cursorPersistence2.

@Test(timeOut = 20000)
void cursorPersistence2() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMetadataMaxEntriesPerLedger(1));
    ManagedCursor c1 = ledger.openCursor("c1");
    ManagedCursor c2 = ledger.openCursor("c2");
    ManagedCursor c3 = ledger.openCursor("c3");
    Position p0 = c3.getMarkDeletedPosition();
    Position p1 = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ManagedCursor c4 = ledger.openCursor("c4");
    Position p2 = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    Position p3 = ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    Position p4 = ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    Position p5 = ledger.addEntry("dummy-entry-5".getBytes(Encoding));
    ledger.addEntry("dummy-entry-6".getBytes(Encoding));
    c1.markDelete(p1);
    c1.markDelete(p2);
    c1.markDelete(p3);
    c1.markDelete(p4);
    c1.markDelete(p5);
    c2.markDelete(p1);
    // Reopen
    ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ledger = factory.open("my_test_ledger");
    c1 = ledger.openCursor("c1");
    c2 = ledger.openCursor("c2");
    c3 = ledger.openCursor("c3");
    c4 = ledger.openCursor("c4");
    assertEquals(c1.getMarkDeletedPosition(), p5);
    assertEquals(c2.getMarkDeletedPosition(), p1);
    assertEquals(c3.getMarkDeletedPosition(), p0);
    assertEquals(c4.getMarkDeletedPosition(), p1);
    factory2.shutdown();
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 75 with Position

use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.

the class ManagedCursorTest method testFindNewestMatchingEdgeCase7.

@Test(timeOut = 20000)
void testFindNewestMatchingEdgeCase7() throws Exception {
    ManagedLedger ledger = factory.open("testFindNewestMatchingEdgeCase7");
    ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
    ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("expired".getBytes(Encoding));
    Position lastPosition = ledger.addEntry("expired".getBytes(Encoding));
    List<Entry> entries = c1.readEntries(4);
    c1.markDelete(entries.get(0).getPosition());
    c1.delete(entries.get(2).getPosition());
    entries.forEach(e -> e.release());
    assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), lastPosition);
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) Future(java.util.concurrent.Future) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) CyclicBarrier(java.util.concurrent.CyclicBarrier) DigestType(org.apache.bookkeeper.client.BookKeeper.DigestType) Set(java.util.Set) Position(org.apache.bookkeeper.mledger.Position) IndividualDeletedEntries(org.apache.bookkeeper.mledger.ManagedCursor.IndividualDeletedEntries) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Code(org.apache.zookeeper.KeeperException.Code) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) MockedBookKeeperTestCase(org.apache.bookkeeper.test.MockedBookKeeperTestCase) Entry(org.apache.bookkeeper.mledger.Entry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Assert(org.testng.Assert) Charset(java.nio.charset.Charset) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) ExecutorService(java.util.concurrent.ExecutorService) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) PositionInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.PositionInfo) MarkDeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback) VoidCallback(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.VoidCallback) Collections(java.util.Collections) ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) Entry(org.apache.bookkeeper.mledger.Entry) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Aggregations

Position (org.apache.bookkeeper.mledger.Position)201 Test (org.testng.annotations.Test)169 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)168 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)167 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)127 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)115 Entry (org.apache.bookkeeper.mledger.Entry)104 CountDownLatch (java.util.concurrent.CountDownLatch)97 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)72 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)68 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)58 BKException (org.apache.bookkeeper.client.BKException)56 List (java.util.List)55 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)53 AtomicReference (java.util.concurrent.atomic.AtomicReference)52 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)52 Logger (org.slf4j.Logger)52 LoggerFactory (org.slf4j.LoggerFactory)52 Lists (com.google.common.collect.Lists)51 TimeUnit (java.util.concurrent.TimeUnit)51