Ejemplo n.º 1
0
        public void ExplicitTransaction1()
        {
            Assert.Null(Transaction.Current);
            CommittableTransaction ct = new CommittableTransaction();
            Transaction oldTransaction = Transaction.Current;

            Transaction.Current = ct;
            try
            {
                IntResourceManager irm = new IntResourceManager(1);

                irm.Value = 2;

                using (TransactionScope scope = new TransactionScope())
                {
                    Assert.Equal(ct, Transaction.Current);
                    irm.Value = 4;
                    scope.Complete();
                }

                Assert.Equal(ct, Transaction.Current);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);
                Assert.Equal(1, irm.Actual);

                ct.Commit();
                Assert.Equal(4, irm.Actual);
                Assert.Equal(TransactionStatus.Committed, Transaction.Current.TransactionInformation.Status);
            }
            finally
            {
                Transaction.Current = oldTransaction;
            }
        }
Ejemplo n.º 2
0
        public void Vol1_Dur0_2PC()
        {
            IntResourceManager irm = new IntResourceManager(1);

            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                scope.Complete();
            }
            irm.Check2PC("irm");
        }
Ejemplo n.º 3
0
        public void Vol1_Dur0_Fail1()
        {
            IntResourceManager irm = new IntResourceManager(1);
            irm.UseSingle = true;
            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                /* Not completing this..
				scope.Complete ();*/
            }

            irm.Check(0, 0, 0, 1, 0, 0, 0, "irm");
        }
Ejemplo n.º 4
0
        public void TransactionScopeAbort()
        {
            Assert.Null(Transaction.Current);
            IntResourceManager irm = new IntResourceManager(1);
            using (TransactionScope scope = new TransactionScope())
            {
                Assert.NotNull(Transaction.Current);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                irm.Value = 2;
                /* Not completing scope here */
            }
            irm.Check(0, 0, 1, 0, "irm");
            Assert.Equal(1, irm.Value);
            Assert.Null(Transaction.Current);
        }
Ejemplo n.º 5
0
        public void Vol1_Dur0_Fail3()
        {
            Assert.Throws<TransactionAbortedException>(() =>
            {
                IntResourceManager irm = new IntResourceManager(1);
                irm.UseSingle = true;
                irm.FailSPC = true;

                using (TransactionScope scope = new TransactionScope())
                {
                    irm.Value = 2;

                    scope.Complete();
                }
            });
        }
Ejemplo n.º 6
0
        public void AsyncFail1()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                IntResourceManager irm = new IntResourceManager(1);

                CommittableTransaction ct = new CommittableTransaction();
                /* Set ambient Tx */
                Transaction.Current = ct;

                /* Enlist */
                irm.Value = 2;

                IAsyncResult ar = ct.BeginCommit(null, null);
                IAsyncResult ar2 = ct.BeginCommit(null, null);
            });
        }
Ejemplo n.º 7
0
        public void AsyncFail2()
        {
            Assert.Throws<TransactionAbortedException>(() =>
            {
                IntResourceManager irm = new IntResourceManager(1);

                CommittableTransaction ct = new CommittableTransaction();
                /* Set ambient Tx */
                Transaction.Current = ct;

                /* Enlist */
                irm.Value = 2;
                irm.FailPrepare = true;

                IAsyncResult ar = ct.BeginCommit(null, null);

                ct.EndCommit(ar);
            });
        }
