コード例 #1
0
        public void ProxyMainLogic_Process_SendDataToRealDistributor()
        {
            var queue = new QueueConfiguration(1, 1000);

            var server1   = new ServerId("localhost", 21171);
            var server2   = new ServerId("localhost", 21172);
            var server3   = new ServerId("localhost", 21173);
            var netconfig = new ConnectionConfiguration("testService", 10);

            TestHelper.OpenDistributorHost(server1, netconfig);
            TestHelper.OpenDistributorHost(server2, netconfig);

            var net = new ProxyNetModule(netconfig,
                                         new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var distributor = new ProxyDistributorModule(new AsyncProxyCache(TimeSpan.FromMinutes(100)), net, queue, server1,
                                                         new AsyncTasksConfiguration(TimeSpan.FromDays(1)),
                                                         new AsyncTasksConfiguration(TimeSpan.FromDays(1)));

            net.SetDistributor(distributor);

            var cache = new ProxyCache(TimeSpan.FromSeconds(20));
            var main  = new ProxyMainLogicModule(distributor, net, cache);

            net.Start();

            distributor.Start();

            distributor.SayIAmHere(server1);
            distributor.SayIAmHere(server2);
            distributor.SayIAmHere(server3);

            cache.Start();
            main.Start();

            const string hash = "";
            var          ev   = new InnerData(new Transaction("", ""));

            ev.Transaction = distributor.CreateTransaction(hash);
            ev.Transaction = distributor.CreateTransaction(hash);
            ev.Transaction = distributor.CreateTransaction(hash);

            ev.Transaction.Destination = new List <ServerId> {
                server1
            };

            bool res = main.Process(ev);

            var server = cache.Get(ev.Transaction.EventHash);

            Assert.IsNull(server);
            Assert.IsTrue(res);

            main.Dispose();
            distributor.Dispose();
            net.Dispose();
        }
コード例 #2
0
        public void ProxyDistributorModule_SayIAmHere_AddDistributor()
        {
            const int server1  = 22250;
            const int server2  = 22251;
            const int server3  = 22252;
            const int server4  = 22253;
            const int server42 = 23253;
            const int server5  = 22254;
            const int server52 = 23254;

            var q1 = new GlobalQueueInner();
            var q2 = new GlobalQueueInner();
            var q3 = new GlobalQueueInner();

            GlobalQueue.SetQueue(q1);
            var queue     = new QueueConfiguration(1, 1000);
            var netconfig = new ConnectionConfiguration("testService", 10);

            var netReceive = new NetReceiverConfiguration(server1, "localhost", "testService");
            var net        = new ProxyNetModule(netconfig,
                                                new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var distributor = new ProxyDistributorModule(new AsyncProxyCache(TimeSpan.FromMinutes(100)), net, queue, new ServerId("localhost", server1),
                                                         new AsyncTasksConfiguration(TimeSpan.FromDays(1)),
                                                         new AsyncTasksConfiguration(TimeSpan.FromDays(1)));

            net.SetDistributor(distributor);
            var receive = new ProxyNetReceiver(distributor, netReceive);

            GlobalQueue.SetQueue(q2);

            var netReceive2 = new NetReceiverConfiguration(server2, "localhost", "testService");
            var net2        = new ProxyNetModule(netconfig,
                                                 new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var distributor2 = new ProxyDistributorModule(new AsyncProxyCache(TimeSpan.FromMinutes(100)), net2, queue, new ServerId("localhost", server2),
                                                          new AsyncTasksConfiguration(TimeSpan.FromDays(1)),
                                                          new AsyncTasksConfiguration(TimeSpan.FromDays(1)));

            net2.SetDistributor(distributor2);
            var receive2 = new ProxyNetReceiver(distributor2, netReceive2);

            GlobalQueue.SetQueue(q3);

            var netReceive3 = new NetReceiverConfiguration(server3, "localhost", "testService");
            var net3        = new ProxyNetModule(netconfig,
                                                 new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var distributor3 = new ProxyDistributorModule(new AsyncProxyCache(TimeSpan.FromMinutes(100)), net3, queue, new ServerId("localhost", server3),
                                                          new AsyncTasksConfiguration(TimeSpan.FromDays(1)),
                                                          new AsyncTasksConfiguration(TimeSpan.FromDays(1)));

            net3.SetDistributor(distributor3);
            var receive3 = new ProxyNetReceiver(distributor3, netReceive3);

            var distrconfig = new DistributorHashConfiguration(2);
            var queueconfig = new QueueConfiguration(1, 100);
            var dnet        = new DistributorNetModule(netconfig,
                                                       new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var ddistributor = new DistributorModule(new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)),
                                                     new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), distrconfig,
                                                     queueconfig, dnet, new ServerId("localhost", server4),
                                                     new ServerId("localhost", server42),
                                                     new HashMapConfiguration("test7", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor));

            dnet.SetDistributor(ddistributor);

            var tranc = new TransactionModule(new QueueConfiguration(1, 1000), dnet, new TransactionConfiguration(4),
                                              new DistributorHashConfiguration(1));
            var main = new MainLogicModule(new DistributorTimeoutCache(new TimeSpan(), new TimeSpan()), ddistributor,
                                           tranc);
            var netReceive4  = new NetReceiverConfiguration(server4, "localhost", "testService");
            var netReceive42 = new NetReceiverConfiguration(server42, "localhost", "testService");

            var input     = new InputModuleWithParallel(new QueueConfiguration(1, 1), main, tranc);
            var receiver4 = new NetDistributorReceiver(main, input, ddistributor, netReceive4, netReceive42);

            GlobalQueue.SetQueue(q1);
            var dnet2 = new DistributorNetModule(netconfig,
                                                 new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var ddistributor2 = new DistributorModule(new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)),
                                                      new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)), distrconfig,
                                                      queueconfig, dnet2,
                                                      new ServerId("localhost", server5),
                                                      new ServerId("localhost", server52),
                                                      new HashMapConfiguration("test6", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor));

            dnet2.SetDistributor(ddistributor2);

            var netReceive5  = new NetReceiverConfiguration(server5, "localhost", "testService");
            var netReceive52 = new NetReceiverConfiguration(server52, "localhost", "testService");
            var receiver5    = new NetDistributorReceiver(main,
                                                          new InputModuleWithParallel(new QueueConfiguration(1, 1), main,
                                                                                      tranc),
                                                          ddistributor2, netReceive5, netReceive52);

            receive.Start();
            receive2.Start();
            receive3.Start();
            receiver4.Start();
            receiver5.Start();
            net.Start();
            net2.Start();
            net3.Start();
            distributor.Start();
            distributor2.Start();
            distributor3.Start();

            dnet.Start();
            dnet2.Start();
            ddistributor.Start();
            ddistributor2.Start();

            q1.Start();
            q2.Start();
            q3.Start();

            distributor.SayIAmHere(new ServerId("localhost", server42));
            distributor2.SayIAmHere(new ServerId("localhost", server42));

            var privateObject = new PrivateObject(distributor);
            var dsm1          = (DistributorSystemModel)privateObject.GetField("_distributorSystemModel");

            privateObject = new PrivateObject(distributor2);
            var dsm2 = (DistributorSystemModel)privateObject.GetField("_distributorSystemModel");

            Assert.AreEqual(1, dsm1.GetDistributorsList().Count);
            Assert.AreEqual(1, dsm2.GetDistributorsList().Count);

            ddistributor2.SayIAmHereRemoteResult(new ServerId("localhost", server42));

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

            privateObject = new PrivateObject(ddistributor);
            var mad1 =
                (Impl.DistributorModules.Model.DistributorSystemModel)
                privateObject.GetField("_modelOfAnotherDistributors");

            privateObject = new PrivateObject(ddistributor2);
            var mad2 =
                (Impl.DistributorModules.Model.DistributorSystemModel)
                privateObject.GetField("_modelOfAnotherDistributors");

            Thread.Sleep(400);

            Assert.AreEqual(1, mad1.GetDistributorList().Count);
            Assert.AreEqual(1, mad2.GetDistributorList().Count);

            distributor3.SayIAmHere(new ServerId("localhost", server52));

            privateObject = new PrivateObject(distributor3);
            var dsm3 = (DistributorSystemModel)privateObject.GetField("_distributorSystemModel");

            Assert.AreEqual(2, dsm3.GetDistributorsList().Count);

            q1.Dispose();
            q2.Dispose();
            q3.Dispose();

            net.Dispose();
            net2.Dispose();
            net3.Dispose();
            dnet.Dispose();
            dnet2.Dispose();

            ddistributor.Dispose();
            ddistributor2.Dispose();

            distributor.Dispose();
            distributor2.Dispose();
            distributor3.Dispose();
        }