Exemple #1
0
        public void LogReplicatorCallsAppendEntriesPassingEncodedLog()
        {
            // Arrange
            var encodedLog = BitConverter.GetBytes(100);
            AppendEntriesRequest request = null;

            var service = Substitute.For <IRaftService>();

            service.When(x => x.AppendEntries(Arg.Any <AppendEntriesRequest>()))
            .Do(x => request = x.Arg <AppendEntriesRequest>());

            var peers = new List <PeerNode> {
                new PeerNode()
            };

            var handler = new LogReplicator(peers);

            var @event = TestEventFactory.GetCommandEvent(1L, encodedLog);

            // Act
            handler.Handle(@event);

            // Assert
            request.Should().NotBeNull();
            request.Entries.Should().HaveCount(1);
            request.Entries[0].Should().Equal(encodedLog);
        }
Exemple #2
0
        public void LogReplicatorCallsAppendEntriesOnOtherNodesInCluster()
        {
            // Arrange
            var service1 = Substitute.For <IRaftService>();
            var service2 = Substitute.For <IRaftService>();

            var peers = new List <PeerNode> {
                new PeerNode(),
                new PeerNode()
            };

            var handler = new LogReplicator(peers);

            var encodedLog = BitConverter.GetBytes(100);
            var @event     = TestEventFactory.GetCommandEvent(1L, encodedLog);

            // Act
            handler.Handle(@event);

            // Assert
            service1.Received().AppendEntries(Arg.Any <AppendEntriesRequest>());
            service2.Received().AppendEntries(Arg.Any <AppendEntriesRequest>());
        }