/// <exception cref="System.Exception"/>
 public virtual void TestDontJoinElectionOnDisconnectAndReconnect()
 {
     electors[0].EnsureParentZNode();
     StopServer();
     ActiveStandbyElectorTestUtil.WaitForElectorState(null, electors[0], ActiveStandbyElector.State
                                                      .Neutral);
     StartServer();
     WaitForServerUp(hostPort, ConnectionTimeout);
     // Have to sleep to allow time for the clients to reconnect.
     Thread.Sleep(2000);
     Org.Mockito.Mockito.Verify(cbs[0], Org.Mockito.Mockito.Never()).BecomeActive();
     Org.Mockito.Mockito.Verify(cbs[1], Org.Mockito.Mockito.Never()).BecomeActive();
     CheckFatalsAndReset();
 }
        /// <exception cref="System.Exception"/>
        public virtual void TestHandleSessionExpirationOfStandby()
        {
            // Let elector 0 be active
            electors[0].EnsureParentZNode();
            electors[0].JoinElection(appDatas[0]);
            ZooKeeperServer zks = GetServer(serverFactory);

            ActiveStandbyElectorTestUtil.WaitForActiveLockData(null, zks, ParentDir, appDatas
                                                               [0]);
            Org.Mockito.Mockito.Verify(cbs[0], Org.Mockito.Mockito.Timeout(1000)).BecomeActive
                ();
            CheckFatalsAndReset();
            // Let elector 1 be standby
            electors[1].JoinElection(appDatas[1]);
            ActiveStandbyElectorTestUtil.WaitForElectorState(null, electors[1], ActiveStandbyElector.State
                                                             .Standby);
            Log.Info("========================== Expiring standby's session");
            zks.CloseSession(electors[1].GetZKSessionIdForTests());
            // Should enter neutral mode when disconnected
            Org.Mockito.Mockito.Verify(cbs[1], Org.Mockito.Mockito.Timeout(1000)).EnterNeutralMode
                ();
            // Should re-join the election and go back to STANDBY
            ActiveStandbyElectorTestUtil.WaitForElectorState(null, electors[1], ActiveStandbyElector.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);
            Org.Mockito.Mockito.Verify(cbs[1], Org.Mockito.Mockito.Never()).BecomeActive();
            ActiveStandbyElectorTestUtil.WaitForActiveLockData(null, zks, ParentDir, null);
            CheckFatalsAndReset();
        }
示例#3
0
 /// <summary>Wait for the given elector to enter the given elector state.</summary>
 /// <param name="idx">the service index (0 or 1)</param>
 /// <param name="state">the state to wait for</param>
 /// <exception cref="System.Exception">
 /// if it times out, or an exception occurs on one
 /// of the ZKFC threads while waiting.
 /// </exception>
 public virtual void WaitForElectorState(int idx, ActiveStandbyElector.State state
                                         )
 {
     ActiveStandbyElectorTestUtil.WaitForElectorState(ctx, GetElector(idx), state);
 }