public void WithTransaction()
        {

            const string notChanged = "Not Changed";
            const string changed = "Changed";
            var ne1 = new NotifiedElement { Key = Guid.NewGuid(), Name = notChanged};
            var une1 = new UnnotifiedElement { Key = Guid.NewGuid(), Name = notChanged };

            _level2Interaction.Post(ne1.Key, ne1);
            _level2Interaction.Post(une1.Key, une1);

            _level2Interaction.Subscribe();

         

            #region Start changing inside transaction.

            var notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew,TimeSpan.FromMinutes(10)))
                {
                    var resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);//just precaching to check cache state later
                    var resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);

                    _level1Interaction.Post(ne1.Key, new NotifiedElement { Key = ne1.Key, Name = changed }, Transaction.Current);//first time we'll explicitly set a transaction (propagation into foreign domain)

                    //No notifyings should arrive yet
                    notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
                    Assert.IsFalse(notifyings.Any());

                    //This time too. Actualy, this action will never send notifications... whatever
                    _level1Interaction.Post(une1.Key, new UnnotifiedElement { Key = une1.Key, Name = changed });
                    notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
                    Assert.IsFalse(notifyings.Any());

                    resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
                    resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
                    //the thing is,that due to lack of notification, 2-level cache should remain untouched...
                    Assert.AreEqual(notChanged, resne.Name);
                    Assert.AreEqual(notChanged, resune.Name);

                    //but 1-level doesn't, 'cause local storage unactualities are not affected by transactions
                    resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
                    resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
                    Assert.AreEqual(changed, resne.Name);
                    Assert.AreEqual(changed, resune.Name);
                    _level1Interaction.Complete();
                    scope.Complete();
                }
            }
            catch (TransactionAbortedException)//по невыясненным мной точно причинам транзакция рушится. Скорее всего, передача транзакции в другой домен ее продвигает, а текущая реализация тестов явно некорректна для продвигаемой транзакции
            {

            }

            #endregion  
        }
Beispiel #2
0
        public void WithTransaction()
        {
            const string notChanged = "Not Changed";
            const string changed    = "Changed";
            var          ne1        = new NotifiedElement {
                Key = Guid.NewGuid(), Name = notChanged
            };
            var une1 = new UnnotifiedElement {
                Key = Guid.NewGuid(), Name = notChanged
            };

            _level2Interaction.Post(ne1.Key, ne1);
            _level2Interaction.Post(une1.Key, une1);

            _level2Interaction.Subscribe();



            #region Start changing inside transaction.

            var notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(10)))
                {
                    var resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);//just precaching to check cache state later
                    var resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);

                    _level1Interaction.Post(ne1.Key, new NotifiedElement {
                        Key = ne1.Key, Name = changed
                    }, Transaction.Current);                                                                                     //first time we'll explicitly set a transaction (propagation into foreign domain)

                    //No notifyings should arrive yet
                    notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
                    Assert.IsFalse(notifyings.Any());

                    //This time too. Actualy, this action will never send notifications... whatever
                    _level1Interaction.Post(une1.Key, new UnnotifiedElement {
                        Key = une1.Key, Name = changed
                    });
                    notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
                    Assert.IsFalse(notifyings.Any());

                    resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
                    resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
                    //the thing is,that due to lack of notification, 2-level cache should remain untouched...
                    Assert.AreEqual(notChanged, resne.Name);
                    Assert.AreEqual(notChanged, resune.Name);

                    //but 1-level doesn't, 'cause local storage unactualities are not affected by transactions
                    resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
                    resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
                    Assert.AreEqual(changed, resne.Name);
                    Assert.AreEqual(changed, resune.Name);
                    _level1Interaction.Complete();
                    scope.Complete();
                }
            }
            catch (TransactionAbortedException)//по невыясненным мной точно причинам транзакция рушится. Скорее всего, передача транзакции в другой домен ее продвигает, а текущая реализация тестов явно некорректна для продвигаемой транзакции
            {
            }

            #endregion
        }
