Пример #1
0
        public void TestSeedNodeInitialState()
        {
            var n = NodeInformation.CreateSeedNode(endpoint);

            Assert.Equal(endpoint, n.Endpoint);
            Assert.Equal(NodeState.Unknown, n.NodeState);
            Assert.Equal(0, n.NodeVersion);
            Assert.Equal(0, n.LastKnownPropertyVersion);
            Assert.Single(n.Properties);
        }
Пример #2
0
        public void TestUpdateInitialSeedNode()
        {
            var n  = NodeInformation.CreateSeedNode(endpoint);
            var n2 = NodeInformation.CreateSelfNode(endpoint);

            n.Update(n2, logger);
            Assert.Equal(n2.NodeVersion, n.NodeVersion);
            Assert.Equal(n2.NodeState, n.NodeState);
            Assert.Equal(n2.LastKnownPropertyVersion, n.LastKnownPropertyVersion);
            Assert.Equal(n2.Properties.Count, n.Properties.Count);

            n2.Properties.Add(new Dictionary <string, VersionedProperty>
            {
                {
                    "test_key",
                    new VersionedProperty
                    {
                        Version        = 5,
                        StringProperty = "test_value"
                    }
                },
                {
                    "test_key2",
                    new VersionedProperty
                    {
                        Version        = 9,
                        StringProperty = "test_value2"
                    }
                }
            });
            n2.BumpVersion();

            n.Update(n2, logger);
            Assert.Equal(n2.NodeVersion, n.NodeVersion);
            Assert.Equal(n2.NodeState, n.NodeState);
            Assert.Equal(n2.LastKnownPropertyVersion, n.LastKnownPropertyVersion);
            Assert.Equal(n2.Properties, n.Properties);
        }
Пример #3
0
        public void TestFullSyncBasic()
        {
            const string node1Endpoint = "192.168.1.1:18841";
            const string node2Endpoint = "192.168.1.2:18841";

            var node1 = CreateNode(node1Endpoint, new[] { node2Endpoint }.Concat(SeedsEndpoint));
            var node2 = CreateNode(node2Endpoint, new[] { node1Endpoint }.Concat(SeedsEndpoint));

            var synRequest = new Ping1Request();

            synRequest.NodesSynopsis.AddRange(node1.GetNodesSynposis());

            var synResponse = node2.Syn(synRequest);

            var ack2Request  = node1.Ack1(synResponse);
            var ack2Response = node2.Ack2(ack2Request);

            Assert.Equal(new Ping2Response(), ack2Response);

            Assert.Equal(
                new NodeInformation
            {
                Endpoint          = node1Endpoint,
                NodeStateProperty = new VersionedProperty
                {
                    StateProperty = NodeState.Live,
                    Version       = 2
                },
                NodeVersion = GetNodeVersion(),
            },
                node1.nodeInformationDictionary[node1Endpoint]);
            Assert.Equal(
                new NodeInformation
            {
                Endpoint          = node2Endpoint,
                NodeStateProperty = new VersionedProperty
                {
                    StateProperty = NodeState.Live,
                    Version       = 2
                },
                NodeVersion = GetNodeVersion(),
            },
                node1.nodeInformationDictionary[node2Endpoint]);
            foreach (var e in SeedsEndpoint)
            {
                Assert.Equal(
                    NodeInformation.CreateSeedNode(e),
                    node1.nodeInformationDictionary[e]);
            }

            Assert.Equal(
                new NodeInformation
            {
                Endpoint          = node1Endpoint,
                NodeStateProperty = new VersionedProperty
                {
                    StateProperty = NodeState.Live,
                    Version       = 2
                },
                NodeVersion = GetNodeVersion(),
            },
                node2.nodeInformationDictionary[node1Endpoint]);
            Assert.Equal(
                new NodeInformation
            {
                Endpoint          = node2Endpoint,
                NodeStateProperty = new VersionedProperty
                {
                    StateProperty = NodeState.Live,
                    Version       = 2
                },
                NodeVersion = GetNodeVersion(),
            },
                node2.nodeInformationDictionary[node2Endpoint]);
            foreach (var e in SeedsEndpoint)
            {
                Assert.Equal(
                    NodeInformation.CreateSeedNode(e),
                    node2.nodeInformationDictionary[e]);
            }
        }