Search in sources :

Example 56 with Position

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

the class ManagedLedgerTerminationTest method terminateWithCursorReadOrWait.

@Test(timeOut = 20000)
public void terminateWithCursorReadOrWait() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    ManagedCursor c1 = ledger.openCursor("c1");
    Position p0 = ledger.addEntry("entry-0".getBytes());
    Position p1 = ledger.addEntry("entry-1".getBytes());
    assertEquals(ledger.isTerminated(), false);
    Position lastPosition = ledger.terminate();
    assertEquals(ledger.isTerminated(), true);
    assertEquals(lastPosition, p1);
    List<Entry> entries = c1.readEntries(10);
    assertEquals(entries.size(), 2);
    assertEquals(entries.get(0).getPosition(), p0);
    assertEquals(entries.get(1).getPosition(), p1);
    entries.forEach(Entry::release);
    // Normal read will just return no entries
    assertEquals(c1.readEntries(10), Collections.emptyList());
    // Read or wait will fail
    try {
        c1.readEntriesOrWait(10);
        fail("Should have thrown exception");
    } catch (NoMoreEntriesToReadException e) {
    // Expected
    }
}
Also used : NoMoreEntriesToReadException(org.apache.bookkeeper.mledger.ManagedLedgerException.NoMoreEntriesToReadException) Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 57 with Position

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

the class ManagedLedgerTerminationTest method terminateWithNonDurableCursor.

@Test(timeOut = 20000)
public void terminateWithNonDurableCursor() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    Position p0 = ledger.addEntry("entry-0".getBytes());
    Position p1 = ledger.addEntry("entry-1".getBytes());
    assertEquals(ledger.isTerminated(), false);
    Position lastPosition = ledger.terminate();
    assertEquals(ledger.isTerminated(), true);
    assertEquals(lastPosition, p1);
    ManagedCursor c1 = ledger.newNonDurableCursor(PositionImpl.earliest);
    List<Entry> entries = c1.readEntries(10);
    assertEquals(entries.size(), 2);
    assertEquals(entries.get(0).getPosition(), p0);
    assertEquals(entries.get(1).getPosition(), p1);
    entries.forEach(Entry::release);
    // Normal read will just return no entries
    assertEquals(c1.readEntries(10), Collections.emptyList());
    // Read or wait will fail
    try {
        c1.readEntriesOrWait(10);
        fail("Should have thrown exception");
    } catch (NoMoreEntriesToReadException e) {
    // Expected
    }
}
Also used : NoMoreEntriesToReadException(org.apache.bookkeeper.mledger.ManagedLedgerException.NoMoreEntriesToReadException) Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 58 with Position

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

the class ManagedLedgerTerminationTest method terminateReopen.

@Test(timeOut = 20000)
public void terminateReopen() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    Position p0 = ledger.addEntry("entry-0".getBytes());
    Position lastPosition = ledger.terminate();
    assertEquals(lastPosition, p0);
    ledger.close();
    ledger = factory.open("my_test_ledger");
    try {
        ledger.addEntry("entry-1".getBytes());
        fail("Should have thrown exception");
    } catch (ManagedLedgerTerminatedException e) {
    // Expected
    }
}
Also used : ManagedLedgerTerminatedException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerTerminatedException) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 59 with Position

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

the class ManagedLedgerTerminationTest method terminateSimple.

@Test(timeOut = 20000)
public void terminateSimple() throws Exception {
    ManagedLedger ledger = factory.open("my_test_ledger");
    Position p0 = ledger.addEntry("entry-0".getBytes());
    Position lastPosition = ledger.terminate();
    assertEquals(lastPosition, p0);
    try {
        ledger.addEntry("entry-1".getBytes());
    } catch (ManagedLedgerTerminatedException e) {
    // Expected
    }
}
Also used : ManagedLedgerTerminatedException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerTerminatedException) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Test(org.testng.annotations.Test)

Example 60 with Position

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

the class ManagedLedgerTest method testEstimatedBacklogSize.

@Test
public void testEstimatedBacklogSize() throws Exception {
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("testEstimatedBacklogSize");
    ManagedCursor c1 = ledger.openCursor("c1");
    ledger.addEntry(new byte[1024]);
    Position position2 = ledger.addEntry(new byte[1024]);
    ledger.addEntry(new byte[1024]);
    ledger.addEntry(new byte[1024]);
    Position lastPosition = ledger.addEntry(new byte[1024]);
    long backlog = ledger.getEstimatedBacklogSize();
    assertEquals(backlog, 1024 * 5);
    List<Entry> entries = c1.readEntries(2);
    entries.forEach(Entry::release);
    c1.markDelete(position2);
    backlog = ledger.getEstimatedBacklogSize();
    assertEquals(backlog, 1024 * 3);
    entries = c1.readEntries(3);
    entries.forEach(Entry::release);
    c1.markDelete(lastPosition);
    backlog = ledger.getEstimatedBacklogSize();
    assertEquals(backlog, 0);
}
Also used : Entry(org.apache.bookkeeper.mledger.Entry) Position(org.apache.bookkeeper.mledger.Position) InitialPosition(org.apache.pulsar.common.api.proto.PulsarApi.CommandSubscribe.InitialPosition) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Aggregations

Position (org.apache.bookkeeper.mledger.Position)201 Test (org.testng.annotations.Test)169 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)168 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)167 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)127 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)115 Entry (org.apache.bookkeeper.mledger.Entry)104 CountDownLatch (java.util.concurrent.CountDownLatch)97 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)72 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)68 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)58 BKException (org.apache.bookkeeper.client.BKException)56 List (java.util.List)55 MarkDeleteCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback)53 AtomicReference (java.util.concurrent.atomic.AtomicReference)52 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)52 Logger (org.slf4j.Logger)52 LoggerFactory (org.slf4j.LoggerFactory)52 Lists (com.google.common.collect.Lists)51 TimeUnit (java.util.concurrent.TimeUnit)51