Search in sources :

Example 1 with BookKeeperTestClient

use of org.apache.bookkeeper.client.BookKeeperTestClient in project pulsar by yahoo.

the class BookKeeperClusterTestCase method startBKCluster.

/**
     * Start cluster. Also, starts the auto recovery process for each bookie, if isAutoRecoveryEnabled is true.
     *
     * @throws Exception
     */
protected void startBKCluster() throws Exception {
    baseClientConf.setZkServers(zkUtil.getZooKeeperConnectString());
    baseClientConf.setUseV2WireProtocol(true);
    if (numBookies > 0) {
        bkc = new BookKeeperTestClient(baseClientConf);
    }
    // Create Bookie Servers (B1, B2, B3)
    for (int i = 0; i < numBookies; i++) {
        startNewBookie();
    }
}
Also used : BookKeeperTestClient(org.apache.bookkeeper.client.BookKeeperTestClient)

Example 2 with BookKeeperTestClient

use of org.apache.bookkeeper.client.BookKeeperTestClient 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();
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) BookKeeperTestClient(org.apache.bookkeeper.client.BookKeeperTestClient) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Test(org.testng.annotations.Test)

Example 3 with BookKeeperTestClient

use of org.apache.bookkeeper.client.BookKeeperTestClient in project pulsar by yahoo.

the class BookKeeperClusterTestCase method startBookie.

/**
     * Helper method to startup a bookie server using a configuration object. Also, starts the auto recovery process if
     * isAutoRecoveryEnabled is true.
     *
     * @param conf
     *            Server Configuration Object
     *
     */
protected BookieServer startBookie(ServerConfiguration conf) throws Exception {
    BookieServer server = new BookieServer(conf);
    bsConfs.add(conf);
    bs.add(server);
    server.start();
    if (bkc == null) {
        bkc = new BookKeeperTestClient(baseClientConf);
    }
    int port = conf.getBookiePort();
    while (bkc.getZkHandle().exists("/ledgers/available/" + InetAddress.getLocalHost().getHostAddress() + ":" + port, false) == null) {
        Thread.sleep(500);
    }
    bkc.readBookiesBlocking();
    LOG.info("New bookie on port " + port + " has been created.");
    return server;
}
Also used : BookieServer(org.apache.bookkeeper.proto.BookieServer) BookKeeperTestClient(org.apache.bookkeeper.client.BookKeeperTestClient)

Aggregations

BookKeeperTestClient (org.apache.bookkeeper.client.BookKeeperTestClient)3 Entry (org.apache.bookkeeper.mledger.Entry)1 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)1 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)1 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)1 BookieServer (org.apache.bookkeeper.proto.BookieServer)1 Test (org.testng.annotations.Test)1