コード例 #1
0
            internal readonly ISet <MemberId> VotingMembersConflict;              // returned set is never mutated

            internal ReadOnlyRaftState(RaftState outerInstance, long leaderCommit, long commitIndex, long appendIndex, long lastLogIndexBeforeWeBecameLeader, long term, ISet <MemberId> votingMembers)
            {
                this._outerInstance       = outerInstance;
                this.LeaderCommitConflict = leaderCommit;
                this.CommitIndexConflict  = commitIndex;
                this.AppendIndexConflict  = appendIndex;
                this.LastLogIndexBeforeWeBecameLeaderConflict = lastLogIndexBeforeWeBecameLeader;
                this.TermConflict          = term;
                this.VotingMembersConflict = votingMembers;
            }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveFollowerStateAfterBecomingLeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRemoveFollowerStateAfterBecomingLeader()
        {
            // given
            RaftState raftState = new RaftState(member(0), new InMemoryStateStorage <TermState>(new TermState()), new FakeMembership(this), new InMemoryRaftLog(), new InMemoryStateStorage <VoteState>(new VoteState()), new ConsecutiveInFlightCache(), NullLogProvider.Instance, false, false);

            raftState.Update(new Outcome(CANDIDATE, 1, null, -1, null, emptySet(), emptySet(), -1, InitialFollowerStates(), true, EmptyLogCommands(), EmptyOutgoingMessages(), emptySet(), -1, emptySet(), false));

            // when
            raftState.Update(new Outcome(CANDIDATE, 1, null, -1, null, emptySet(), emptySet(), -1, new FollowerStates <MemberId>(), true, EmptyLogCommands(), EmptyOutgoingMessages(), emptySet(), -1, emptySet(), false));

            // then
            assertEquals(0, raftState.FollowerStates().size());
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public RaftState build() throws java.io.IOException
        public virtual RaftState Build()
        {
            StateStorage <TermState> termStore  = new InMemoryStateStorage <TermState>(new TermState());
            StateStorage <VoteState> voteStore  = new InMemoryStateStorage <VoteState>(new VoteState());
            StubMembership           membership = new StubMembership(_votingMembers, _replicationMembers);

            RaftState state = new RaftState(MyselfConflict, termStore, membership, _entryLog, voteStore, new ConsecutiveInFlightCache(), NullLogProvider.Instance, _supportPreVoting, _refusesToBeLeader);

            ICollection <Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed> noMessages = Collections.emptyList();
            IList <RaftLogCommand> noLogCommands = Collections.emptyList();

            state.Update(new Outcome(null, TermConflict, LeaderConflict, LeaderCommitConflict, _votedFor, _votesForMe, _preVotesForMe, _lastLogIndexBeforeWeBecameLeader, _followerStates, false, noLogCommands, noMessages, emptySet(), CommitIndexConflict, emptySet(), _isPreElection));

            return(state);
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateCacheState() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateCacheState()
        {
            //Test that updates applied to the raft state will be reflected in the entry cache.

            //given
            InFlightCache cache     = new ConsecutiveInFlightCache();
            RaftState     raftState = new RaftState(member(0), new InMemoryStateStorage <TermState>(new TermState()), new FakeMembership(this), new InMemoryRaftLog(), new InMemoryStateStorage <VoteState>(new VoteState()), cache, NullLogProvider.Instance, false, false);

            IList <RaftLogCommand> logCommands = new LinkedListAnonymousInnerClass(this);

            Outcome raftTestMemberOutcome = new Outcome(CANDIDATE, 0, null, -1, null, emptySet(), emptySet(), -1, InitialFollowerStates(), true, logCommands, EmptyOutgoingMessages(), emptySet(), -1, emptySet(), false);

            //when
            raftState.Update(raftTestMemberOutcome);

            //then
            assertNotNull(cache.Get(1L));
            assertNotNull(cache.Get(2L));
            assertNotNull(cache.Get(3L));
            assertEquals(valueOf(5), cache.Get(3L).content());
            assertNull(cache.Get(4L));
        }