Ejemplo n.º 8
0
        public void ExplicitTransaction10()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);
            Transaction.Current = ct;
            try
            {
                irm.Value = 2;

                TransactionScope scope = new TransactionScope(ct);
                Assert.Equal(ct, Transaction.Current);
                Assert.Throws<TransactionAbortedException>(() => ct.Commit());
                irm.Check(0, 0, 1, 0, "irm");
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Ejemplo n.º 9
0
        public void Vol2_Throwing_On_Commit()
        {
            bool      called = false;
            Exception ex     = null;
            var       rm1    = new IntResourceManager(1)
            {
                FailCommit         = true,
                FailWithException  = true,
                ThrowThisException = new InvalidOperationException("rm1"),
                Type = ResourceManagerType.Volatile
            };
            var rm2 = new IntResourceManager(2)
            {
                Type = ResourceManagerType.Volatile
            };

            try
            {
                using (var ts = new TransactionScope())
                {
                    rm1.Value = 11;
                    rm2.Value = 22;

                    var tr = Transaction.Current;
                    tr.TransactionCompleted += (s, e) => called = true;
                    ts.Complete();
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }

            rm1.Check(0, 1, 1, 0, 0, 0, 0, "rm1");
            rm2.Check(0, 1, 0, 0, 0, 0, 0, "rm2");

            // MS.NET won't call TransactionCompleted event in this particular case.
            Assert.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.NotNull(ex);
            Assert.Equal(rm1.ThrowThisException, ex);
        }
Ejemplo n.º 10
0
        public void Vol1_Committed()
        {
            bool called = false;
            TransactionStatus status = TransactionStatus.Active;
            var rm = new IntResourceManager(1)
            {
                Type = ResourceManagerType.Volatile,
            };

            using (var ts = new TransactionScope())
            {
                rm.Value = 2;
                var tr = Transaction.Current;
                tr.TransactionCompleted += (s, e) => { called = true; status = e.Transaction.TransactionInformation.Status; };
                ts.Complete();
            }

            rm.Check(0, 1, 1, 0, 0, 0, 0, "rm");
            Assert.True(called, "TransactionCompleted event handler not called!");
            Assert.Equal(TransactionStatus.Committed, status);
        }
Ejemplo n.º 11
0
        public void ExplicitTransaction14()
        {
            CommittableTransaction ct  = new CommittableTransaction();
            IntResourceManager     irm = new IntResourceManager(1);

            Assert.Null(Transaction.Current);
            Transaction.Current = ct;
            try
            {
                irm.Value = 2;

                ct.Commit();

                Assert.Equal(TransactionStatus.Committed, ct.TransactionInformation.Status);
                Assert.Throws <InvalidOperationException>(() => ct.BeginCommit(null, null));
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Ejemplo n.º 12
0
        public void ExplicitTransaction10()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;
            try
            {
                irm.Value = 2;

                TransactionScope scope = new TransactionScope(ct);
                Assert.Equal(ct, Transaction.Current);
                Assert.Throws <TransactionAbortedException>(() => ct.Commit());
                irm.Check(0, 0, 1, 0, "irm");
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Ejemplo n.º 13
0
        public void Vol0_Dur1_Fail()
        {
            IntResourceManager irm = new IntResourceManager(1);

            /* Durable resource enlisted with a IEnlistedNotification
             * object
             */
            irm.Type      = ResourceManagerType.Durable;
            irm.FailSPC   = true;
            irm.UseSingle = true;
            Assert.Throws <TransactionAbortedException>(() =>
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm.Value = 2;

                    scope.Complete();
                }
            });
            irm.Check(1, 0, 0, 0, 0, 0, 0, "irm");
        }
Ejemplo n.º 14
0
        public void Vol2_Dur1_Fail3()
        {
            IntResourceManager[] irm = new IntResourceManager[4];
            irm[0] = new IntResourceManager(1);
            irm[1] = new IntResourceManager(3);
            irm[2] = new IntResourceManager(5);
            irm[3] = new IntResourceManager(7);

            irm[0].Type        = ResourceManagerType.Durable;
            irm[2].FailPrepare = true;

            for (int i = 0; i < 4; i++)
            {
                irm[i].UseSingle = true;
            }

            /* Durable RM irm[2] does on SPC, so
             * all volatile RMs get Rollback */
            Assert.Throws <TransactionAbortedException>(() =>
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm[0].Value = 2;
                    irm[1].Value = 6;
                    irm[2].Value = 10;
                    irm[3].Value = 14;

                    scope.Complete();
                }
            });
            irm[0].Check(0, 0, 0, 1, 0, 0, 0, "irm [0]");

            /* irm [1] & [2] get prepare,
             * [2] -> ForceRollback,
             * [1] & [3] get rollback,
             * [0](durable) gets rollback */
            irm[1].Check(0, 1, 0, 1, 0, 0, 0, "irm [1]");
            irm[2].Check(0, 1, 0, 0, 0, 0, 0, "irm [2]");
            irm[3].Check(0, 0, 0, 1, 0, 0, 0, "irm [3]");
        }
Ejemplo n.º 15
0
        public void Vol0_Dur2()
        {
            IntResourceManager[] irm = new IntResourceManager[2];
            irm[0] = new IntResourceManager(1);
            irm[1] = new IntResourceManager(3);

            irm[0].Type = ResourceManagerType.Durable;
            irm[1].Type = ResourceManagerType.Durable;

            for (int i = 0; i < 2; i++)
            {
                irm[i].UseSingle = true;
            }

            using (TransactionScope scope = new TransactionScope())
            {
                irm[0].Value = 2;
                irm[1].Value = 6;

                scope.Complete();
            }
        }
Ejemplo n.º 16
0
        public void ExplicitTransaction6e()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;
            try
            {
                TransactionScope scope1 = new TransactionScope();
                /* Enlist */
                irm.Value = 2;

                TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress);
                Assert.Throws <InvalidOperationException>(() => scope1.Dispose());
                scope2.Dispose();
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Ejemplo n.º 17
0
        public void ExplicitTransactionRollback()
        {
            Assert.Null(Transaction.Current);

            CommittableTransaction ct             = new CommittableTransaction();
            Transaction            oldTransaction = Transaction.Current;

            Transaction.Current = ct;
            try
            {
                IntResourceManager irm = new IntResourceManager(1);
                irm.Value = 2;
                Assert.Equal(TransactionStatus.Active, ct.TransactionInformation.Status);
                ct.Rollback();

                Assert.Equal(1, irm.Value);
                Assert.Equal(TransactionStatus.Aborted, ct.TransactionInformation.Status);
            }
            finally
            {
                Transaction.Current = oldTransaction;
            }
        }
Ejemplo n.º 18
0
        public void Async5()
        {
            IntResourceManager irm = new IntResourceManager(1);

            CommittableTransaction ct = new CommittableTransaction();

            /* Set ambient Tx */
            Transaction.Current = ct;

            /* Enlist */
            irm.Value       = 2;
            irm.FailPrepare = true;

            IAsyncResult ar = ct.BeginCommit(null, null);

            ar.AsyncWaitHandle.WaitOne();
            Assert.True(ar.IsCompleted);

            CommittableTransaction ctx = ar as CommittableTransaction;

            Assert.Throws <TransactionAbortedException>(() => ctx.EndCommit(ar));
            irm.Check(1, 0, 0, 0, "irm");
        }
Ejemplo n.º 19
0
        public void Vol2_Dur1_Fail5()
        {
            CommittableTransaction ct = new CommittableTransaction();
            IntResourceManager[] irm = new IntResourceManager[2];
            irm[0] = new IntResourceManager(1);
            irm[1] = new IntResourceManager(3);

            Transaction.Current = ct;
            irm[0].Type = ResourceManagerType.Durable;
            irm[0].FailSPC = true;
            irm[0].FailWithException = true;

            for (int i = 0; i < 2; i++)
                irm[i].UseSingle = true;

            /* Durable RM irm[2] does on SPC, so
             * all volatile RMs get Rollback */

            using (TransactionScope scope = new TransactionScope())
            {
                irm[0].Value = 2;
                irm[1].Value = 6;

                scope.Complete();
            }

            TransactionAbortedException tae = Assert.Throws<TransactionAbortedException>(() => ct.Commit());
            Assert.IsType<NotSupportedException>(tae.InnerException);

            irm[0].Check(1, 0, 0, 0, 0, 0, 0, "irm [0]");
            irm[1].Check(0, 1, 0, 1, 0, 0, 0, "irm [1]");

            InvalidOperationException ioe = Assert.Throws<InvalidOperationException>(() => ct.Commit());
            Assert.Null(ioe.InnerException);

            Transaction.Current = null;
        }
Ejemplo n.º 20
0
        public void Vol1SPC_Throwing_On_Commit()
        {
            bool              called = false;
            Exception         ex     = null;
            TransactionStatus status = TransactionStatus.Active;
            var rm = new IntResourceManager(1)
            {
                UseSingle         = true,
                FailSPC           = true,
                FailWithException = true,
                Type = ResourceManagerType.Volatile
            };

            try
            {
                using (var ts = new TransactionScope())
                {
                    rm.Value = 2;
                    var tr = Transaction.Current;
                    tr.TransactionCompleted += (s, e) => { called = true; status = e.Transaction.TransactionInformation.Status; };
                    ts.Complete();
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }

            rm.Check(1, 0, 0, 0, 0, 0, 0, "rm");

            Assert.True(called, "TransactionCompleted event handler not called!");
            Assert.Equal(TransactionStatus.Aborted, status);
            Assert.NotNull(ex);
            Assert.IsType <TransactionAbortedException>(ex);
            Assert.NotNull(ex.InnerException);
            Assert.IsType <NotSupportedException>(ex.InnerException);
        }
Ejemplo n.º 21
0
        public void NestedTransactionScope9()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    /* Not transactional, so this WON'T get committed */
                    irm2.Value = 4;
                    scope2.Complete();
                }
                irm2.Check(0, 0, 0, 0, "irm2");

                using (TransactionScope scope3 = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    irm.Value = 6;
                    scope3.Complete();
                }

                /* vr's value has changed as the inner scope committed = 6 */
                irm.Check(1, 1, 0, 0, "irm");
                Assert.Equal(6, irm.Value);
                Assert.Equal(6, irm.Actual);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(6, irm.Value);
            irm.Check(2, 2, 0, 0, "irm");
        }
