Search in sources :

Example 31 with ManagedLedgerConfig

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

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 32 with ManagedLedgerConfig

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

the class ManagedLedgerTest method testGetNextValidPosition.

@Test
public void testGetNextValidPosition() throws Exception {
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(1);
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("testGetNextValidPosition", conf);
    ManagedCursor c1 = ledger.openCursor("c1");
    PositionImpl p1 = (PositionImpl) ledger.addEntry("entry1".getBytes());
    PositionImpl p2 = (PositionImpl) ledger.addEntry("entry2".getBytes());
    PositionImpl p3 = (PositionImpl) ledger.addEntry("entry3".getBytes());
    assertEquals(ledger.getNextValidPosition((PositionImpl) c1.getMarkDeletedPosition()), p1);
    assertEquals(ledger.getNextValidPosition(p1), p2);
    assertEquals(ledger.getNextValidPosition(p3), PositionImpl.get(p3.getLedgerId(), p3.getEntryId() + 1));
}
Also used : ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 33 with ManagedLedgerConfig

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

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)

Example 34 with ManagedLedgerConfig

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

the class ManagedCursorTest method testFindNewestMatchingAllEntriesSingleLedger.

@Test(timeOut = 20000)
void testFindNewestMatchingAllEntriesSingleLedger() throws Exception {
    final String ledgerAndCursorName = "testFindNewestMatchingAllEntriesSingleLedger";
    ManagedLedgerConfig config = new ManagedLedgerConfig();
    // needs to be changed if entries per ledger is changed
    int expectedEntryId = 3;
    int entriesPerLedger = config.getMaxEntriesPerLedger();
    internalTestFindNewestMatchingAllEntries(ledgerAndCursorName, entriesPerLedger, expectedEntryId);
}
Also used : ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 35 with ManagedLedgerConfig

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

the class ManagedCursorTest method seekPosition.

@Test(timeOut = 20000)
void seekPosition() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(10));
    ManagedCursor cursor = ledger.openCursor("c1");
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    PositionImpl lastPosition = (PositionImpl) ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    cursor.seek(new PositionImpl(lastPosition.getLedgerId(), lastPosition.getEntryId() - 1));
}
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)

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