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
}
}
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
}
}
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
}
}
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
}
}
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);
}
Aggregations