Ejemplo n.º 22
0
        public void Vol2_Dur1_Fail1()
        {
            IntResourceManager[] irm = new IntResourceManager[4];
            irm[0] = new IntResourceManager(1);
            irm[1] = new IntResourceManager(3);
            irm[2] = new IntResourceManager(5);
            irm[3] = new IntResourceManager(7);

            irm[0].Type    = ResourceManagerType.Durable;
            irm[0].FailSPC = true;

            for (int i = 0; i < 4; i++)
            {
                irm[i].UseSingle = true;
            }

            /* Durable RM irm[0] does Abort on SPC, so
             * all volatile RMs get Rollback */
            Assert.Throws <TransactionAbortedException>(() =>
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm[0].Value = 2;
                    irm[1].Value = 6;
                    irm[2].Value = 10;
                    irm[3].Value = 14;

                    scope.Complete();
                }
            });
            irm[0].CheckSPC("irm [0]");
            /* Volatile RMs get 2PC Prepare, and then get rolled back */
            for (int i = 1; i < 4; i++)
            {
                irm[i].Check(0, 1, 0, 1, 0, 0, 0, "irm [" + i + "]");
            }
        }
Ejemplo n.º 23
0
        public void AsyncFail3()
        {
            s_delayedException = null;
            IntResourceManager irm = new IntResourceManager(1);

            CommittableTransaction ct = new CommittableTransaction();

            /* Set ambient Tx */
            Transaction.Current = ct;

            /* Enlist */
            irm.Value       = 2;
            irm.FailPrepare = true;

            _callback = new AsyncCallback(CommitCallback);
            IAsyncResult ar = ct.BeginCommit(_callback, 5);

            s_mr.WaitOne(new TimeSpan(0, 0, 60));

            Assert.True(s_called, "callback not called");
            Assert.Equal(5, s_state);

            Assert.IsType <TransactionAbortedException>(s_delayedException);
        }
