Пример #1
0
        public void HeartbeatDoesntChangeRecomputeTime()
        {
            var       clusterState = new ClusterStateMachine();
            MachineId n1Id;

            (clusterState, n1Id) = clusterState.RegisterMachine(new MachineLocation("node1"), _clock.UtcNow);

            _clock.Increment(TimeSpan.FromMinutes(1));
            clusterState = clusterState.Heartbeat(n1Id, _clock.UtcNow, MachineState.Open).ThrowIfFailure().Next;

            clusterState.LastStateMachineRecomputeTimeUtc.Should().Be(DateTime.MinValue);
        }
Пример #2
0
        public void HeartbeatUpdatesLastHeartbeatTimeAndState()
        {
            var       clusterState = new ClusterStateMachine();
            MachineId machineId;

            (clusterState, machineId) = clusterState.RegisterMachine(new MachineLocation("node1"), _clock.UtcNow);

            _clock.Increment(TimeSpan.FromMinutes(1));
            clusterState = clusterState.Heartbeat(machineId, _clock.UtcNow, MachineState.Open).ThrowIfFailure().Next;

            var r = clusterState.GetStatus(machineId).ShouldBeSuccess().Value;

            r.LastHeartbeatTimeUtc.Should().Be(_clock.UtcNow);
            r.State.Should().Be(MachineState.Open);
        }
Пример #3
0
        public void HeartbeatKeepsOtherRecordsAsIs()
        {
            var clusterState = new ClusterStateMachine();
            var nowUtc       = _clock.UtcNow;

            MachineId n1Id;

            (clusterState, n1Id) = clusterState.RegisterMachine(new MachineLocation("node1"), nowUtc);

            MachineId n2Id;

            (clusterState, n2Id) = clusterState.RegisterMachine(new MachineLocation("node2"), nowUtc);

            _clock.Increment(TimeSpan.FromMinutes(1));
            clusterState = clusterState.Heartbeat(n1Id, _clock.UtcNow, MachineState.Closed).ThrowIfFailure().Next;

            var r = clusterState.GetStatus(n2Id).ShouldBeSuccess().Value;

            r.LastHeartbeatTimeUtc.Should().Be(nowUtc);
            r.State.Should().Be(MachineState.Open);
        }