Ejemplo n.º 1
0
        public void ProcessChangeSet_update_dirty_invokes_unsuccessful_merge_and_no_retry()
        {
            var repo = A.Fake<IRepository<Asset, int>>();
            var context = A.Fake<IDataContext>();
            var resolver = new RejectConcurrentEditsConflictResolver();
            var afim = A.Dummy<Models.Asset>();

            var cs = new ChangeSet()
            {
                Assets = new List<ChangeItem<Models.Asset>>{
                     new ChangeItem<Models.Asset>{
                         Action = ChangeAction.Update,
                         BFIM = A.Dummy<Models.Asset>(),
                         AFIM = afim
                     }
                 }
            };
            A.CallTo(() => repo.KeySelector).Returns((Asset a) => a.Id);
            A.CallTo(() => context.Assets).Returns(repo);
            A.CallTo(() => context.AcceptChanges()).Throws(new ConcurrencyException()).Once();

            var processor = new ChangeSetProcessor(context, resolver);
            var result = processor.Process(1, false, cs);

            Assert.IsFalse(result.IsEmpty);
            Assert.AreNotEqual(ChangeSet.Empty, result);
            A.CallTo(() => context.Assets.Update(afim)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => context.AcceptChanges()).MustHaveHappened(Repeated.Exactly.Once);
        }
Ejemplo n.º 2
0
        public void PCLock()
        {
            Exception ex = null;
            int jobId = 1;
            long flag = Interlocked.CompareExchange(ref s_flag, 1, 0);
            var un = "fixed_unique_name";
            if (flag == 1)
            {
                Concurrent();
                return;
            }

            try
            {

                using (var uc = new FakeUserContext(un))
                {
                    bool failed = false;
                    var resolver = new RejectConcurrentEditsConflictResolver();
                    try
                    {
                        s_pcAttempt.Increment();
                        Exec(jobId, 1, 1, resolver); // test can get the lock
                        s_pcAttemptSuccess.Increment();
                    }
                    catch (ConcurrencyException)
                    {

                    }
                    catch
                    {
                        failed = true;
                        return;
                    }

                    if (!failed)
                    {
                        try
                        {
                            s_pcPost.Increment();
                            Exec(jobId, 1, 0, resolver); // test can update after acquiring
                            s_pcPostSuccess.Increment();
                        }
                        catch (Exception e)
                        {
                            ex = e;
                        }
                    }

                }
            }
            finally
            {
                try
                {
                    EnsureJobIsNotLocked(1, ex, un);
                }
                finally
                {
                    Interlocked.Exchange(ref s_flag, 0);
                }
            }
        }