Ejemplo n.º 24
0
        public void Async1()
        {
            IntResourceManager irm = new IntResourceManager(1);

            CommittableTransaction ct = new CommittableTransaction();

            /* Set ambient Tx */
            Transaction.Current = ct;
            /* Enlist */
            irm.Value = 2;

            _callback = new AsyncCallback(CommitCallback);
            IAsyncResult ar = ct.BeginCommit(_callback, 5);

            s_mr.WaitOne(new TimeSpan(0, 2, 0));

            Assert.True(s_called, "callback not called");
            Assert.Equal(5, s_state);

            if (s_delayedException != null)
            {
                throw new Exception("", s_delayedException);
            }
        }
Ejemplo n.º 25
0
        public void NestedTransactionScope13()
        {
            Assert.Throws <TransactionAbortedException>(() =>
            {
                IntResourceManager irm = new IntResourceManager(1);

                Assert.Null(Transaction.Current);
                using (TransactionScope scope = new TransactionScope())
                {
                    irm.Value = 2;

                    using (TransactionScope scope2 = new TransactionScope())
                    {
                        irm.Value = 4;

                        /* Not completing this, so the transaction will
                         * get aborted
                         * scope2.Complete (); */
                    }

                    scope.Complete();
                }
            });
        }
Ejemplo n.º 26
0
        public void NestedTransactionScope12()
        {
            IntResourceManager irm = new IntResourceManager(1);

            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope())
                {
                    irm.Value = 4;
                    /* Not completing this, so the transaction will
					 * get aborted 
					scope2.Complete (); */
                }

                using (TransactionScope scope3 = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    /* Using RequiresNew here, so outer transaction
					 * being aborted doesn't matter
					 */
                    scope3.Complete();
                }
            }
        }
