當前位置: 首頁>>代碼示例>>Java>>正文


Java ZooKeeperServer.closeSession方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.server.ZooKeeperServer.closeSession方法的典型用法代碼示例。如果您正苦於以下問題:Java ZooKeeperServer.closeSession方法的具體用法?Java ZooKeeperServer.closeSession怎麽用?Java ZooKeeperServer.closeSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.server.ZooKeeperServer的用法示例。


在下文中一共展示了ZooKeeperServer.closeSession方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testHandleSessionExpiration

import org.apache.zookeeper.server.ZooKeeperServer; //導入方法依賴的package包/類
@Test(timeout=15000)
public void testHandleSessionExpiration() throws Exception {
  ActiveStandbyElectorCallback cb = cbs[0];
  byte[] appData = appDatas[0];
  ActiveStandbyElector elector = electors[0];
  
  // Let the first elector become active
  elector.ensureParentZNode();
  elector.joinElection(appData);
  ZooKeeperServer zks = getServer(serverFactory);
  ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
      zks, PARENT_DIR, appData);
  Mockito.verify(cb, Mockito.timeout(1000)).becomeActive();
  checkFatalsAndReset();
  
  LOG.info("========================== Expiring session");
  zks.closeSession(elector.getZKSessionIdForTests());

  // Should enter neutral mode when disconnected
  Mockito.verify(cb, Mockito.timeout(1000)).enterNeutralMode();

  // Should re-join the election and regain active
  ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
      zks, PARENT_DIR, appData);
  Mockito.verify(cb, Mockito.timeout(1000)).becomeActive();
  checkFatalsAndReset();
  
  LOG.info("========================== Quitting election");
  elector.quitElection(false);
  ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
      zks, PARENT_DIR, null);

  // Double check that we don't accidentally re-join the election
  // due to receiving the "expired" event.
  Thread.sleep(1000);
  Mockito.verify(cb, Mockito.never()).becomeActive();
  ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
      zks, PARENT_DIR, null);

  checkFatalsAndReset();
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:42,代碼來源:TestActiveStandbyElectorRealZK.java

示例2: testHandleSessionExpirationOfStandby

import org.apache.zookeeper.server.ZooKeeperServer; //導入方法依賴的package包/類
@Test(timeout=15000)
public void testHandleSessionExpirationOfStandby() throws Exception {
  // Let elector 0 be active
  electors[0].ensureParentZNode();
  electors[0].joinElection(appDatas[0]);
  ZooKeeperServer zks = getServer(serverFactory);
  ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
      zks, PARENT_DIR, appDatas[0]);
  Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeActive();
  checkFatalsAndReset();
  
  // Let elector 1 be standby
  electors[1].joinElection(appDatas[1]);
  ActiveStandbyElectorTestUtil.waitForElectorState(null, electors[1],
      State.STANDBY);
  
  LOG.info("========================== Expiring standby's session");
  zks.closeSession(electors[1].getZKSessionIdForTests());

  // Should enter neutral mode when disconnected
  Mockito.verify(cbs[1], Mockito.timeout(1000)).enterNeutralMode();

  // Should re-join the election and go back to STANDBY
  ActiveStandbyElectorTestUtil.waitForElectorState(null, electors[1],
      State.STANDBY);
  checkFatalsAndReset();
  
  LOG.info("========================== Quitting election");
  electors[1].quitElection(false);

  // Double check that we don't accidentally re-join the election
  // by quitting elector 0 and ensuring elector 1 doesn't become active
  electors[0].quitElection(false);
  
  // due to receiving the "expired" event.
  Thread.sleep(1000);
  Mockito.verify(cbs[1], Mockito.never()).becomeActive();
  ActiveStandbyElectorTestUtil.waitForActiveLockData(null,
      zks, PARENT_DIR, null);

  checkFatalsAndReset();
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:43,代碼來源:TestActiveStandbyElectorRealZK.java


注:本文中的org.apache.zookeeper.server.ZooKeeperServer.closeSession方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。