Example #1
0
        public void WriterSystemModel_GetDestination_ChechAvailableServers()
        {
            var config = new DistributorHashConfiguration(1);

            var writer = new HashWriter(new HashMapConfiguration("test", HashMapCreationMode.CreateNew, 6, 3, HashFileType.Distributor));

            writer.CreateMap();
            writer.SetServer(0, "local", 11010, 157);
            writer.SetServer(1, "local", 11011, 157);
            writer.SetServer(2, "local", 11012, 157);
            writer.SetServer(3, "local", 11010, 157);
            writer.SetServer(4, "local", 11011, 157);
            writer.SetServer(5, "local", 11012, 157);
            writer.Save();

            var model = new WriterSystemModel(config,
                                              new HashMapConfiguration("test", HashMapCreationMode.ReadFromFile, 1,
                                                                       1, HashFileType.Distributor));

            model.Start();

            var ev = new InnerData(new Transaction("123", ""))
            {
                Transaction = new Transaction(HashConvertor.GetString("1"), "")
            };

            ev.Transaction.Destination = new List <ServerId>();

            var ret = model.GetDestination(ev);

            Assert.IsTrue(ret.Count == 1);
            model.ServerNotAvailable(ret.First());
            var ret2 = model.GetDestination(ev);

            Assert.IsTrue(ret2.Count == 1);
            Assert.AreNotEqual(ret.First(), ret2.First());
            model.ServerNotAvailable(ret2.First());
            var ret3 = model.GetDestination(ev);

            Assert.IsTrue(ret3.Count == 1);
            Assert.AreNotEqual(ret.First(), ret3.First());
            Assert.AreNotEqual(ret3.First(), ret2.First());
            model.ServerNotAvailable(ret3.First());
            var ret4 = model.GetDestination(ev);

            Assert.IsTrue(ret4.Count == 0);
        }
Example #2
0
        public void WriterSystemModel_GetUnavailableServers_CheckAvailableAndUnAvailableServers()
        {
            var server1 = new ServerId("local", 11010);
            var server2 = new ServerId("local", 11011);
            var server3 = new ServerId("local", 11012);

            var config = new DistributorHashConfiguration(1);

            var writer =
                new HashWriter(new HashMapConfiguration("TestDbModelGetUnavalibaleServers",
                                                        HashMapCreationMode.CreateNew, 6, 3, HashFileType.Collector));

            writer.CreateMap();
            writer.SetServer(0, server1.RemoteHost, server1.Port, 157);
            writer.SetServer(1, server2.RemoteHost, server2.Port, 157);
            writer.SetServer(2, server3.RemoteHost, server3.Port, 157);
            writer.SetServer(3, server1.RemoteHost, server1.Port, 157);
            writer.SetServer(4, server2.RemoteHost, server2.Port, 157);
            writer.SetServer(5, server3.RemoteHost, server3.Port, 157);
            writer.Save();

            var model = new WriterSystemModel(config,
                                              new HashMapConfiguration("TestDbModelGetUnavalibaleServers",
                                                                       HashMapCreationMode.ReadFromFile, 1,
                                                                       1, HashFileType.Writer));

            model.Start();

            model.ServerNotAvailable(server1);
            Assert.AreEqual(1, model.GetUnavailableServers().Count);
            model.ServerNotAvailable(server1);
            Assert.AreEqual(1, model.GetUnavailableServers().Count);
            model.ServerNotAvailable(server2);
            Assert.AreEqual(2, model.GetUnavailableServers().Count);
            model.ServerNotAvailable(server3);
            Assert.AreEqual(3, model.GetUnavailableServers().Count);
            model.ServerAvailable(server1);
            Assert.AreEqual(2, model.GetUnavailableServers().Count);
            model.ServerAvailable(server1);
            Assert.AreEqual(2, model.GetUnavailableServers().Count);
            model.ServerAvailable(server2);
            Assert.AreEqual(1, model.GetUnavailableServers().Count);
            model.ServerAvailable(server3);
            Assert.AreEqual(0, model.GetUnavailableServers().Count);
        }
Example #3
0
        public override void Start()
        {
            _queue.DistributorDistributorQueue.Registrate(_queueConfiguration, Process);
            _queue.DistributorTransactionCallbackQueue.Registrate(_queueConfiguration, ProcessCallbackTransaction);
            _modelOfDbWriters.Start();

            _asyncTaskModule.AddAsyncTask(
                new AsyncDataPeriod(_asyncPing.TimeoutPeriod, PingProcess, AsyncTasksNames.AsyncPing, -1), false);

            _asyncTaskModule.AddAsyncTask(
                new AsyncDataPeriod(_asyncCheck.TimeoutPeriod, CheckRestore, AsyncTasksNames.CheckRestore, -1), false);

            _asyncTaskModule.AddAsyncTask(
                new AsyncDataPeriod(_asyncCheck.TimeoutPeriod, DistributerPing, AsyncTasksNames.CheckDistributors, -1),
                false);

            _asyncTaskModule.Start();
        }
Example #4
0
        public void WriterSystemModel_GetDestination_CountReplics()
        {
            var config = new DistributorHashConfiguration(4);

            var writer = new HashWriter(new HashMapConfiguration("testhash", HashMapCreationMode.CreateNew, 6, 3, HashFileType.Distributor));

            writer.CreateMap();
            writer.SetServer(0, "local", 11010, 157);
            writer.SetServer(1, "local", 11011, 157);
            writer.SetServer(2, "local", 11012, 157);
            writer.SetServer(3, "local", 11010, 157);
            writer.SetServer(4, "local", 11011, 157);
            writer.SetServer(5, "local", 11012, 157);
            writer.Save();

            var model = new WriterSystemModel(config,
                                              new HashMapConfiguration("testhash", HashMapCreationMode.ReadFromFile,
                                                                       1, 1, HashFileType.Distributor));

            model.Start();

            var ev = new InnerData(new Transaction("123", ""))
            {
                Transaction = new Transaction(HashConvertor.GetString("1"), "")
            };

            ev.Transaction.Destination = new List <ServerId>();

            var ret = model.GetDestination(ev);

            Assert.IsTrue(ret.Count == 0);
            model = new WriterSystemModel(new DistributorHashConfiguration(3),
                                          new HashMapConfiguration("testhash", HashMapCreationMode.ReadFromFile, 1,
                                                                   1, HashFileType.Distributor));
            model.Start();

            ret = model.GetDestination(ev);
            Assert.AreEqual(3, ret.Count);
            Assert.AreNotEqual(ret[0], ret[1]);
            Assert.AreNotEqual(ret[0], ret[2]);
            Assert.AreNotEqual(ret[2], ret[1]);
        }