Search in sources :

Example 56 with ManagedLedgerConfig

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();
}
Also used : ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 57 with ManagedLedgerConfig

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();
}
Also used : ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 58 with ManagedLedgerConfig

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();
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 59 with ManagedLedgerConfig

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();
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) CountDownLatch(java.util.concurrent.CountDownLatch) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) Test(org.testng.annotations.Test)

Example 60 with ManagedLedgerConfig

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
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)194 Test (org.testng.annotations.Test)182 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)159 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)147 Position (org.apache.bookkeeper.mledger.Position)85 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)77 Entry (org.apache.bookkeeper.mledger.Entry)63 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)54 CountDownLatch (java.util.concurrent.CountDownLatch)52 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 CyclicBarrier (java.util.concurrent.CyclicBarrier)20 ManagedLedgerFactoryConfig (org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig)19 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)18 List (java.util.List)17 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)16 TimeUnit (java.util.concurrent.TimeUnit)15 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)15 BKException (org.apache.bookkeeper.client.BKException)14 Lists (com.google.common.collect.Lists)13