Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecogniseSomeMembersBeingInconsistent() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecogniseSomeMembersBeingInconsistent()
        {
            // given
            ClusterState clusterState = new ClusterState(asSet(member(0), member(1), member(2)));

            clusterState.States[member(0)].entryLog.append(new RaftLogEntry(1, valueOf(1)));
            clusterState.States[member(1)].entryLog.append(new RaftLogEntry(1, valueOf(1)));
            clusterState.States[member(2)].entryLog.append(new RaftLogEntry(1, valueOf(1)));

            clusterState.States[member(0)].entryLog.append(new RaftLogEntry(1, valueOf(2)));
            clusterState.States[member(1)].entryLog.append(new RaftLogEntry(1, valueOf(2)));
            clusterState.States[member(2)].entryLog.append(new RaftLogEntry(2, valueOf(2)));

            Commit(clusterState, member(0), 0);
            Commit(clusterState, member(1), 0);
            Commit(clusterState, member(2), 0);

            // then
            assertFalse(inconsistentCommittedLogEntries(clusterState));

            // when
            Commit(clusterState, member(0), 1);
            Commit(clusterState, member(1), 1);

            // then
            assertFalse(inconsistentCommittedLogEntries(clusterState));

            // when
            Commit(clusterState, member(2), 1);

            // then
            assertTrue(inconsistentCommittedLogEntries(clusterState));
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static boolean inconsistentCommittedLogEntries(ClusterState state) throws java.io.IOException
        public static bool InconsistentCommittedLogEntries(ClusterState state)
        {
            int  index   = 0;
            bool moreLog = true;

            while (moreLog)
            {
                moreLog = false;
                RaftLogEntry clusterLogEntry = null;
                foreach (ComparableRaftState memberState in state.States.Values)
                {
                    if (index <= memberState.CommitIndex())
                    {
                        RaftLogEntry memberLogEntry = readLogEntry(memberState.EntryLog(), index);
                        if (clusterLogEntry == null)
                        {
                            clusterLogEntry = memberLogEntry;
                        }
                        else
                        {
                            if (!clusterLogEntry.Equals(memberLogEntry))
                            {
                                return(true);
                            }
                        }
                    }
                    if (index < memberState.CommitIndex())
                    {
                        moreLog = true;
                    }
                }
                index++;
            }
            return(false);
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void commit(ClusterState clusterState, org.neo4j.causalclustering.identity.MemberId member, long commitIndex) throws java.io.IOException
        private void Commit(ClusterState clusterState, MemberId member, long commitIndex)
        {
            ComparableRaftState state   = clusterState.States[member];
            Outcome             outcome = new Outcome(clusterState.Roles[member], state);

            outcome.CommitIndex = commitIndex;
            state.Update(outcome);
        }
Example #4
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            ClusterState that = ( ClusterState )o;

            return(Objects.Equals(Roles, that.Roles) && Objects.Equals(States, that.States) && Objects.Equals(Queues, that.Queues));
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static java.util.List<Violation> violations(ClusterState state) throws java.io.IOException
        public static IList <Violation> Violations(ClusterState state)
        {
            IList <Violation> invariantsViolated = new List <Violation>();

            if (MultipleLeadersInSameTerm(state))
            {
                invariantsViolated.Add(Violation.MultipleLeaders);
            }

            if (InconsistentCommittedLogEntries(state))
            {
                invariantsViolated.Add(Violation.DivergedLog);
            }

            return(invariantsViolated);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecogniseTwoLeadersInDifferentTerms() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecogniseTwoLeadersInDifferentTerms()
        {
            // given
            ClusterState clusterState = new ClusterState(asSet(member(0), member(1), member(2)));

            // when
            clusterState.States[member(0)].term = 21;
            clusterState.States[member(1)].term = 22;
            clusterState.States[member(2)].term = 21;

            clusterState.Roles[member(0)] = Role.LEADER;
            clusterState.Roles[member(1)] = Role.LEADER;
            clusterState.Roles[member(2)] = Role.FOLLOWER;

            // then
            assertFalse(multipleLeadersInSameTerm(clusterState));
        }
Example #7
0
        public static bool MultipleLeadersInSameTerm(ClusterState state)
        {
            ISet <long> termThatHaveALeader = new HashSet <long>();

            foreach (KeyValuePair <MemberId, Role> entry in state.Roles.SetOfKeyValuePairs())
            {
                RaftMessageHandler role = entry.Value.handler;
                if (role is Leader)
                {
                    long term = state.States[entry.Key].term();
                    if (termThatHaveALeader.Contains(term))
                    {
                        return(true);
                    }
                    else
                    {
                        termThatHaveALeader.Add(term);
                    }
                }
            }
            return(false);
        }
Example #8
0
 public ClusterState(ClusterState original)
 {
     this.Roles  = new Dictionary <MemberId, Role>(original.Roles);
     this.States = new Dictionary <MemberId, ComparableRaftState>(original.States);
     this.Queues = new Dictionary <MemberId, LinkedList <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> >(original.Queues);
 }