Search in sources :

Example 81 with ManagedLedger

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

the class ManagedCursorTest method testFindNewestMatchingEven4.

@Test(timeOut = 20000)
void testFindNewestMatchingEven4() 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));
    ledger.addEntry("expired".getBytes(Encoding));
    Position p4 = ledger.addEntry("expired".getBytes(Encoding));
    assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), p4);
}
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 82 with ManagedLedger

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

the class ManagedCursorTest method unorderedAsyncMarkDelete.

@Test(timeOut = 20000)
void unorderedAsyncMarkDelete() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    final ManagedCursor c1 = ledger.openCursor("c1");
    Position p1 = ledger.addEntry("entry-1".getBytes(Encoding));
    Position p2 = ledger.addEntry("entry-2".getBytes(Encoding));
    final CountDownLatch latch = new CountDownLatch(2);
    c1.asyncMarkDelete(p2, new MarkDeleteCallback() {

        @Override
        public void markDeleteFailed(ManagedLedgerException exception, Object ctx) {
            fail();
        }

        @Override
        public void markDeleteComplete(Object ctx) {
            latch.countDown();
        }
    }, null);
    c1.asyncMarkDelete(p1, new MarkDeleteCallback() {

        @Override
        public void markDeleteFailed(ManagedLedgerException exception, Object ctx) {
            latch.countDown();
        }

        @Override
        public void markDeleteComplete(Object ctx) {
            fail();
        }
    }, null);
    latch.await();
    assertEquals(c1.getMarkDeletedPosition(), p2);
}
Also used : MarkDeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 83 with ManagedLedger

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

the class ManagedCursorTest method testFindNewestMatchingEdgeCase4.

@Test(timeOut = 20000)
void testFindNewestMatchingEdgeCase4() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
    Position p1 = ledger.addEntry("expired".getBytes(Encoding));
    ledger.addEntry("not-expired".getBytes(Encoding));
    ledger.addEntry("not-expired".getBytes(Encoding));
    assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), p1);
}
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 84 with ManagedLedger

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

the class ManagedCursorTest method testMarkDeleteTwice.

@Test(timeOut = 20000)
void testMarkDeleteTwice() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    ManagedCursor cursor = ledger.openCursor("c1");
    Position p1 = ledger.addEntry("entry1".getBytes());
    cursor.markDelete(p1);
    cursor.markDelete(p1);
    assertEquals(cursor.getMarkDeletedPosition(), p1);
}
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 85 with ManagedLedger

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

the class ManagedCursorTest method testSkipEntries.

@Test(timeOut = 20000)
void testSkipEntries() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    Position pos;
    ManagedCursor c1 = ledger.openCursor("c1");
    // test skip on empty ledger
    pos = c1.getReadPosition();
    c1.skipEntries(1, IndividualDeletedEntries.Exclude);
    assertEquals(c1.getReadPosition(), pos);
    pos = ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    pos = ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    // skip entries in same ledger
    c1.skipEntries(1, IndividualDeletedEntries.Exclude);
    assertEquals(c1.getNumberOfEntries(), 1);
    // skip entries until end of ledger
    c1.skipEntries(1, IndividualDeletedEntries.Exclude);
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getReadPosition(), pos.getNext());
    assertEquals(c1.getMarkDeletedPosition(), pos);
    // skip entries across ledgers
    for (int i = 0; i < 6; i++) {
        pos = ledger.addEntry("dummy-entry".getBytes(Encoding));
    }
    c1.skipEntries(5, IndividualDeletedEntries.Exclude);
    assertEquals(c1.getNumberOfEntries(), 1);
    // skip more than the current set of entries
    c1.skipEntries(10, IndividualDeletedEntries.Exclude);
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.hasMoreEntries(), false);
    assertEquals(c1.getReadPosition(), pos.getNext());
    assertEquals(c1.getMarkDeletedPosition(), pos);
}
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)

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