Ejemplo n.º 27
0
        public void ExplicitTransactionRollback()
        {
            Assert.Null(Transaction.Current);

            CommittableTransaction ct = new CommittableTransaction();
            Transaction oldTransaction = Transaction.Current;
            Transaction.Current = ct;
            try
            {
                IntResourceManager irm = new IntResourceManager(1);
                irm.Value = 2;
                Assert.Equal(TransactionStatus.Active, ct.TransactionInformation.Status);
                ct.Rollback();

                Assert.Equal(1, irm.Value);
                Assert.Equal(TransactionStatus.Aborted, ct.TransactionInformation.Status);
            }
            finally
            {
                Transaction.Current = oldTransaction;
            }
        }
Ejemplo n.º 28
0
        public void NestedTransactionScope13()
        {
            Assert.Throws<TransactionAbortedException>(() =>
           {
               IntResourceManager irm = new IntResourceManager(1);

               Assert.Null(Transaction.Current);
               using (TransactionScope scope = new TransactionScope())
               {
                   irm.Value = 2;

                   using (TransactionScope scope2 = new TransactionScope())
                   {
                       irm.Value = 4;
                       /* Not completing this, so the transaction will
                        * get aborted 
                       scope2.Complete (); */
                   }

                   scope.Complete();
               }
           });
        }
Ejemplo n.º 29
0
        public void ExplicitTransaction12()
        {
            Assert.Throws<ArgumentException>(() =>
            {
                CommittableTransaction ct = new CommittableTransaction();

                IntResourceManager irm = new IntResourceManager(1);
                irm.FailPrepare = true;
                ct.BeginCommit(null, null);
                ct.EndCommit(null);
            });
        }
Ejemplo n.º 30
0
        public void RMFail1()
        {
            IntResourceManager irm = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);
            IntResourceManager irm3 = new IntResourceManager(12);

            Assert.Null(Transaction.Current);
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm.Value = 2;
                    irm2.Value = 20;
                    irm3.Value = 24;

                    /* Make second RM fail to prepare, this should throw
					 * TransactionAbortedException when the scope ends 
					 */
                    irm2.FailPrepare = true;
                    scope.Complete();
                }
            }
            catch (TransactionAbortedException)
            {
                irm.Check(1, 0, 1, 0, "irm");
                irm2.Check(1, 0, 0, 0, "irm2");
                irm3.Check(0, 0, 1, 0, "irm3");
            }
            Assert.Null(Transaction.Current);
        }
 public PromotableSinglePhaseNotification(IntResourceManager resource)
     : base(resource)
 {
 }
 public EnlistmentNotification(IntResourceManager resource)
 {
     this.resource = resource;
 }
