Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleMixedChangeToExistingRaftGroup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleMixedChangeToExistingRaftGroup()
        {
            DirectNetworking net = new DirectNetworking();

            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader = member(0);
            MemberId leader = member(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable = member(1);
            MemberId stable = member(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeRemoved1 = member(2);
            MemberId toBeRemoved1 = member(2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeRemoved2 = member(3);
            MemberId toBeRemoved2 = member(3);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeAdded1 = member(4);
            MemberId toBeAdded1 = member(4);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeAdded2 = member(5);
            MemberId toBeAdded2 = member(5);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] everyone = {leader, stable, toBeRemoved1, toBeRemoved2, toBeAdded1, toBeAdded2};
            MemberId[] everyone = new MemberId[] { leader, stable, toBeRemoved1, toBeRemoved2, toBeAdded1, toBeAdded2 };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] initialMembers = {leader, stable, toBeRemoved1, toBeRemoved2};
            MemberId[] initialMembers = new MemberId[] { leader, stable, toBeRemoved1, toBeRemoved2 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] finalMembers = {leader, stable, toBeAdded1, toBeAdded2};
            MemberId[] finalMembers = new MemberId[] { leader, stable, toBeAdded1, toBeAdded2 };

            RaftTestFixture fixture = new RaftTestFixture(net, 3, everyone);

            fixture.Bootstrap(initialMembers);

            fixture.Members().withId(leader).timerService().invoke(ELECTION);
            net.ProcessMessages();

            // when
            fixture.Members().withId(leader).raftInstance().TargetMembershipSet = (new RaftTestGroup(finalMembers)).Members;
            net.ProcessMessages();

            fixture.Members().withId(leader).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();
            fixture.Members().withId(leader).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();
            fixture.Members().withId(leader).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();

            // then
            assertThat(fixture.Members().withIds(finalMembers), HasCurrentMembers(new RaftTestGroup(finalMembers)));
            assertEquals(fixture.MessageLog(), 1, fixture.Members().withIds(finalMembers).withRole(LEADER).size());
            assertEquals(fixture.MessageLog(), 3, fixture.Members().withIds(finalMembers).withRole(FOLLOWER).size());
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddMultipleInstancesToExistingRaftGroup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddMultipleInstancesToExistingRaftGroup()
        {
            // given
            DirectNetworking net = new DirectNetworking();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader = member(0);
            MemberId leader = member(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable1 = member(1);
            MemberId stable1 = member(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable2 = member(2);
            MemberId stable2 = member(2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeAdded1 = member(3);
            MemberId toBeAdded1 = member(3);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeAdded2 = member(4);
            MemberId toBeAdded2 = member(4);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId toBeAdded3 = member(5);
            MemberId toBeAdded3 = member(5);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] initialMembers = {leader, stable1, stable2};
            MemberId[] initialMembers = new MemberId[] { leader, stable1, stable2 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] finalMembers = {leader, stable1, stable2, toBeAdded1, toBeAdded2, toBeAdded3};
            MemberId[] finalMembers = new MemberId[] { leader, stable1, stable2, toBeAdded1, toBeAdded2, toBeAdded3 };

            RaftTestFixture fixture = new RaftTestFixture(net, 3, finalMembers);

            fixture.Bootstrap(initialMembers);

            fixture.Members().withId(leader).timerService().invoke(ELECTION);
            net.ProcessMessages();

            // when
            fixture.Members().TargetMembershipSet = (new RaftTestGroup(finalMembers)).Members;
            net.ProcessMessages();

            // We need a heartbeat for every member we add. It is necessary to have the new members report their state
            // so their membership change can be processed. We can probably do better here.
            fixture.Members().withId(leader).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();
            fixture.Members().withId(leader).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();
            fixture.Members().withId(leader).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();

            // then
            assertThat(fixture.MessageLog(), fixture.Members().withIds(finalMembers), HasCurrentMembers(new RaftTestGroup(finalMembers)));
            assertEquals(fixture.MessageLog(), 1, fixture.Members().withRole(LEADER).size());
            assertEquals(fixture.MessageLog(), 5, fixture.Members().withRole(FOLLOWER).size());
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveLeaderAndAddItBackIn() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRemoveLeaderAndAddItBackIn()
        {
            DirectNetworking net = new DirectNetworking();

            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader1 = member(0);
            MemberId leader1 = member(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader2 = member(1);
            MemberId leader2 = member(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable1 = member(2);
            MemberId stable1 = member(2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable2 = member(3);
            MemberId stable2 = member(3);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] allMembers = {leader1, leader2, stable1, stable2};
            MemberId[] allMembers = new MemberId[] { leader1, leader2, stable1, stable2 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] fewerMembers = {leader2, stable1, stable2};
            MemberId[] fewerMembers = new MemberId[] { leader2, stable1, stable2 };

            RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);

            fixture.Bootstrap(allMembers);

            // when
            fixture.Members().withId(leader1).timerService().invoke(ELECTION);
            net.ProcessMessages();

            fixture.Members().withId(leader1).raftInstance().setTargetMembershipSet(new RaftTestGroup(fewerMembers)
                                                                                    .Members);
            net.ProcessMessages();

            fixture.Members().withId(leader2).timerService().invoke(ELECTION);
            net.ProcessMessages();

            fixture.Members().withId(leader2).raftInstance().setTargetMembershipSet(new RaftTestGroup(allMembers)
                                                                                    .Members);
            net.ProcessMessages();

            fixture.Members().withId(leader2).timerService().invoke(HEARTBEAT);
            net.ProcessMessages();

            // then
            assertTrue(fixture.MessageLog(), fixture.Members().withId(leader2).raftInstance().Leader);
            assertThat(fixture.MessageLog(), fixture.Members().withIds(allMembers), HasCurrentMembers(new RaftTestGroup(allMembers)));
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFormGroupWithoutAnyBootstrapping()
        public virtual void ShouldNotFormGroupWithoutAnyBootstrapping()
        {
            // given
            DirectNetworking net = new DirectNetworking();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] ids = {member(0), member(1), member(2)};
            MemberId[] ids = new MemberId[] { member(0), member(1), member(2) };

            RaftTestFixture fixture = new RaftTestFixture(net, 3, ids);

            fixture.Members().TargetMembershipSet = (new RaftTestGroup(ids)).Members;
            fixture.Members().invokeTimeout(ELECTION);

            // when
            net.ProcessMessages();

            // then
            assertThat(fixture.Members(), HasCurrentMembers(new RaftTestGroup(new int[0])));
            assertEquals(fixture.MessageLog(), 0, fixture.Members().withRole(LEADER).size());
            assertEquals(fixture.MessageLog(), 3, fixture.Members().withRole(FOLLOWER).size());
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveLeaderFromExistingRaftGroupAndActivelyTransferLeadership() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRemoveLeaderFromExistingRaftGroupAndActivelyTransferLeadership()
        {
            DirectNetworking net = new DirectNetworking();

            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader = member(0);
            MemberId leader = member(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable1 = member(1);
            MemberId stable1 = member(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable2 = member(2);
            MemberId stable2 = member(2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] initialMembers = {leader, stable1, stable2};
            MemberId[] initialMembers = new MemberId[] { leader, stable1, stable2 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] finalMembers = {stable1, stable2};
            MemberId[] finalMembers = new MemberId[] { stable1, stable2 };

            RaftTestFixture fixture = new RaftTestFixture(net, 2, initialMembers);

            fixture.Bootstrap(initialMembers);
            fixture.Members().withId(leader).timerService().invoke(ELECTION);
            net.ProcessMessages();

            // when
            fixture.Members().withId(leader).raftInstance().TargetMembershipSet = (new RaftTestGroup(finalMembers)).Members;
            net.ProcessMessages();

            fixture.Members().withId(stable1).timerService().invoke(ELECTION);
            net.ProcessMessages();

            // then
            assertThat(fixture.MessageLog(), fixture.Members().withIds(finalMembers), HasCurrentMembers(new RaftTestGroup(finalMembers)));
            assertTrue(fixture.MessageLog(), fixture.Members().withId(stable1).raftInstance().Leader || fixture.Members().withId(stable2).raftInstance().Leader);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldElectNewLeaderWhenOldOneAbruptlyLeaves() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldElectNewLeaderWhenOldOneAbruptlyLeaves()
        {
            DirectNetworking net = new DirectNetworking();

            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader1 = member(0);
            MemberId leader1 = member(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader2 = member(1);
            MemberId leader2 = member(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId stable = member(2);
            MemberId stable = member(2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId[] initialMembers = {leader1, leader2, stable};
            MemberId[] initialMembers = new MemberId[] { leader1, leader2, stable };

            RaftTestFixture fixture = new RaftTestFixture(net, 2, initialMembers);

            fixture.Bootstrap(initialMembers);

            fixture.Members().withId(leader1).timerService().invoke(ELECTION);
            net.ProcessMessages();

            // when
            net.Disconnect(leader1);
            fixture.Members().withId(leader2).timerService().invoke(ELECTION);
            net.ProcessMessages();

            // then
            assertTrue(fixture.MessageLog(), fixture.Members().withId(leader2).raftInstance().Leader);
            assertFalse(fixture.MessageLog(), fixture.Members().withId(stable).raftInstance().Leader);
            assertEquals(fixture.MessageLog(), 1, fixture.Members().withIds(leader2, stable).withRole(LEADER).size());
            assertEquals(fixture.MessageLog(), 1, fixture.Members().withIds(leader2, stable).withRole(FOLLOWER).size());
        }