コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSendAndReceive() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSendAndReceive()
        {
            // given: raft server handler
            int                   port            = PortAuthority.allocatePort();
            Semaphore             messageReceived = new Semaphore(0);
            ChannelInboundHandler nettyHandler    = new ChannelInboundHandlerAdapterAnonymousInnerClass(this, messageReceived);
            Server                raftServer      = raftServer(nettyHandler, port);

            raftServer.Start();

            // given: raft messaging service
            SenderService sender = RaftSender();

            sender.Start();

            // when
            AdvertisedSocketAddress to = new AdvertisedSocketAddress("localhost", port);
            MemberId  memberId         = new MemberId(System.Guid.randomUUID());
            ClusterId clusterId        = new ClusterId(System.Guid.randomUUID());

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request newEntryMessage = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(memberId, new MemberIdSet(asSet(memberId)));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage<?> message = org.neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage.of(clusterId, newEntryMessage);
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage <object> message = Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage.of(clusterId, newEntryMessage);

            sender.Send(to, message, Blocking);

            // then
            assertTrue(messageReceived.tryAcquire(15, SECONDS));

            // cleanup
            sender.Stop();
            raftServer.Stop();
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.causalclustering.core.consensus.outcome.Outcome handle(org.neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request req) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request req)
            {
                ReplicatedContent content = req.Content();

                Appending.AppendNewEntry(Ctx, Outcome, content);
                return(Outcome);
            }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Void handle(org.neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request newEntryRequest) throws Exception
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request newEntryRequest)
            {
                BoundedNetworkWritableChannel sizeBoundChannel = new BoundedNetworkWritableChannel(Channel.byteBuf(), ByteUnit.gibiBytes(1));

                Marshal.marshal(newEntryRequest.Content(), sizeBoundChannel);
                return(null);
            }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEncodeAndDecodeNewEntryRequest()
        public virtual void ShouldEncodeAndDecodeNewEntryRequest()
        {
            // given
            MemberId member = new MemberId(System.Guid.randomUUID());

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request request = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(member, ReplicatedInteger.valueOf(12));

            // when
            _channel.writeOutbound(request);
            object message = _channel.readOutbound();

            _channel.writeInbound(message);

            // then
            assertEquals(request, _channel.readInbound());
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldDecideToAppendToItsLogAndSendAppendEntriesMessageOnReceiptOfClientProposal() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldDecideToAppendToItsLogAndSendAppendEntriesMessageOnReceiptOfClientProposal()
        {
            // given
            RaftState state = raftState().votingMembers(asSet(_myself, _member1, _member2)).build();

            Leader leader = new Leader();

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request newEntryRequest = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(member(9), _content);

            // when
            Outcome outcome = leader.Handle(newEntryRequest, state, Log());
            //state.update( outcome );

            // then
            AppendLogEntry logCommand = ( AppendLogEntry )single(outcome.LogCommands);

            assertEquals(0, logCommand.Index);
            assertEquals(0, logCommand.Entry.term());

            ShipCommand.NewEntries shipCommand = (ShipCommand.NewEntries)single(outcome.ShipCommands);

            assertEquals(shipCommand, new ShipCommand.NewEntries(-1, -1, new RaftLogEntry[] { new RaftLogEntry(0, _content) }));
        }
コード例 #6
0
 public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request request)
 {
     return(Outcome);
 }
コード例 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf buffer, java.util.List<Object> list) throws Exception
        public override void Decode(ChannelHandlerContext ctx, ByteBuf buffer, IList <object> list)
        {
            ReadableChannel channel   = new NetworkReadableClosableChannelNetty4(buffer);
            ClusterId       clusterId = ClusterId.Marshal.INSTANCE.unmarshal(channel);

            int messageTypeWire = channel.Int;

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type[] values      = Enum.GetValues(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type));
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type   messageType = values[messageTypeWire];

            MemberId from = RetrieveMember(channel);

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage result;

            if (messageType.Equals(VOTE_REQUEST))
            {
                MemberId candidate = RetrieveMember(channel);

                long term         = channel.Long;
                long lastLogIndex = channel.Long;
                long lastLogTerm  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(from, term, candidate, lastLogIndex, lastLogTerm);
            }
            else if (messageType.Equals(VOTE_RESPONSE))
            {
                long term        = channel.Long;
                bool voteGranted = channel.Get() == 1;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(from, term, voteGranted);
            }
            else if (messageType.Equals(PRE_VOTE_REQUEST))
            {
                MemberId candidate = RetrieveMember(channel);

                long term         = channel.Long;
                long lastLogIndex = channel.Long;
                long lastLogTerm  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Request(from, term, candidate, lastLogIndex, lastLogTerm);
            }
            else if (messageType.Equals(PRE_VOTE_RESPONSE))
            {
                long term        = channel.Long;
                bool voteGranted = channel.Get() == 1;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Response(from, term, voteGranted);
            }
            else if (messageType.Equals(APPEND_ENTRIES_REQUEST))
            {
                // how many
                long term         = channel.Long;
                long prevLogIndex = channel.Long;
                long prevLogTerm  = channel.Long;

                long leaderCommit = channel.Long;
                long count        = channel.Long;

                RaftLogEntry[] entries = new RaftLogEntry[( int )count];
                for (int i = 0; i < count; i++)
                {
                    long entryTerm = channel.Long;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.replication.ReplicatedContent content = marshal.unmarshal(channel);
                    ReplicatedContent content = _marshal.unmarshal(channel);
                    entries[i] = new RaftLogEntry(entryTerm, content);
                }

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(from, term, prevLogIndex, prevLogTerm, entries, leaderCommit);
            }
            else if (messageType.Equals(APPEND_ENTRIES_RESPONSE))
            {
                long term        = channel.Long;
                bool success     = channel.Get() == 1;
                long matchIndex  = channel.Long;
                long appendIndex = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(from, term, success, matchIndex, appendIndex);
            }
            else if (messageType.Equals(NEW_ENTRY_REQUEST))
            {
                ReplicatedContent content = _marshal.unmarshal(channel);

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(from, content);
            }
            else if (messageType.Equals(HEARTBEAT))
            {
                long leaderTerm      = channel.Long;
                long commitIndexTerm = channel.Long;
                long commitIndex     = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(from, leaderTerm, commitIndex, commitIndexTerm);
            }
            else if (messageType.Equals(HEARTBEAT_RESPONSE))
            {
                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(from);
            }
            else if (messageType.Equals(LOG_COMPACTION_INFO))
            {
                long leaderTerm = channel.Long;
                long prevIndex  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo(from, leaderTerm, prevIndex);
            }
            else
            {
                throw new System.ArgumentException("Unknown message type");
            }

            list.Add(Org.Neo4j.causalclustering.core.consensus.RaftMessages_ReceivedInstantClusterIdAwareMessage.of(_clock.instant(), clusterId, result));
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Void handle(org.neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request request) throws Exception
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request request)
            {
                SerializableContents(request.Content(), Out);
                return(null);
            }
コード例 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Void handle(org.neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request newEntryRequest) throws Exception
            public override Void Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request newEntryRequest)
            {
                return(null);
            }