Search in sources :

Example 81 with ManagedLedgerConfig

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

the class NonDurableCursorTest method rewind.

@Test(timeOut = 20000)
void rewind() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
    ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.earliest);
    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));
    log.debug("p1: {}", p1);
    log.debug("p2: {}", p2);
    log.debug("p3: {}", p3);
    log.debug("p4: {}", p4);
    assertEquals(c1.getNumberOfEntries(), 4);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 4);
    c1.markDelete(p1);
    assertEquals(c1.getNumberOfEntries(), 3);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
    List<Entry> entries = c1.readEntries(10);
    assertEquals(entries.size(), 3);
    entries.forEach(e -> e.release());
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
    c1.rewind();
    assertEquals(c1.getNumberOfEntries(), 3);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 3);
    c1.markDelete(p2);
    assertEquals(c1.getNumberOfEntries(), 2);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
    entries = c1.readEntries(10);
    assertEquals(entries.size(), 2);
    entries.forEach(e -> e.release());
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
    c1.rewind();
    assertEquals(c1.getNumberOfEntries(), 2);
    c1.markDelete(p4);
    assertEquals(c1.getNumberOfEntries(), 0);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 0);
    c1.rewind();
    assertEquals(c1.getNumberOfEntries(), 0);
    ledger.addEntry("dummy-entry-5".getBytes(Encoding));
    assertEquals(c1.getNumberOfEntries(), 1);
    ledger.addEntry("dummy-entry-6".getBytes(Encoding));
    assertEquals(c1.getNumberOfEntries(), 2);
}
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 82 with ManagedLedgerConfig

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

the class NonDurableCursorTest method testResetCursor.

@Test(timeOut = 20000)
void testResetCursor() throws Exception {
    ManagedLedger ledger = factory.open("my_test_move_cursor_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(10));
    ManagedCursor cursor = ledger.newNonDurableCursor(PositionImpl.latest);
    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));
    final AtomicBoolean moveStatus = new AtomicBoolean(false);
    PositionImpl resetPosition = new PositionImpl(lastPosition.getLedgerId(), lastPosition.getEntryId() - 2);
    try {
        cursor.resetCursor(resetPosition);
        moveStatus.set(true);
    } catch (Exception e) {
        log.warn("error in reset cursor", e.getCause());
    }
    assertTrue(moveStatus.get());
    assertTrue(cursor.getReadPosition().equals(resetPosition));
    cursor.close();
    ledger.close();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 83 with ManagedLedgerConfig

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

the class NonDurableCursorTest method readWithCacheDisabled.

@Test(timeOut = 20000)
void readWithCacheDisabled() throws Exception {
    ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
    config.setMaxCacheSize(0);
    factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle(), config);
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
    ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.latest);
    ManagedCursor c2 = ledger.newNonDurableCursor(PositionImpl.latest);
    ledger.addEntry("entry-1".getBytes(Encoding));
    ledger.addEntry("entry-2".getBytes(Encoding));
    List<Entry> entries = c1.readEntries(2);
    assertEquals(entries.size(), 2);
    assertEquals(new String(entries.get(0).getData(), Encoding), "entry-1");
    assertEquals(new String(entries.get(1).getData(), Encoding), "entry-2");
    entries.forEach(e -> e.release());
    entries = c1.readEntries(2);
    assertEquals(entries.size(), 0);
    entries.forEach(e -> e.release());
    entries = c2.readEntries(2);
    assertEquals(entries.size(), 2);
    entries.forEach(e -> e.release());
    entries = c2.readEntries(2);
    assertEquals(entries.size(), 0);
    entries.forEach(e -> e.release());
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 84 with ManagedLedgerConfig

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

the class NonDurableCursorTest method subscribeToEarliestPositionWithDeferredDeletion.

// (timeOut = 20000)
@Test
void subscribeToEarliestPositionWithDeferredDeletion() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
    Position p1 = ledger.addEntry("entry-1".getBytes());
    Position p2 = ledger.addEntry("entry-2".getBytes());
    /* Position p3 = */
    ledger.addEntry("entry-3".getBytes());
    /* Position p4 = */
    ledger.addEntry("entry-4".getBytes());
    /* Position p5 = */
    ledger.addEntry("entry-5".getBytes());
    /* Position p6 = */
    ledger.addEntry("entry-6".getBytes());
    ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.earliest);
    assertEquals(c1.getReadPosition(), p1);
    assertEquals(c1.getMarkDeletedPosition(), new PositionImpl(3, -1));
    assertEquals(c1.getNumberOfEntries(), 6);
    assertEquals(c1.getNumberOfEntriesInBacklog(), 6);
    ManagedCursor c2 = ledger.newNonDurableCursor(p1);
    assertEquals(c2.getReadPosition(), p2);
    assertEquals(c2.getMarkDeletedPosition(), p1);
    assertEquals(c2.getNumberOfEntries(), 5);
    assertEquals(c2.getNumberOfEntriesInBacklog(), 5);
}
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 ManagedLedgerConfig

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

the class NonDurableCursorTest method testNumberOfEntries.

@Test(timeOut = 20000)
void testNumberOfEntries() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2).setRetentionTime(1, TimeUnit.HOURS).setRetentionSizeInMB(1));
    ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.latest);
    ledger.addEntry("dummy-entry-1".getBytes(Encoding));
    ManagedCursor c2 = ledger.newNonDurableCursor(PositionImpl.latest);
    ledger.addEntry("dummy-entry-2".getBytes(Encoding));
    ManagedCursor c3 = ledger.newNonDurableCursor(PositionImpl.latest);
    ledger.addEntry("dummy-entry-3".getBytes(Encoding));
    ManagedCursor c4 = ledger.newNonDurableCursor(PositionImpl.latest);
    ledger.addEntry("dummy-entry-4".getBytes(Encoding));
    ManagedCursor c5 = ledger.newNonDurableCursor(PositionImpl.latest);
    assertEquals(c1.getNumberOfEntries(), 4);
    assertEquals(c1.hasMoreEntries(), true);
    assertEquals(c2.getNumberOfEntries(), 3);
    assertEquals(c2.hasMoreEntries(), true);
    assertEquals(c3.getNumberOfEntries(), 2);
    assertEquals(c3.hasMoreEntries(), true);
    assertEquals(c4.getNumberOfEntries(), 1);
    assertEquals(c4.hasMoreEntries(), true);
    assertEquals(c5.getNumberOfEntries(), 0);
    assertEquals(c5.hasMoreEntries(), false);
    List<Entry> entries = c1.readEntries(2);
    assertEquals(entries.size(), 2);
    c1.markDelete(entries.get(1).getPosition());
    assertEquals(c1.getNumberOfEntries(), 2);
    entries.forEach(e -> e.release());
}
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)

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