예제 #1
0
    public static OperationalMessage?MessageFrom(string content)
    {
        if (content.StartsWith(APP))
        {
            return(ApplicationSays.From(content));
        }

        if (content.StartsWith(DIR))
        {
            return(Directory.From(content));
        }

        if (content.StartsWith(ELECT))
        {
            return(Elect.From(content));
        }

        if (content.StartsWith(JOIN))
        {
            return(Join.From(content));
        }

        if (content.StartsWith(LEADER))
        {
            return(Leader.From(content));
        }

        if (content.StartsWith(LEAVE))
        {
            return(Leave.From(content));
        }

        if (content.StartsWith(PING))
        {
            return(Ping.From(content));
        }

        if (content.StartsWith(PULSE))
        {
            return(Pulse.From(content));
        }

        if (content.StartsWith(SPLIT))
        {
            return(Split.From(content));
        }

        if (content.StartsWith(VOTE))
        {
            return(Vote.From(content));
        }

        return(null);
    }
        public void TestGenerateLeaderMessage()
        {
            var leader = new Leader(Id.Of(1));

            MessageConverters.MessageToBytes(leader, _messageBuffer);
            var raw = OperationalMessage.LEADER + "\nid=1";

            _expectedBuffer.Write(Converters.TextToBytes(raw));
            Assert.Equal(_expectedBuffer.ToArray(), _messageBuffer.ToArray());

            Assert.Equal(leader, Leader.From(raw));
        }