Exemple #1
0
        public void DbModule_LocalAndRemoteData_Count()
        {
            var provider = new IntHashConvertor();

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

            writer.CreateMap();
            writer.SetServer(0, "localhost", 157, 157);
            writer.SetServer(1, "localhost", 11011, 157);
            writer.Save();

            _writer1.Build(157, "TestLocalAndRemote", 1);

            var       list  = new List <InnerData>();
            const int count = 100;

            for (int i = 0; i < count; i++)
            {
                var ev =
                    new InnerData(new Transaction(provider.CalculateHashFromKey(i), "")
                {
                    OperationName = OperationName.Create
                })
                {
                    Data        = CommonDataSerializer.Serialize(i),
                    Key         = CommonDataSerializer.Serialize(i),
                    Transaction = { Distributor = new ServerId("localhost", 22188) }
                };
                ev.Transaction.TableName = "Int";

                list.Add(ev);
            }

            TestHelper.OpenDistributorHostForDb(new ServerId("localhost", 22188), new ConnectionConfiguration("testService", 10));

            _writer1.Start();

            foreach (var data in list)
            {
                _writer1.Input.Process(data);
            }

            Thread.Sleep(1000);

            var mem = _writer1.Db.GetDbModules.First() as TestDbInMemory;

            Assert.AreNotEqual(count, mem.Local);
            Assert.AreNotEqual(count, mem.Remote);
            Assert.AreEqual(count, mem.Local + mem.Remote);

            _writer1.Dispose();
        }
Exemple #2
0
        public void Writer_Restore_TwoServers()
        {
            var writer =
                new HashWriter(new HashMapConfiguration("test8", HashMapCreationMode.CreateNew, 2, 3,
                                                        HashFileType.Distributor));

            writer.CreateMap();
            writer.SetServer(0, "localhost", storageServer1, 157);
            writer.SetServer(1, "localhost", storageServer2, 157);
            writer.Save();

            _distrTest.Build(1, distrServer1, distrServer12, "test8");

            _writer1.Build(storageServer1, "test8", 1);
            _writer2.Build(storageServer2, "test8", 1);

            _distrTest.Start();
            _writer1.Start();

            var       list  = new List <InnerData>();
            const int count = 1;

            for (int i = 1; i < count + 1; i++)
            {
                var ev =
                    new InnerData(new Transaction(HashConvertor.GetString(i.ToString(CultureInfo.InvariantCulture)), "")
                {
                    OperationName = OperationName.Create,
                    OperationType = OperationType.Async
                })
                {
                    Data        = CommonDataSerializer.Serialize(i),
                    Key         = CommonDataSerializer.Serialize(i),
                    Transaction = { Distributor = new ServerId("localhost", distrServer1) }
                };
                ev.Transaction.TableName = "Int";

                list.Add(ev);
            }

            foreach (var data in list)
            {
                _distrTest.Input.ProcessAsync(data);
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(6000));

            foreach (var data in list)
            {
                var tr = _distrTest.Main.GetTransactionState(data.Transaction.UserTransaction);
                if (tr.State != TransactionState.Complete)
                {
                    data.Transaction = new Transaction(data.Transaction);
                    data.Transaction.ClearError();
                    _distrTest.Input.ProcessAsync(data);
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5000));

            var mem  = _writer1.Db.GetDbModules.First() as TestDbInMemory;
            var mem2 = _writer2.Db.GetDbModules.First() as TestDbInMemory;

            if (count > 1)
            {
                Assert.AreNotEqual(count, mem.Local);
                Assert.AreNotEqual(count, mem.Remote);
            }
            Assert.AreEqual(count, mem.Local + mem.Remote);

            _writer2.Start();

            _writer2.Distributor.Restore(new ServerId("localhost", distrServer1), false);

            Thread.Sleep(TimeSpan.FromMilliseconds(2000));

            Assert.AreEqual(0, mem.Remote);
            Assert.AreEqual(0, mem2.Remote);
            Assert.AreEqual(count, mem.Local + mem2.Local);
            Assert.AreEqual(false, _writer1.Restore.IsNeedRestore);
            Assert.AreEqual(false, _writer2.Restore.IsNeedRestore);

            _distrTest.Dispose();
            _writer1.Dispose();
            _writer2.Dispose();
        }
