Search in sources :

Example 21 with ManagedLedger

use of org.apache.bookkeeper.mledger.ManagedLedger 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 22 with ManagedLedger

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

the class ManagedCursorTest method testReadEntriesOrWait.

@Test(timeOut = 10000)
void testReadEntriesOrWait() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    final int Consumers = 10;
    final CountDownLatch counter = new CountDownLatch(Consumers);
    for (int i = 0; i < Consumers; i++) {
        ManagedCursor c = ledger.openCursor("c" + i);
        c.asyncReadEntriesOrWait(1, new ReadEntriesCallback() {

            public void readEntriesComplete(List<Entry> entries, Object ctx) {
                assertEquals(entries.size(), 1);
                entries.forEach(e -> e.release());
                counter.countDown();
            }

            public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
                log.error("Error reading", exception);
            }
        }, null);
    }
    ledger.addEntry("test".getBytes());
    counter.await();
}
Also used : ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) 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) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 23 with ManagedLedger

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

the class ManagedCursorTest method testFindNewestMatchingOdd3.

@Test(timeOut = 20000)
void testFindNewestMatchingOdd3() 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));
    ledger.addEntry("not-expired".getBytes(Encoding));
    assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), p3);
}
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) Test(org.testng.annotations.Test)

Example 24 with ManagedLedger

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

the class ManagedCursorTest method testIndividuallyDeletedMessages.

@Test(timeOut = 20000)
void testIndividuallyDeletedMessages() throws Exception {
    ManagedLedger ledger = factory.open("testIndividuallyDeletedMessages");
    ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
    ledger.addEntry("entry-0".getBytes(Encoding));
    ledger.addEntry("entry-1".getBytes(Encoding));
    ledger.addEntry("entry-2".getBytes(Encoding));
    ledger.addEntry("entry-3".getBytes(Encoding));
    ledger.addEntry("entry-4".getBytes(Encoding));
    List<Entry> entries = c1.readEntries(4);
    c1.delete(entries.get(1).getPosition());
    c1.delete(entries.get(2).getPosition());
    c1.markDelete(entries.get(3).getPosition());
    entries.forEach(e -> e.release());
    assertTrue(c1.isIndividuallyDeletedEntriesEmpty());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 25 with ManagedLedger

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

the class ManagedCursorTest method testReopenMultipleTimes.

@Test(timeOut = 20000)
public void testReopenMultipleTimes() throws Exception {
    ManagedLedger ledger = factory.open("testReopenMultipleTimes");
    ManagedCursor c1 = ledger.openCursor("c1");
    Position mdPosition = c1.getMarkDeletedPosition();
    c1.close();
    ledger.close();
    ledger = factory.open("testReopenMultipleTimes");
    c1 = ledger.openCursor("c1");
    // since the empty data ledger will be deleted, the cursor position should also be updated
    assertNotEquals(c1.getMarkDeletedPosition(), mdPosition);
    c1.close();
    ledger.close();
    ledger = factory.open("testReopenMultipleTimes");
    c1 = ledger.openCursor("c1");
}
Also used : Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Aggregations

ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)166 Test (org.testng.annotations.Test)162 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)118 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)89 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)86 Position (org.apache.bookkeeper.mledger.Position)75 Entry (org.apache.bookkeeper.mledger.Entry)68 CountDownLatch (java.util.concurrent.CountDownLatch)57 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)48 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)35 CyclicBarrier (java.util.concurrent.CyclicBarrier)33 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)33 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)29 ArrayList (java.util.ArrayList)28 Future (java.util.concurrent.Future)28 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)28 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)28 ExecutorService (java.util.concurrent.ExecutorService)27 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 ReadEntriesCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback)27