Search in sources :

Example 71 with ManagedLedgerConfig

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

the class ManagedLedgerTest method testProducerAndNoConsumer.

@Test(timeOut = 20000)
public void testProducerAndNoConsumer() throws Exception {
    ManagedLedgerConfig config = new ManagedLedgerConfig().setMaxEntriesPerLedger(1);
    ManagedLedger ledger = factory.open("my_test_ledger", config);
    assertEquals(ledger.getNumberOfEntries(), 0);
    ledger.addEntry("entry-1".getBytes(Encoding));
    assertEquals(ledger.getNumberOfEntries(), 1);
    // Since there are no consumers, older ledger will be deleted
    // in a short time (in a background thread)
    ledger.addEntry("entry-2".getBytes(Encoding));
    while (ledger.getNumberOfEntries() > 1) {
        log.debug("entries={}", ledger.getNumberOfEntries());
        Thread.sleep(100);
    }
    ledger.addEntry("entry-3".getBytes(Encoding));
    while (ledger.getNumberOfEntries() > 1) {
        log.debug("entries={}", ledger.getNumberOfEntries());
        Thread.sleep(100);
    }
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 72 with ManagedLedgerConfig

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

the class ManagedLedgerTest method totalSizeTest.

@Test
public void totalSizeTest() throws Exception {
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(1);
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", conf);
    ManagedCursor c1 = ledger.openCursor("c1");
    ledger.addEntry(new byte[10], 1, 8);
    assertEquals(ledger.getTotalSize(), 8);
    PositionImpl p2 = (PositionImpl) ledger.addEntry(new byte[12], 2, 5);
    assertEquals(ledger.getTotalSize(), 13);
    c1.markDelete(new PositionImpl(p2.getLedgerId(), -1));
    // Wait for background trimming
    Thread.sleep(400);
    assertEquals(ledger.getTotalSize(), 5);
}
Also used : ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 73 with ManagedLedgerConfig

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

the class ManagedLedgerTest method moveCursorToNextLedger.

@Test(timeOut = 20000)
public void moveCursorToNextLedger() 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));
    log.debug("Added 1st message");
    List<Entry> entries = cursor.readEntries(1);
    log.debug("read message ok");
    assertEquals(entries.size(), 1);
    entries.forEach(e -> e.release());
    ledger.addEntry("entry-2".getBytes(Encoding));
    log.debug("Added 2nd message");
    ledger.addEntry("entry-3".getBytes(Encoding));
    log.debug("Added 3nd message");
    assertEquals(cursor.hasMoreEntries(), true);
    assertEquals(cursor.getNumberOfEntries(), 2);
    entries = cursor.readEntries(2);
    assertEquals(entries.size(), 2);
    entries.forEach(e -> e.release());
    entries = cursor.readEntries(2);
    assertEquals(entries.size(), 0);
    entries = cursor.readEntries(2);
    assertEquals(entries.size(), 0);
}
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 74 with ManagedLedgerConfig

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

the class ManagedLedgerTest method readFromOlderLedgers.

@Test(timeOut = 20000)
public void readFromOlderLedgers() 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);
    cursor.readEntries(1).forEach(e -> e.release());
    assertEquals(cursor.hasMoreEntries(), true);
    cursor.readEntries(1).forEach(e -> e.release());
    assertEquals(cursor.hasMoreEntries(), true);
    cursor.readEntries(1).forEach(e -> e.release());
    assertEquals(cursor.hasMoreEntries(), false);
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 75 with ManagedLedgerConfig

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

the class ManagedLedgerTest method testMaximumRolloverTime.

@Test
public void testMaximumRolloverTime() throws Exception {
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(5);
    conf.setMinimumRolloverTime(1, TimeUnit.SECONDS);
    conf.setMaximumRolloverTime(1, TimeUnit.SECONDS);
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_maxtime_ledger", conf);
    ledger.openCursor("c1");
    ledger.addEntry("data".getBytes());
    ledger.addEntry("data".getBytes());
    assertEquals(ledger.getLedgersInfoAsList().size(), 1);
    Thread.sleep(2000);
    ledger.addEntry("data".getBytes());
    ledger.addEntry("data".getBytes());
    assertEquals(ledger.getLedgersInfoAsList().size(), 2);
}
Also used : ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)194 Test (org.testng.annotations.Test)182 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)159 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)147 Position (org.apache.bookkeeper.mledger.Position)85 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)77 Entry (org.apache.bookkeeper.mledger.Entry)63 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)54 CountDownLatch (java.util.concurrent.CountDownLatch)52 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 CyclicBarrier (java.util.concurrent.CyclicBarrier)20 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)19 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)18 List (java.util.List)17 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)16 TimeUnit (java.util.concurrent.TimeUnit)15 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)15 BKException (org.apache.bookkeeper.client.BKException)14 Lists (com.google.common.collect.Lists)13