예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldVoteFalseForCandidateInOldTerm() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldVoteFalseForCandidateInOldTerm()
        {
            // Given
            FakeClock                fakeClock    = Clocks.fakeClock();
            OnDemandTimerService     timerService = new OnDemandTimerService(fakeClock);
            OutboundMessageCollector messages     = new OutboundMessageCollector();

            RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).outbound(messages).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            // When
            raft.Handle(voteRequest().from(_member1).term(-1).candidate(_member1).lastLogIndex(0).lastLogTerm(-1).build());

            // Then
            assertThat(messages.SentTo(_member1).Count, equalTo(1));
            assertThat(messages.SentTo(_member1), hasItem(voteResponse().from(_myself).term(0).deny().build()));
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendNewLeaderBarrierAfterBecomingLeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendNewLeaderBarrierAfterBecomingLeader()
        {
            // Given
            FakeClock                fakeClock    = Clocks.fakeClock();
            OnDemandTimerService     timerService = new OnDemandTimerService(fakeClock);
            OutboundMessageCollector messages     = new OutboundMessageCollector();

            InMemoryRaftLog raftLog = new InMemoryRaftLog();
            RaftMachine     raft    = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).outbound(messages).raftLog(raftLog).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            // When
            timerService.Invoke(ELECTION);
            raft.Handle(voteResponse().from(_member1).term(1).grant().build());

            // Then
            assertEquals(new NewLeaderBarrier(), readLogEntry(raftLog, raftLog.AppendIndex()).content());
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldSendHeartBeatsOnHeartbeatTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldSendHeartBeatsOnHeartbeatTimeout()
        {
            // Given
            FakeClock                fakeClock    = Clocks.fakeClock();
            OnDemandTimerService     timerService = new OnDemandTimerService(fakeClock);
            OutboundMessageCollector messages     = new OutboundMessageCollector();

            RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).outbound(messages).clock(fakeClock).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            timerService.Invoke(ELECTION);
            raft.Handle(voteResponse().from(_member1).term(1).grant().build());

            // When
            timerService.Invoke(RaftMachine.Timeouts.Heartbeat);

            // Then
            assertTrue(last(messages.SentTo(_member1)) is RaftMessages_Heartbeat);
            assertTrue(last(messages.SentTo(_member2)) is RaftMessages_Heartbeat);
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void newMembersShouldBeIncludedInHeartbeatMessages() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void NewMembersShouldBeIncludedInHeartbeatMessages()
        {
            // Given
            DirectNetworking network = new DirectNetworking();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId newMember = member(99);
            MemberId newMember = member(99);

            DirectNetworking.Inbound <RaftMessages_RaftMessage> newMemberInbound = new Org.Neo4j.causalclustering.core.consensus.DirectNetworking.Inbound <RaftMessages_RaftMessage>(network, newMember);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final OutboundMessageCollector messages = new OutboundMessageCollector();
            OutboundMessageCollector messages = new OutboundMessageCollector();

            newMemberInbound.RegisterHandler((Org.Neo4j.causalclustering.messaging.Inbound_MessageHandler <RaftMessages_RaftMessage>)message => messages.send(newMember, message));

            FakeClock            fakeClock    = Clocks.fakeClock();
            OnDemandTimerService timerService = new OnDemandTimerService(fakeClock);
            RaftMachine          raft         = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).outbound(messages).clock(fakeClock).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            // We make ourselves the leader
            timerService.Invoke(ELECTION);
            raft.Handle(voteResponse().from(_member1).term(1).grant().build());

            // When
            raft.TargetMembershipSet = asSet(_myself, _member1, _member2, newMember);
            network.ProcessMessages();

            timerService.Invoke(RaftMachine.Timeouts.Heartbeat);
            network.ProcessMessages();

            // Then
            assertEquals(typeof(RaftMessages_AppendEntries_Request), messages.SentTo(newMember)[0].GetType());
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRequestVotesOnElectionTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRequestVotesOnElectionTimeout()
        {
            // Given
            FakeClock                fakeClock    = Clocks.fakeClock();
            OnDemandTimerService     timerService = new OnDemandTimerService(fakeClock);
            OutboundMessageCollector messages     = new OutboundMessageCollector();

            RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).electionTimeout(_electionTimeout).clock(fakeClock).outbound(messages).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            // When
            timerService.Invoke(ELECTION);

            // Then
            assertThat(messages.SentTo(_myself).Count, equalTo(0));

            assertThat(messages.SentTo(_member1).Count, equalTo(1));
            assertThat(messages.SentTo(_member1)[0], instanceOf(typeof(RaftMessages_Vote_Request)));

            assertThat(messages.SentTo(_member2).Count, equalTo(1));
            assertThat(messages.SentTo(_member2)[0], instanceOf(typeof(RaftMessages_Vote_Request)));
        }