Ejemplo n.º 33
0
        public void ExplicitTransaction7()
        {
            Assert.Throws<TransactionException>(() =>
            {
                CommittableTransaction ct = new CommittableTransaction();

                IntResourceManager irm = new IntResourceManager(1);
                irm.Value = 2;
                ct.Commit();
                /* Cannot accept any new work now, so TransactionException */
                ct.Rollback();
            });
        }
Ejemplo n.º 34
0
        public void ExplicitTransaction6e()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;
            try
            {
                TransactionScope scope1 = new TransactionScope();
                /* Enlist */
                irm.Value = 2;

                TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress);
                Assert.Throws<InvalidOperationException>(() => scope1.Dispose());
                scope2.Dispose();
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Ejemplo n.º 35
0
        public void ExplicitTransaction6b()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;
            try
            {
                TransactionScope scope1 = new TransactionScope();
                /* Enlist */
                irm.Value = 2;

                scope1.Complete();

                Assert.Throws<TransactionAbortedException>(() => ct.Commit());
                irm.Check(0, 0, 1, 0, "irm");

                scope1.Dispose();
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Ejemplo n.º 36
0
        public void ExplicitTransaction6a()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                CommittableTransaction ct = new CommittableTransaction();

                IntResourceManager irm = new IntResourceManager(1);
                irm.Value = 2;
                ct.Commit();

                /* Using a already committed transaction in a new 
                 * TransactionScope
                 */
                TransactionScope scope = new TransactionScope(ct);
            });
        }
Ejemplo n.º 37
0
        public void ExplicitTransaction6()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                CommittableTransaction ct = new CommittableTransaction();

                IntResourceManager irm = new IntResourceManager(1);
                irm.Value = 2;
                ct.Commit();

                ct.Commit();
            });
        }
Ejemplo n.º 38
0
        public void ExplicitTransaction5()
        {
            Assert.Null(Transaction.Current);
            CommittableTransaction ct = new CommittableTransaction();
            Transaction oldTransaction = Transaction.Current;

            /* Not setting ambient transaction 
			 Transaction.Current = ct; 
			 */

            IntResourceManager irm = new IntResourceManager(1);

            using (TransactionScope scope = new TransactionScope(ct))
            {
                Assert.Equal(ct, Transaction.Current);

                irm.Value = 2;

                /* Not completing this scope
				scope.Complete (); */
            }

            Assert.Equal(oldTransaction, Transaction.Current);
            Assert.Equal(TransactionStatus.Aborted, ct.TransactionInformation.Status);
            Assert.Equal(1, irm.Actual);

            irm.Check(0, 0, 1, 0, "irm");
        }
Ejemplo n.º 39
0
        public void NestedTransactionScope9()
        {
            IntResourceManager irm = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    /* Not transactional, so this WONT get committed */
                    irm2.Value = 4;
                    scope2.Complete();
                }
                irm2.Check(0, 0, 0, 0, "irm2");

                using (TransactionScope scope3 = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    irm.Value = 6;
                    scope3.Complete();
                }

                /* vr's value has changed as the inner scope committed = 6 */
                irm.Check(1, 1, 0, 0, "irm");
                Assert.Equal(irm.Value, 6);
                Assert.Equal(irm.Actual, 6);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(irm.Value, 6);
            irm.Check(2, 2, 0, 0, "irm");
        }
Ejemplo n.º 40
0
        public void NestedTransactionScope8a()
        {
            IntResourceManager irm = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope())
                {
                    irm2.Value = 20;
                    scope2.Complete();
                }
                irm2.Check(1, 1, 0, 0, "irm2");
                Assert.Equal(20, irm2.Value);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(2, irm.Value);
            irm.Check(0, 0, 0, 0, "irm");
        }
Ejemplo n.º 41
0
        public void ExplicitTransactionCommit()
        {
            Assert.Null(Transaction.Current);

            CommittableTransaction ct = new CommittableTransaction();
            Transaction oldTransaction = Transaction.Current;
            Transaction.Current = ct;

            IntResourceManager irm = new IntResourceManager(1);
            irm.Value = 2;
            ct.Commit();

            Assert.Equal(2, irm.Value);
            Assert.Equal(TransactionStatus.Committed, ct.TransactionInformation.Status);
            Transaction.Current = oldTransaction;
        }
