ZKFailoverController { void cedeActive(final int millisToCede) throws AccessControlException, ServiceFailedException, IOException { try { UserGroupInformation.getLoginUser().doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { doCedeActive(millisToCede); return null; } }); } catch (InterruptedException e) { throw new IOException(e); } } protected  ZKFailoverController(Configuration conf, HAServiceTarget localTarget); HAServiceTarget getLocalTarget(); @VisibleForTesting HAServiceState getServiceState(); int run(final String[] args); @VisibleForTesting ActiveStandbyElector getElectorForTests(); static final String ZK_QUORUM_KEY; static final String ZK_ACL_KEY; static final String ZK_AUTH_KEY; }
@Test public void testCedeActive() throws Exception { cluster.start(); DummyZKFC zkfc = cluster.getZkfc(0); assertEquals(ActiveStandbyElector.State.ACTIVE, zkfc.getElectorForTests().getStateForTests()); ZKFCProtocol proxy = zkfc.getLocalTarget().getZKFCProxy(conf, 5000); long st = Time.now(); proxy.cedeActive(3000); long et = Time.now(); assertTrue("RPC to cedeActive took " + (et - st) + " ms", et - st < 1000); assertEquals(ActiveStandbyElector.State.INIT, zkfc.getElectorForTests().getStateForTests()); cluster.waitForElectorState(0, ActiveStandbyElector.State.STANDBY); long et2 = Time.now(); assertTrue("Should take ~3 seconds to rejoin. Only took " + (et2 - et) + "ms before rejoining.", et2 - et > 2800); }