public void TestLastPartnerUpdate()
 {
     var state = new InstanceState();
     Assert.IsNull(state.LastPartnerUpdate);
     var date = new DateTime(2025, 10, 10, 3, 4, 5, 6);
     state.LastPartnerUpdate = date;
     Assert.AreEqual(date, state.LastPartnerUpdate);
 }
        public void Test_SplitBrain_Backup()
        {
            StateChanged<InstanceState> stateChanged = null;
            var observer = new MockStateObserver(s => stateChanged = s, Assert.IsNull);
            InstanceState localState;
            ClusterException cex = null;
            ClusterStateMachine machine = CreateClusterStateMachine(observer, NodeRole.Backup, out localState,
                ex => cex = ex);
            var newState = new InstanceState
            {
                CurrentState = machine.Active,
                Role = NodeRole.Backup,
                Status = NodeStatus.Active
            };
            machine.TransitionToState(newState, machine.Active);

            var remoteState = new NodeState { Role = NodeRole.Primary, Status = NodeStatus.Active };
            machine.RaiseEvent(newState, machine.PartnerStatusReceived, remoteState);

            Assert.AreEqual(ClusterFailureReason.SplitBrain, cex.Reason);
            Assert.AreEqual("Stopped", stateChanged.Previous.Name);
            Assert.AreEqual("Final", stateChanged.Current.Name);
        }
 private static ClusterStateMachine CreateClusterStateMachine(MockStateObserver observer, NodeRole role,
     out InstanceState localState, Action<ClusterException> clusterExceptionAction = null, bool becomeActiveWhenPrimaryOnInitialConnectionTimeout = false)
 {
     var machine = new ClusterStateMachine(clusterExceptionAction ?? Assert.IsNull, s => true, becomeActiveWhenPrimaryOnInitialConnectionTimeout);
     machine.StateChanged.Subscribe(observer);
     localState = new InstanceState { Role = role };
     machine.RaiseEvent(localState, machine.Start);
     return machine;
 }
 private static ClusterStateMachine CreateClusterStateMachine(MockStateObserver observer, NodeRole role,
     out InstanceState localState, Action<ClusterException> clusterExceptionAction = null)
 {
     var machine = new ClusterStateMachine(clusterExceptionAction ?? Assert.IsNull, s => true);
     machine.StateChanged.Subscribe(observer);
     localState = new InstanceState {Role = role};
     machine.RaiseEvent(localState, machine.Start);
     return machine;
 }