Ejemplo n.º 42
0
        public void ExplicitTransaction8a()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);
            using (TransactionScope scope = new TransactionScope(ct))
            {
                irm.Value = 2;
                scope.Complete();
                Assert.Throws<TransactionAbortedException>(() => ct.Commit()); /* FIXME: Why TransactionAbortedException ?? */
                irm.Check(0, 0, 1, 0, "irm");
            }
        }
Ejemplo n.º 43
0
 public EnlistmentNotification(IntResourceManager resource)
 {
     this.resource = resource;
 }
Ejemplo n.º 44
0
        public void ExplicitTransaction9()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                CommittableTransaction ct = new CommittableTransaction();

                IntResourceManager irm = new IntResourceManager(1);
                ct.BeginCommit(null, null);
                ct.BeginCommit(null, null);
            });
        }
Ejemplo n.º 45
0
        public void NestedTransactionScope1()
        {
            IntResourceManager irm = new IntResourceManager(1);

            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                /* Complete this scope */
                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            /* Value = 2, got committed */
            Assert.Equal(irm.Value, 2);
            irm.Check(1, 1, 0, 0, "irm");
        }
Ejemplo n.º 46
0
        public void ExplicitTransaction2()
        {
            Assert.Null(Transaction.Current);
            CommittableTransaction ct = new CommittableTransaction();
            Transaction oldTransaction = Transaction.Current;

            Transaction.Current = ct;
            try
            {
                IntResourceManager irm = new IntResourceManager(1);

                irm.Value = 2;
                using (TransactionScope scope = new TransactionScope())
                {
                    Assert.Equal(ct, Transaction.Current);

                    /* Not calling scope.Complete
                    scope.Complete ();*/
                }

                Assert.Equal(TransactionStatus.Aborted, ct.TransactionInformation.Status);
                Assert.Equal(ct, Transaction.Current);
                Assert.Equal(1, irm.Actual);
                Assert.Equal(1, irm.NumRollback);
                irm.Check(0, 0, 1, 0, "irm");
            }
            finally
            {
                Transaction.Current = oldTransaction;
            }
            Assert.Throws<TransactionAbortedException>(() => ct.Commit());
        }
Ejemplo n.º 47
0
        [OuterLoop] // 30 second timeout
        public void RMFail2()
        {
            IntResourceManager irm = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);
            IntResourceManager irm3 = new IntResourceManager(12);

            Assert.Null(Transaction.Current);
            TransactionAbortedException e = Assert.Throws<TransactionAbortedException>(() =>
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 30)))
                {
                    irm.Value = 2;
                    irm2.Value = 20;
                    irm3.Value = 24;

                    /* irm2 wont call Prepared or ForceRollback in
					 * its Prepare (), so TransactionManager will timeout
					 * waiting for it 
					 */
                    irm2.IgnorePrepare = true;
                    scope.Complete();
                }
            });

            Assert.NotNull(e.InnerException);
            Assert.IsType<TimeoutException>(e.InnerException);
            Assert.Null(Transaction.Current);
        }
Ejemplo n.º 48
0
 public PromotableSinglePhaseNotification(IntResourceManager resource)
     : base(resource)
 {
 }
Ejemplo n.º 49
0
        public void ExplicitTransaction3()
        {
            Assert.Null(Transaction.Current);
            CommittableTransaction ct = new CommittableTransaction();
            Transaction oldTransaction = Transaction.Current;

            Transaction.Current = ct;
            try
            {
                IntResourceManager irm = new IntResourceManager(1);

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Assert.True(ct != Transaction.Current, "Scope with RequiresNew should have a new ambient transaction");

                    irm.Value = 3;
                    scope.Complete();
                }

                irm.Value = 2;

                Assert.Equal(3, irm.Actual);

                Assert.Equal(ct, Transaction.Current);
                ct.Commit();
                Assert.Equal(2, irm.Actual);
            }
            finally
            {
                Transaction.Current = oldTransaction;
            }
        }