use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerTest method fenceManagedLedger.
@Test(enabled = false)
public void fenceManagedLedger() throws Exception {
ManagedLedgerFactory factory1 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedger ledger1 = factory1.open("my_test_ledger");
ManagedCursor cursor1 = ledger1.openCursor("c1");
ledger1.addEntry("entry-1".getBytes(Encoding));
ManagedLedgerFactory factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedger ledger2 = factory2.open("my_test_ledger");
ManagedCursor cursor2 = ledger2.openCursor("c1");
// At this point ledger1 must have been fenced
try {
ledger1.addEntry("entry-1".getBytes(Encoding));
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
try {
ledger1.addEntry("entry-2".getBytes(Encoding));
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
try {
cursor1.readEntries(10);
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
try {
ledger1.openCursor("new cursor");
fail("Expecting exception");
} catch (ManagedLedgerFencedException e) {
}
ledger2.addEntry("entry-2".getBytes(Encoding));
assertEquals(cursor2.getNumberOfEntries(), 2);
factory1.shutdown();
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactory 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.ManagedLedgerFactory 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.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerBkTest method testBookieFailure.
@Test
public void testBookieFailure() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(2).setAckQuorumSize(2).setMetadataEnsembleSize(2);
ManagedLedger ledger = factory.open("my-ledger", config);
ManagedCursor cursor = ledger.openCursor("my-cursor");
ledger.addEntry("entry-0".getBytes());
killBookie(1);
// Now we want to simulate that:
// 1. The write operation fails because we only have 1 bookie available
// 2. The bk client cannot properly close the ledger (finalizing the number of entries) because ZK is also
// not available
// 3. When we re-establish the service one, the ledger recovery will be triggered and the half-committed entry
// is restored
// Force to close the ZK client object so that BK will fail to close the ledger
bkc.getZkHandle().close();
try {
ledger.addEntry("entry-1".getBytes());
fail("should fail");
} catch (ManagedLedgerException e) {
// ok
}
bkc = new BookKeeperTestClient(baseClientConf);
startNewBookie();
// Reconnect a new bk client
factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ledger = factory.open("my-ledger", config);
cursor = ledger.openCursor("my-cursor");
// Next add should succeed
ledger.addEntry("entry-2".getBytes());
assertEquals(3, cursor.getNumberOfEntriesInBacklog());
List<Entry> entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-0", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
// entry-1 which was half-committed will get fully committed during the recovery phase
entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-1", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
entries = cursor.readEntries(1);
assertEquals(1, entries.size());
assertEquals("entry-2", new String(entries.get(0).getData()));
entries.forEach(e -> e.release());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerFactory in project pulsar by yahoo.
the class ManagedLedgerBkTest method testSimple.
@Test
public void testSimple() throws Exception {
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, zkc);
ManagedLedgerConfig mlConfig = new ManagedLedgerConfig();
mlConfig.setEnsembleSize(1).setAckQuorumSize(1).setMetadataEnsembleSize(1);
// set the data ledger size
mlConfig.setMaxEntriesPerLedger(100);
// set the metadata ledger size to 1 to kick off many ledger switching cases
mlConfig.setMetadataMaxEntriesPerLedger(2);
ManagedLedger ledger = factory.open("ml-simple-ledger", mlConfig);
ledger.addEntry("test".getBytes());
factory.shutdown();
}
Aggregations