コード例 #1
0
  /**
   * Verify read last confirmed op, it shouldn't cause any deadlock as new bookie connection is
   * being established and returning the connection notification in the same caller thread. It would
   * be simulated by delaying the future.addlistener() in PerChannelBookieClient after the
   * connection establishment. Now the future.addlistener() will notify back in the same thread and
   * simultaneously invoke the pendingOp.operationComplete() event.
   *
   * <p>BOOKKEEPER-326
   */
  @Test(timeout = 60000)
  public void testReadLastConfirmedOp() throws Exception {
    startNewBookie();
    startNewBookie();
    // Create a ledger
    LedgerHandle beforelh =
        bkc.createLedger(numBookies + 2, numBookies + 2, digestType, "".getBytes());

    int numEntries = 10;
    String tmp = "BookKeeper is cool!";
    for (int i = 0; i < numEntries; i++) {
      beforelh.addEntry(tmp.getBytes());
    }

    // shutdown first bookie server
    killBookie(0);
    startNewBookie();

    // create new bookie client, and forcing to establish new
    // PerChannelBookieClient connections for recovery flows.
    BookKeeperTestClient bkc1 = new BookKeeperTestClient(baseClientConf);
    // try to open ledger with recovery
    LedgerHandle afterlh = bkc1.openLedger(beforelh.getId(), digestType, "".getBytes());

    assertEquals("Entries got missed", beforelh.getLastAddPushed(), afterlh.getLastAddConfirmed());
    bkc1.close();
  }
コード例 #2
0
  @Test(timeout = 60000)
  public void testLedgerOpenAfterBKCrashed() throws Exception {
    // Create a ledger
    LedgerHandle beforelh = bkc.createLedger(numBookies, numBookies, digestType, "".getBytes());

    int numEntries = 10;
    String tmp = "BookKeeper is cool!";
    for (int i = 0; i < numEntries; i++) {
      beforelh.addEntry(tmp.getBytes());
    }

    // shutdown first bookie server
    killBookie(0);
    startNewBookie();

    // try to open ledger no recovery
    LedgerHandle afterlh = bkc.openLedger(beforelh.getId(), digestType, "".getBytes());

    assertEquals(beforelh.getLastAddPushed(), afterlh.getLastAddConfirmed());

    LedgerHandle beforelh2 = bkc.createLedger(numBookies, 1, digestType, "".getBytes());

    for (int i = 0; i < numEntries; i++) {
      beforelh2.addEntry(tmp.getBytes());
    }

    // shutdown first bookie server
    killBookie(0);

    // try to open ledger no recovery
    try {
      bkc.openLedger(beforelh2.getId(), digestType, "".getBytes());
      fail("Should have thrown exception");
    } catch (BKException.BKLedgerRecoveryException e) {
      // correct behaviour
    }
  }