Exemple #3
0
        public void Writer_SendRestoreCommandToDistributors_RestoreRemoteTable()
        {
            const int distrServer1   = 22113;
            const int distrServer12  = 23113;
            const int distrServer2   = 22114;
            const int distrServer22  = 23114;
            const int storageServer1 = 22115;
            const int storageServer2 = 22116;

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

            writer.CreateMap();
            writer.SetServer(0, "localhost", storageServer1, 157);
            writer.SetServer(1, "localhost", storageServer2, 157);
            writer.Save();

            writer =
                new HashWriter(new HashMapConfiguration("test6", HashMapCreationMode.CreateNew, 2, 3,
                                                        HashFileType.Writer));
            writer.CreateMap();
            writer.SetServer(0, "localhost", storageServer1, 157);
            writer.SetServer(1, "localhost", storageServer2, 157);
            writer.Save();

            _distributor1.Build(2, distrServer1, distrServer12, "test7");
            _distributor2.Build(2, distrServer2, distrServer22, "test6");

            _writer1.Build(storageServer1, "test6", 2);
            _writer2.Build(storageServer2, "test7", 2);

            _proxy.Start();

            _distributor1.Start();
            _distributor2.Start();

            _proxy.Distributor.SayIAmHere(new ServerId("localhost", distrServer12));
            _proxy.Distributor.SayIAmHere(new ServerId("localhost", distrServer22));

            _distributor2.Distributor.SayIAmHereRemoteResult(new ServerId("localhost", distrServer12));

            Thread.Sleep(TimeSpan.FromMilliseconds(300));
            Assert.AreEqual(1, _distributor1.Distributor.GetDistributors().Count);
            Assert.AreEqual(1, _distributor2.Distributor.GetDistributors().Count);

            var api = _proxy.CreateApi("Int", false, new IntHashConvertor());

            var tr1 = api.CreateSync(10, 10);
            var tr2 = api.CreateSync(11, 11);

            tr1.Wait();
            tr2.Wait();

            _writer1.Start();
            _writer2.Start();

            _writer1.Distributor.Restore(new ServerId("localhost", distrServer1), false);

            _writer2.Distributor.Restore(new ServerId("localhost", distrServer2), false);

            Thread.Sleep(TimeSpan.FromMilliseconds(2000));

            var tr3 = api.CreateSync(12, 12);
            var tr4 = api.CreateSync(13, 13);

            tr3.Wait();
            tr4.Wait();

            var mem  = _writer1.Db.GetDbModules.First() as TestDbInMemory;
            var mem2 = _writer2.Db.GetDbModules.First() as TestDbInMemory;

            Assert.AreEqual(2, mem.Local);
            Assert.AreEqual(2, mem2.Local);

            _writer1.Dispose();
            _writer2.Dispose();

            _proxy.Dispose();

            _distributor1.Dispose();
            _distributor2.Dispose();
        }
Exemple #4
0
        public void Writer_Restore_ThreeServers()
        {
            var writer =
                new HashWriter(new HashMapConfiguration("test11", HashMapCreationMode.CreateNew, 3, 3,
                                                        HashFileType.Distributor));

            writer.CreateMap();
            writer.SetServer(0, "localhost", storageServer1, 157);
            writer.SetServer(1, "localhost", storageServer2, 157);
            writer.SetServer(2, "localhost", storageServer3, 157);
            writer.Save();

            #region hell

            var queue      = new QueueConfiguration(2, 100);
            var connection = new ConnectionConfiguration("testService", 10);
            var ndrc2      = new NetReceiverConfiguration(proxyServer, "localhost", "testService");
            var pcc        = new ProxyCacheConfiguration(TimeSpan.FromSeconds(20));
            var pccc2      = new ProxyCacheConfiguration(TimeSpan.FromSeconds(40));

            var proxy = new TestProxySystem(new ServerId("localhost", proxyServer),
                                            queue, connection, pcc, pccc2, ndrc2,
                                            new AsyncTasksConfiguration(new TimeSpan()),
                                            new AsyncTasksConfiguration(new TimeSpan()),
                                            new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));

            _distrTest.Build(1, distrServer1, distrServer12, "test11");
            _writer1.Build(storageServer1, "test11", 1);
            _writer2.Build(storageServer2, "test11", 1);
            _writer3.Build(storageServer3, "test11", 1);

            #endregion

            #region hell2

            proxy.Build();
            proxy.Start();

            _distrTest.Start();
            _writer1.Start();

            proxy.Distributor.SayIAmHere(new ServerId("localhost", distrServer12));

            Thread.Sleep(TimeSpan.FromMilliseconds(200));

            int count   = 50;
            int counter = 0;

            var api = proxy.CreateApi("Int", false, new IntHashConvertor());

            for (int i = 0; i < count; i++)
            {
                bool flag = false;

                while (!flag && counter < 3)
                {
                    var task = api.CreateSync(i + 1, i + 1);
                    task.Wait();
                    flag = true;
                    if (task.Result.IsError)
                    {
                        counter++;
                        flag = false;
                    }
                }
            }
            Assert.AreEqual(2, counter);

            #endregion

            var mem  = _writer1.Db.GetDbModules.First() as TestDbInMemory;
            var mem2 = _writer2.Db.GetDbModules.First() as TestDbInMemory;
            var mem3 = _writer3.Db.GetDbModules.First() as TestDbInMemory;

            if (count > 1)
            {
                Assert.AreNotEqual(count, mem.Local);
                Assert.AreNotEqual(count, mem.Remote);
            }
            Assert.AreEqual(count, mem.Local + mem.Remote);

            _writer2.Start();
            _writer3.Start();

            _writer2.Distributor.Restore(new ServerId("localhost", distrServer1), false);

            Thread.Sleep(TimeSpan.FromMilliseconds(4000));

            _writer3.Distributor.Restore(new ServerId("localhost", distrServer1), false);

            Thread.Sleep(TimeSpan.FromMilliseconds(3000));

            Assert.AreEqual(0, mem.Remote);
            Assert.AreEqual(0, mem2.Remote);
            Assert.AreEqual(0, mem3.Remote);
            Assert.AreEqual(count, mem.Local + mem2.Local + mem3.Local);
            Assert.AreEqual(false, _writer1.Restore.IsNeedRestore);
            Assert.AreEqual(false, _writer2.Restore.IsNeedRestore);
            Assert.AreEqual(false, _writer3.Restore.IsNeedRestore);

            _distrTest.Dispose();
            _writer1.Dispose();
            _writer2.Dispose();
            _writer3.Dispose();

            proxy.Dispose();
        }