/** * Expires the ZK session associated with service 'fromIdx', and waits * until service 'toIdx' takes over. * @throws Exception if the target service does not become active */ public void expireAndVerifyFailover(int fromIdx, int toIdx) throws Exception { Preconditions.checkArgument(fromIdx != toIdx); getElector(fromIdx).preventSessionReestablishmentForTests(); try { expireActiveLockHolder(fromIdx); waitForHAState(fromIdx, HAServiceState.STANDBY); waitForHAState(toIdx, HAServiceState.ACTIVE); } finally { getElector(fromIdx).allowSessionReestablishmentForTests(); } }
/** * Expires the ZK session associated with service 'fromIdx', and waits * until service 'toIdx' takes over. * @throws Exception if the target service does not become active */ public void expireAndVerifyFailover(int fromIdx, int toIdx) throws Exception { Preconditions.checkArgument(fromIdx != toIdx); getElector(fromIdx).preventSessionReestablishmentForTests(); try { expireActiveLockHolder(fromIdx); waitForHAState(fromIdx, HAServiceState.STANDBY); waitForHAState(toIdx, HAServiceState.ACTIVE); } finally { getElector(fromIdx).allowSessionReestablishmentForTests(); } }
/** * Test that, if the standby node is unhealthy, it doesn't try to become * active */ @Test public void testDontFailoverToUnhealthyNode() throws Exception { cluster.start(); // Make svc1 unhealthy, and wait for its FC to notice the bad health. cluster.setHealthy(1, false); cluster.waitForHealthState(1, HealthMonitor.State.SERVICE_UNHEALTHY); // Expire svc0 cluster.getElector(0).preventSessionReestablishmentForTests(); try { cluster.expireActiveLockHolder(0); LOG.info("Expired svc0's ZK session. Waiting a second to give svc1" + " a chance to take the lock, if it is ever going to."); Thread.sleep(1000); // Ensure that no one holds the lock. cluster.waitForActiveLockHolder(null); } finally { LOG.info("Allowing svc0's elector to re-establish its connection"); cluster.getElector(0).allowSessionReestablishmentForTests(); } // svc0 should get the lock again cluster.waitForActiveLockHolder(0); }
cluster.getElector(0).preventSessionReestablishmentForTests(); try { cluster.expireActiveLockHolder(0);
electors[1].preventSessionReestablishmentForTests(); try { zkServer.closeSession(electors[1].getZKSessionIdForTests()); electors[0].preventSessionReestablishmentForTests(); try { zkServer.closeSession(electors[0].getZKSessionIdForTests());
electors[1].preventSessionReestablishmentForTests(); try { zkServer.closeSession(electors[1].getZKSessionIdForTests()); electors[0].preventSessionReestablishmentForTests(); try { zkServer.closeSession(electors[0].getZKSessionIdForTests());