use of org.apache.bookkeeper.mledger.Position in project incubator-pulsar by apache.
the class PersistentTopic method terminate.
public CompletableFuture<MessageId> terminate() {
CompletableFuture<MessageId> future = new CompletableFuture<>();
ledger.asyncTerminate(new TerminateCallback() {
@Override
public void terminateComplete(Position lastCommittedPosition, Object ctx) {
producers.forEach(Producer::disconnect);
subscriptions.forEach((name, sub) -> sub.topicTerminated());
PositionImpl lastPosition = (PositionImpl) lastCommittedPosition;
MessageId messageId = new MessageIdImpl(lastPosition.getLedgerId(), lastPosition.getEntryId(), -1);
log.info("[{}] Topic terminated at {}", getName(), messageId);
future.complete(messageId);
}
@Override
public void terminateFailed(ManagedLedgerException exception, Object ctx) {
future.completeExceptionally(exception);
}
}, null);
return future;
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedCursorTest method testFindNewestMatchingEdgeCase3.
@Test(timeOut = 20000)
void testFindNewestMatchingEdgeCase3() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ManagedCursorImpl c1 = (ManagedCursorImpl) ledger.openCursor("c1");
Position p1 = ledger.addEntry("expired".getBytes(Encoding));
ledger.addEntry("not-expired".getBytes(Encoding));
assertEquals(c1.findNewestMatching(entry -> Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))), p1);
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerBinaryFormatConversion method textToBinary.
@Test(timeOut = 20000, dataProvider = "gracefulClose")
void textToBinary(boolean gracefulClose) throws Exception {
ManagedLedgerFactoryConfig textConf = new ManagedLedgerFactoryConfig();
textConf.setUseProtobufBinaryFormatInZK(false);
ManagedLedgerFactory textFactory = new ManagedLedgerFactoryImpl(bkc, zkc, textConf);
ManagedLedger ledger = textFactory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("test-0".getBytes(Encoding));
Position p1 = ledger.addEntry("test-1".getBytes(Encoding));
ledger.addEntry("test-2".getBytes(Encoding));
c1.delete(p1);
if (gracefulClose) {
ledger.close();
}
// Reopen with binary format
ManagedLedgerFactoryConfig binaryConf = new ManagedLedgerFactoryConfig();
binaryConf.setUseProtobufBinaryFormatInZK(true);
ManagedLedgerFactory binaryFactory = new ManagedLedgerFactoryImpl(bkc, zkc, binaryConf);
ledger = binaryFactory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
// The 'p1' entry was already deleted
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
textFactory.shutdown();
binaryFactory.shutdown();
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerBinaryFormatConversion method binaryToText.
@Test(timeOut = 20000, dataProvider = "gracefulClose")
void binaryToText(boolean gracefulClose) throws Exception {
ManagedLedgerFactoryConfig binaryConf = new ManagedLedgerFactoryConfig();
binaryConf.setUseProtobufBinaryFormatInZK(true);
ManagedLedgerFactory binaryFactory = new ManagedLedgerFactoryImpl(bkc, zkc, binaryConf);
ManagedLedger ledger = binaryFactory.open("my_test_ledger");
ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("test-0".getBytes(Encoding));
Position p1 = ledger.addEntry("test-1".getBytes(Encoding));
ledger.addEntry("test-2".getBytes(Encoding));
c1.delete(p1);
if (gracefulClose) {
ledger.close();
}
// Reopen with binary format
ManagedLedgerFactoryConfig textConf = new ManagedLedgerFactoryConfig();
textConf.setUseProtobufBinaryFormatInZK(false);
ManagedLedgerFactory textFactory = new ManagedLedgerFactoryImpl(bkc, zkc, textConf);
ledger = textFactory.open("my_test_ledger");
c1 = ledger.openCursor("c1");
// The 'p1' entry was already deleted
assertEquals(c1.getNumberOfEntriesInBacklog(), 2);
textFactory.shutdown();
binaryFactory.shutdown();
}
use of org.apache.bookkeeper.mledger.Position in project pulsar by yahoo.
the class ManagedLedgerBkTest method asyncMarkDeleteAndClose.
@Test
public void asyncMarkDeleteAndClose() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig config = new ManagedLedgerConfig().setEnsembleSize(1).setWriteQuorumSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1).setMetadataWriteQuorumSize(1).setMetadataAckQuorumSize(1);
ManagedLedger ledger = factory.open("my_test_ledger", config);
ManagedCursor cursor = ledger.openCursor("c1");
List<Position> positions = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
Position p = ledger.addEntry("entry".getBytes());
positions.add(p);
}
final CountDownLatch counter = new CountDownLatch(positions.size());
final AtomicBoolean gotException = new AtomicBoolean(false);
for (Position p : positions) {
cursor.asyncDelete(p, new DeleteCallback() {
@Override
public void deleteComplete(Object ctx) {
// Ok
counter.countDown();
}
@Override
public void deleteFailed(ManagedLedgerException exception, Object ctx) {
exception.printStackTrace();
gotException.set(true);
counter.countDown();
}
}, null);
}
cursor.close();
ledger.close();
counter.await();
assertFalse(gotException.get());
factory.shutdown();
}
Aggregations