Inheritance: INodeCollection
コード例 #1
0
        public void AllCountTest()
        {
            var nodes = CreateNodes(NodesCount);
            var nodesCollection = new NodeCollection(nodes);

            Assert.AreEqual(NodesCount, nodesCollection.All.Count());
        }
コード例 #2
0
        public void AddNewNodeForbidsNullsTest()
        {
            var nodes = CreateNodes(2);
            var nodesCollection = new NodeCollection(nodes);

            Assert.Throws<ArgumentNullException>(() => nodesCollection.AddNewNode(null));
        }
コード例 #3
0
        public void AddNewNodeForbidsIdDuplication()
        {
            var nodes = CreateNodes(2);
            var nodesCollection = new NodeCollection(nodes);

            Assert.Throws<ArgumentException>(() => nodesCollection.AddNewNode(new NodeConfiguration{ServerId = 1}));
        }
コード例 #4
0
        public void CanAddNodesTest()
        {
            var nodes = CreateNodes(NodesCount);
            var nodesColection = new NodeCollection(nodes);

            nodesColection.AddNewNode(new NodeConfiguration() {ServerId = 19});

            Assert.AreEqual(NodesCount + 1, nodesColection.All.Count());
        }
コード例 #5
0
        public void AddNewNodeForbidsSecondMasterTest()
        {
            var nodes = CreateNodes(2, i => i == 0);
            var nodesCollection = new NodeCollection(nodes);

            var secondMaster = new Mock<INodeConfiguration>();
            secondMaster.SetupGet(m => m.IsMaster).Returns(true);
            Assert.Throws<ArgumentException>(() => nodesCollection.AddNewNode(secondMaster.Object));
        }
コード例 #6
0
        public void CanMarkAsDeadNodeTest()
        {
            var nodes = CreateNodes(NodesCount);
            var nodesColection = new NodeCollection(nodes);

            nodesColection.MarkAsDead(1);

            Assert.AreEqual(NodesCount - 1, nodesColection.All.Count());
            Assert.AreEqual(1, nodesColection.DeadNodesCount);
        }
コード例 #7
0
        public void CannotAddSecondMasterTest()
        {
            var nodes = CreateNodes(NodesCount);
            var nodesColection = new NodeCollection(nodes);

            var master = new NodeConfiguration() {IsMaster = true};

            Assert.Throws<ArgumentException>(() => nodesColection.AddNewNode(master));
        }
コード例 #8
0
        public void SyblingsTest()
        {
            m_ServerConfigurationMock.Setup((config) => config.ServerId).Returns(0);

            var nodes = CreateNodes(NodesCount);
            var nodesCollection = new NodeCollection(nodes);

            var syblings = nodesCollection.Siblings;

            Assert.IsFalse(syblings.Any(sybling => sybling.ServerId == ServerClass.Configuration.ServerId));
        }
コード例 #9
0
        public void SelfAccessTest()
        {
            m_ServerConfigurationMock.Setup((config) => config.ServerId).Returns(1);
            var nodes = CreateNodes(NodesCount);
            var nodesCollection = new NodeCollection(nodes);

            var self = nodesCollection.Self;

            Assert.AreEqual(nodes.Single(n => n.ServerId == 1), self);
        }
コード例 #10
0
        public void SelfAccessInCaseBadIdTest()
        {
            m_ServerConfigurationMock.Setup((config) => config.ServerId).Returns(11);
            var nodes = CreateNodes(NodesCount);
            var nodesCollection = new NodeCollection(nodes);

            Assert.Throws<ApplicationException>(() =>
                                                    {
                                                        var self = nodesCollection.Self;
                                                    });
        }
コード例 #11
0
        public void RemoveDeadNodeWorksWithInvalidIdsTest()
        {
            var nodes = CreateNodes(NodesCount);
            var nodesColection = new NodeCollection(nodes);

            Assert.DoesNotThrow(() => nodesColection.MarkAsDead(17));
        }
コード例 #12
0
        public void MasterThrowsExceptionInCaseOfManyMastersTest()
        {
            var nodes = CreateNodes(NodesCount, (serverId) => serverId < 2);
            var nodesCollection = new NodeCollection(nodes);

            Assert.Throws<ApplicationException>(() =>
            {
                var master = nodesCollection.Master;
            });
        }
コード例 #13
0
        public void MasterTest()
        {
            var nodes = CreateNodes(NodesCount, (serverId) => serverId == 0);
            var nodesCollection = new NodeCollection(nodes);

            var master = nodesCollection.Master;
            Assert.AreEqual(0, master.ServerId);
        }