Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void happyClusterPropagatesUpdates() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void HappyClusterPropagatesUpdates()
        {
            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[] allMembers = {leader, member(1), member(2)};
            MemberId[] allMembers = new MemberId[] { leader, member(1), member(2) };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
            RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);

            fixture.Bootstrap(allMembers);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leaderMember = fixture.members().withId(leader).member();
            MemberId leaderMember = fixture.Members().withId(leader).member();

            // when
            fixture.Members().withId(leader).timerService().invoke(RaftMachine.Timeouts.Election);
            net.ProcessMessages();
            fixture.Members().withId(leader).raftInstance().handle(new RaftMessages_NewEntry_Request(leaderMember, valueOf(42)));
            net.ProcessMessages();

            // then
            foreach (MemberId aMember in allMembers)
            {
                assertThat(fixture.MessageLog(), IntegerValues(fixture.Members().withId(aMember).raftLog()), hasItems(42));
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void newMemberWithNoLogShouldCatchUpFromPeers() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void NewMemberWithNoLogShouldCatchUpFromPeers()
        {
            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 leaderId = member(0);
            MemberId leaderId = member(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId sleepyId = member(2);
            MemberId sleepyId = member(2);

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

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

            fixture.Bootstrap(allMembers);
            fixture.Members().withId(leaderId).raftInstance().installCoreState(new RaftCoreState(new MembershipEntry(0, new HashSet <MemberId>(Arrays.asList(allMembers)))));

            fixture.Members().withId(leaderId).timerService().invoke(RaftMachine.Timeouts.Election);
            net.ProcessMessages();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId leader = fixture.members().withId(leaderId).member();
            MemberId leader = fixture.Members().withId(leaderId).member();

            net.Disconnect(sleepyId);

            // when
            fixture.Members().withId(leaderId).raftInstance().handle(new RaftMessages_NewEntry_Request(leader, valueOf(10)));
            fixture.Members().withId(leaderId).raftInstance().handle(new RaftMessages_NewEntry_Request(leader, valueOf(20)));
            fixture.Members().withId(leaderId).raftInstance().handle(new RaftMessages_NewEntry_Request(leader, valueOf(30)));
            fixture.Members().withId(leaderId).raftInstance().handle(new RaftMessages_NewEntry_Request(leader, valueOf(40)));
            net.ProcessMessages();

            // then
            foreach (MemberId awakeMember in awakeMembers)
            {
                assertThat(IntegerValues(fixture.Members().withId(awakeMember).raftLog()), hasItems(10, 20, 30, 40));
            }

            assertThat(IntegerValues(fixture.Members().withId(sleepyId).raftLog()), empty());

            // when
            net.Reconnect(sleepyId);
            fixture.Members().invokeTimeout(RaftLogShipper.Timeouts.RESEND);
            net.ProcessMessages();

            // then
            assertThat(fixture.MessageLog(), IntegerValues(fixture.Members().withId(sleepyId).raftLog()), hasItems(10, 20, 30, 40));
        }
Esempio n. 3
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());
        }