Esempio n. 1
0
        public void DistributorTimeoutCache_GetUpdate()
        {
            var cache = new DistributorTimeoutCache(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(500));

            var ev = new InnerData(new Transaction("123", ""))
            {
                Transaction = { Destination = new List <ServerId>() }
            };

            cache.AddToCache("123", ev.Transaction);
            var ret = cache.Get("123");

            Assert.AreEqual(ev.Transaction, ret);
            ev.Transaction.Complete();
            cache.Update("123", ev.Transaction);
            ret = cache.Get("123");
            Assert.AreEqual(ev.Transaction, ret);
            Thread.Sleep(200);
            ret = cache.Get("123");
            Assert.AreEqual(ev.Transaction, ret);
            Assert.AreEqual(TransactionState.Complete, ev.Transaction.State);
            Thread.Sleep(500);
            ret = cache.Get("123");
            Assert.AreEqual(null, ret);
        }
Esempio n. 2
0
        public void TransactionAnswerIncome(Common.Data.TransactionTypes.Transaction transaction)
        {
            var item = _cache.Get(transaction.CacheKey);

            //Так как обработка однопоточная, то если элемента нет в кеше
            // значит, что либо кеш обновляется(только в случае ошибки), либо
            // элемента просто нет в кеше(тоже ошибка)
            if (item == null)
            {
                return;
            }

            if (item.IsError)
            {
                if (transaction.IsError)
                {
                    AddErrorAndUpdate(item, transaction.ErrorDescription);
                }
                return;
            }

            if (transaction.IsError)
            {
                AddErrorAndUpdate(item, transaction.ErrorDescription);
            }

            item.IncreaseTransactionAnswersCount();

            if (item.TransactionAnswersCount > _transaction.CountReplics)
            {
                AddErrorAndUpdate(item, Errors.TransactionCountAnswersError);
                return;
            }

            if (item.TransactionAnswersCount == _transaction.CountReplics)
            {
                FinishTransaction(item);
            }
        }
Esempio n. 3
0
        public void DistributorTimeoutCache_TimeoutData_SendToMainLogicModuleObsoleteData()
        {
            var cache = new DistributorTimeoutCache(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(500));

            var net = new DistributorNetModule(new ConnectionConfiguration("", 1),
                                               new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout));
            var distributor = new DistributorModule(new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)),
                                                    new AsyncTasksConfiguration(TimeSpan.FromMinutes(5)),
                                                    new DistributorHashConfiguration(1), new QueueConfiguration(1, 1),
                                                    net, new ServerId("", -1), new ServerId("", -1),
                                                    new HashMapConfiguration("", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor));
            var trans = new TransactionModule(new QueueConfiguration(1, 1000), net, new TransactionConfiguration(1),
                                              new DistributorHashConfiguration(1));
            var main = new MainLogicModule(cache, distributor, trans);

            cache.SetMainLogicModule(main);

            var ev = new InnerData(new Transaction("123", "")
            {
                OperationName = OperationName.Create
            })
            {
                Transaction = { Destination = new List <ServerId>() }
            };

            ev.Transaction.Complete();
            cache.AddToCache(ev.Transaction.CacheKey, ev.Transaction);
            var ret = cache.Get(ev.Transaction.CacheKey);

            Assert.AreEqual(ev.Transaction, ret);
            Thread.Sleep(200);
            cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(TransactionState.Complete, ev.Transaction.State);
            Thread.Sleep(200);
            cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(TransactionState.Complete, ev.Transaction.State);
            Thread.Sleep(500);
            ret = cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(null, ret);

            ev = new InnerData(new Transaction("1231", "")
            {
                OperationName = OperationName.Create
            })
            {
                Transaction = { Destination = new List <ServerId>() }
            };

            ev.Transaction.StartTransaction();
            cache.AddToCache(ev.Transaction.CacheKey, ev.Transaction);
            ret = cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(ev.Transaction, ret);
            Thread.Sleep(200);
            cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(TransactionState.Error, ev.Transaction.State);
            Thread.Sleep(200);
            cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(TransactionState.Error, ev.Transaction.State);
            Thread.Sleep(500);
            ret = cache.Get(ev.Transaction.CacheKey);
            Assert.AreEqual(null, ret);
        }