use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
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();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method ledgerFencedByAutoReplication.
/**
* When auto-replication is triggered, if there were no writes on the ML during the grace period, auto-replication
* will close the ledger an re-replicate it. After that, the next write will get a FencedException. We should
* recover from this condition by creating a new ledger and retrying the write.
*/
@Test
public void ledgerFencedByAutoReplication() throws Exception {
ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(2).setAckQuorumSize(2).setMetadataEnsembleSize(2);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger", config);
ManagedCursor c1 = ledger.openCursor("c1");
PositionImpl p1 = (PositionImpl) ledger.addEntry("entry-1".getBytes());
// Trigger the closure of the data ledger
bkc.openLedger(p1.getLedgerId(), DigestType.CRC32C, new byte[] {});
ledger.addEntry("entry-2".getBytes());
assertEquals(2, c1.getNumberOfEntries());
assertEquals(2, c1.getNumberOfEntriesInBacklog());
PositionImpl p3 = (PositionImpl) ledger.addEntry("entry-3".getBytes());
// Now entry-2 should have been written before entry-3
assertEquals(3, c1.getNumberOfEntries());
assertEquals(3, c1.getNumberOfEntriesInBacklog());
assertTrue(p1.getLedgerId() != p3.getLedgerId());
factory.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerBkTest method ledgerFencedByFailover.
/**
* When another process steals the ML, the old instance should not succeed in any operation
*/
@Test
public void ledgerFencedByFailover() throws Exception {
ManagedLedgerFactoryImpl factory1 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setEnsembleSize(2).setAckQuorumSize(2).setMetadataEnsembleSize(2);
ManagedLedgerImpl ledger1 = (ManagedLedgerImpl) factory1.open("my_test_ledger", config);
ledger1.openCursor("c");
ledger1.addEntry("entry-1".getBytes());
// Open the ML from another factory
ManagedLedgerFactoryImpl factory2 = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerImpl ledger2 = (ManagedLedgerImpl) factory2.open("my_test_ledger", config);
ManagedCursor c2 = ledger2.openCursor("c");
try {
ledger1.addEntry("entry-2".getBytes());
fail("Should have failed");
} catch (ManagedLedgerException e) {
// Ok
}
ledger2.addEntry("entry-2".getBytes());
try {
ledger1.addEntry("entry-2".getBytes());
fail("Should have failed");
} catch (ManagedLedgerException bve) {
// Ok
}
assertEquals(2, c2.getNumberOfEntriesInBacklog());
factory1.shutdown();
factory2.shutdown();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method errorInUpdatingLedgersList.
@Test(timeOut = 20000, invocationCount = 1, skipFailedInvocations = true, enabled = false)
public void errorInUpdatingLedgersList() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(1));
final CountDownLatch latch = new CountDownLatch(1);
zkc.failAfter(0, Code.CONNECTIONLOSS);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
// not-ok
}
public void addComplete(Position position, Object ctx) {
// ok
}
}, null);
ledger.asyncAddEntry("entry".getBytes(), new AddEntryCallback() {
public void addFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
public void addComplete(Position position, Object ctx) {
fail("should have failed");
}
}, null);
latch.await();
}
use of org.apache.bookkeeper.mledger.ManagedLedgerConfig in project incubator-pulsar by apache.
the class ManagedLedgerErrorsTest method digestError.
@Test
public void digestError() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setDigestType(DigestType.CRC32));
ledger.openCursor("c1");
ledger.addEntry("entry".getBytes());
ledger.close();
try {
ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setDigestType(DigestType.MAC));
fail("should fail for digest error");
} catch (ManagedLedgerException e) {
// ok
}
}
Aggregations