Ejemplo n.º 1
0
        public void MainLogicModule_TransactionAnswerResult_ReceiveAnswersFromWriter()
        {
            const int distrServer1 = 22168;
            const int distrServer2 = 23168;

            #region hell

            var connectionConf = new ConnectionConfiguration("testService", 10);

            var distrconfig = new DistributorHashConfiguration(1);
            var queueconfig = new QueueConfiguration(1, 100);
            var dnet        = new DistributorNetModule(connectionConf,
                                                       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", distrServer1),
                                                     new ServerId("localhost", distrServer2),
                                                     new HashMapConfiguration("TestDistributorReceiveAndDbSendAsync",
                                                                              HashMapCreationMode.ReadFromFile,
                                                                              1, 1, HashFileType.Distributor));
            dnet.SetDistributor(ddistributor);

            var tranc = new TransactionModule(new QueueConfiguration(1, 1000), dnet, new TransactionConfiguration(4),
                                              distrconfig);
            var cache = new DistributorTimeoutCache(TimeSpan.FromMilliseconds(2000), TimeSpan.FromMilliseconds(200000));
            var main  = new MainLogicModule(cache, ddistributor, tranc);
            cache.SetMainLogicModule(main);

            var netReceive4  = new NetReceiverConfiguration(distrServer1, "localhost", "testService");
            var netReceive42 = new NetReceiverConfiguration(distrServer2, "localhost", "testService");
            var input        = new InputModuleWithParallel(new QueueConfiguration(2, 100000), main, tranc);
            var receiver4    = new NetDistributorReceiver(main, input,
                                                          ddistributor, netReceive4, netReceive42);

            ddistributor.Start();
            receiver4.Start();

            #endregion

            var t = 0;
            GlobalQueue.Queue.TransactionQueue.Registrate(data => Interlocked.Increment(ref t));
            GlobalQueue.Queue.Start();

            var connection = new SingleConnectionToDistributor(
                new ServerId("localhost", distrServer1), new ConnectionConfiguration("testService", 10),
                new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            connection.Connect();

            connection.TransactionAnswerResult(new Transaction("123", "123"));
            Thread.Sleep(TimeSpan.FromMilliseconds(100));
            connection.TransactionAnswerResult(new Transaction("1243", "1423"));
            Thread.Sleep(TimeSpan.FromMilliseconds(100));
            Assert.AreEqual(2, t);

            connection.Dispose();
            receiver4.Dispose();
        }
Ejemplo n.º 2
0
        public void Dispose()
        {
            Main.Dispose();
            _receiver.Dispose();
            Input.Dispose();
            _dnet.Dispose();
            Distributor.Dispose();

            _q.Dispose();
        }