public override void When()
        {
            _followers = new [] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            BecomeLeader();
            // All of the nodes have acked the first write
            WriterCheckpoint.Write(_firstLogPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            foreach (var follower in _followers)
            {
                Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(follower, _firstLogPosition));
            }
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());

            ReplicatedTos.Clear();

            // Followers 3 and 4 are lagging behind, they ack the previous positions
            WriterCheckpoint.Write(_secondLogPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_followers[0], _secondLogPosition));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_followers[1], _secondLogPosition));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_followers[2], _firstLogPosition));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_followers[3], _firstLogPosition));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());
        }
        public override void When()
        {
            BecomeLeader();
            // All of the nodes have acked the first write
            WriterCheckpoint.Write(_firstLogPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_follower1, _firstLogPosition));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_follower2, _firstLogPosition));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());

            ReplicatedTos.Clear();

            // Follower 2 has lost connection and does not ack the write
            WriterCheckpoint.Write(_secondLogPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_follower1, _secondLogPosition));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());
        }
Ejemplo n.º 3
0
        public override void When()
        {
            BecomeMaster();
            // All of the nodes have acked the first write
            WriterCheckpoint.Write(_firstLogPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica1, _firstLogPosition));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica2, _firstLogPosition - 100));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(Guid.NewGuid(), _firstLogPosition - 100));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(Guid.NewGuid(), _firstLogPosition - 100));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());

            ReplicatedTos.Clear();

            WriterCheckpoint.Write(_secondLogPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica1, _secondLogPosition));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());
        }
Ejemplo n.º 4
0
        public override void When()
        {
            BecomeMaster();
            WriterCheckpoint.Write(_logPosition);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.WriterCheckpointFlushed());
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica1, _logPosition));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica2, _logPosition));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());

            Service.Handle(new SystemMessage.VNodeConnectionLost(
                               PortsHelper.GetLoopback(),
                               Guid.NewGuid(),
                               _replica1));

            ReplicatedTos.Clear();
            WriterCheckpoint.Write(_logPosition2);
            WriterCheckpoint.Flush();
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica2, _logPosition2));
            Service.Handle(new ReplicationTrackingMessage.ReplicaWriteAck(_replica3, _logPosition2));
            AssertEx.IsOrBecomesTrue(() => Service.IsCurrent());
        }