Beispiel #3
0
        public void NoTransaction()
        {
            Settings.NoCacheGarbageChecking = true;
            const string notChanged = "Not Changed"; 
            const string changed = "Changed";
           
            var ne1 = new NotifiedElement { Key = Guid.NewGuid(), Name = "" };
            var une1 = new UnnotifiedElement { Key = Guid.NewGuid(), Name = "" };
            _level2Interaction.Post(ne1.Key,ne1);
            _level2Interaction.Post(une1.Key,une1);

            #region Transfer correctness check
            var resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            var resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(ne1.Name,resne.Name);
            Assert.AreEqual(une1.Name, resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(ne1.Name, resne.Name);
            Assert.AreEqual(une1.Name, resune.Name);
            #endregion

            #region Than check, that no changes are coming back to level 2 yet
            _level1Interaction.Post(ne1.Key, new NotifiedElement{Key = ne1.Key,Name = notChanged});
            _level1Interaction.Post(une1.Key, new UnnotifiedElement { Key = une1.Key, Name = notChanged });

            resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual("", resne.Name);
            Assert.AreEqual("", resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);
            var notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());

            #endregion

            _level2Interaction.Post(ne1.Key, new NotifiedElement { Key = ne1.Key, Name = notChanged });
            _level2Interaction.Post(une1.Key, new UnnotifiedElement { Key = une1.Key, Name = notChanged });
            _level2Interaction.Subscribe();

            #region Checking results after subscription and preparing for change tracking
            resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);
            #endregion


            _level1Interaction.Post(ne1.Key, new NotifiedElement { Key = ne1.Key, Name = changed });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement { Key = une1.Key, Name = changed });

            #region Checking results after changing. Unnotifing element on level 2 should remain unchanged. Token should return event
            resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(changed, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.AreEqual(1,notifyings.Count());
            Assert.AreEqual("NotifiedElement",notifyings.First().ResourceName);
            Assert.AreEqual(resne.Key, notifyings.First().ResourceKey);
            #endregion

            _level2Interaction.Unsubscribe();

            #region Checking results after unsubscribing. Everything should be the same.
            resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(changed, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            #endregion

            _level1Interaction.Post(ne1.Key, new NotifiedElement { Key = ne1.Key, Name = notChanged });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement { Key = une1.Key, Name = notChanged });


            #region Checking results first time. Update for notifying element will arrive, because the were alive subscription. But due to token unsubscription, we should not have event of unactuality.
            resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            #endregion

            _level1Interaction.Post(ne1.Key, new NotifiedElement { Key = ne1.Key, Name = changed });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement { Key = une1.Key, Name = changed });

            #region But this time subscription should go away. 
            resne = _level2Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne = _level1Interaction.Get<NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get<UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(changed, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            #endregion
        }
Beispiel #4
0
        public void NoTransaction()
        {
            Settings.NoCacheGarbageChecking = true;
            const string notChanged = "Not Changed";
            const string changed    = "Changed";

            var ne1 = new NotifiedElement {
                Key = Guid.NewGuid(), Name = ""
            };
            var une1 = new UnnotifiedElement {
                Key = Guid.NewGuid(), Name = ""
            };

            _level2Interaction.Post(ne1.Key, ne1);
            _level2Interaction.Post(une1.Key, une1);

            #region Transfer correctness check
            var resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            var resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(ne1.Name, resne.Name);
            Assert.AreEqual(une1.Name, resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(ne1.Name, resne.Name);
            Assert.AreEqual(une1.Name, resune.Name);
            #endregion

            #region Than check, that no changes are coming back to level 2 yet
            _level1Interaction.Post(ne1.Key, new NotifiedElement {
                Key = ne1.Key, Name = notChanged
            });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement {
                Key = une1.Key, Name = notChanged
            });

            resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual("", resne.Name);
            Assert.AreEqual("", resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);
            var notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());

            #endregion

            _level2Interaction.Post(ne1.Key, new NotifiedElement {
                Key = ne1.Key, Name = notChanged
            });
            _level2Interaction.Post(une1.Key, new UnnotifiedElement {
                Key = une1.Key, Name = notChanged
            });
            _level2Interaction.Subscribe();

            #region Checking results after subscription and preparing for change tracking
            resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);
            #endregion


            _level1Interaction.Post(ne1.Key, new NotifiedElement {
                Key = ne1.Key, Name = changed
            });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement {
                Key = une1.Key, Name = changed
            });

            #region Checking results after changing. Unnotifing element on level 2 should remain unchanged. Token should return event
            resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(changed, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.AreEqual(1, notifyings.Count());
            Assert.AreEqual("NotifiedElement", notifyings.First().ResourceName);
            Assert.AreEqual(resne.Key, notifyings.First().ResourceKey);
            #endregion

            _level2Interaction.Unsubscribe();

            #region Checking results after unsubscribing. Everything should be the same.
            resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(changed, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            #endregion

            _level1Interaction.Post(ne1.Key, new NotifiedElement {
                Key = ne1.Key, Name = notChanged
            });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement {
                Key = une1.Key, Name = notChanged
            });


            #region Checking results first time. Update for notifying element will arrive, because the were alive subscription. But due to token unsubscription, we should not have event of unactuality.
            resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            #endregion

            _level1Interaction.Post(ne1.Key, new NotifiedElement {
                Key = ne1.Key, Name = changed
            });
            _level1Interaction.Post(une1.Key, new UnnotifiedElement {
                Key = une1.Key, Name = changed
            });

            #region But this time subscription should go away.
            resne  = _level2Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level2Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(notChanged, resne.Name);
            Assert.AreEqual(notChanged, resune.Name);

            resne  = _level1Interaction.Get <NotifiedElement>(ne1.Key);
            resune = _level1Interaction.Get <UnnotifiedElement>(une1.Key);
            Assert.AreEqual(changed, resne.Name);
            Assert.AreEqual(changed, resune.Name);

            notifyings = _level2Interaction.CheckSubscriptionCameFromLastCheck();
            Assert.IsFalse(notifyings.Any());
            #endregion
        }