Example #1
0
        public void ExplicitTransaction6b()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;

            TransactionScope scope1 = new TransactionScope();

            /* Enlist */
            irm.Value = 2;

            scope1.Complete();

            try {
                ct.Commit();
            } catch (TransactionAbortedException) {
                irm.Check(0, 0, 1, 0, "irm");

                scope1.Dispose();
                Transaction.Current = null;
                return;
            }
            Assert.Fail("Commit should've failed");
        }
Example #2
0
        public void ExplicitTransaction4()
        {
            Assert.IsNull(Transaction.Current, "Ambient transaction exists (before)");
            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.AreEqual(ct, Transaction.Current, "#53");

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

            Assert.AreEqual(oldTransaction, Transaction.Current, "#54");
            Assert.AreEqual(TransactionStatus.Active, ct.TransactionInformation.Status, "#55");
            Assert.AreEqual(1, irm.Actual, "#56");              /* Actual value */

            ct.Commit();
            Assert.AreEqual(2, irm.Actual, "#57");              /* New committed actual value */
            Assert.AreEqual(TransactionStatus.Committed, ct.TransactionInformation.Status, "#58");

            irm.Check(1, 1, 0, 0, "irm");
        }
Example #3
0
        public void ExplicitTransaction5()
        {
            Assert.IsNull(Transaction.Current, "Ambient transaction exists (before)");
            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.AreEqual(ct, Transaction.Current, "#59");

                irm.Value = 2;

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

            Assert.AreEqual(oldTransaction, Transaction.Current, "#60");
            Assert.AreEqual(TransactionStatus.Aborted, ct.TransactionInformation.Status, "#61");
            Assert.AreEqual(1, irm.Actual, "#62");              /* Actual value */

            irm.Check(0, 0, 1, 0, "irm");
        }
Example #4
0
        public void RMFail1()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);
            IntResourceManager irm3 = new IntResourceManager(12);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists (before)");
            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.IsNull(Transaction.Current, "Ambient transaction exists (after)");
        }
Example #5
0
        public void ExplicitTransaction2()
        {
            Assert.IsNull(Transaction.Current, "Ambient transaction exists (before)");
            CommittableTransaction ct             = new CommittableTransaction();
            Transaction            oldTransaction = Transaction.Current;

            Transaction.Current = ct;

            IntResourceManager irm = new IntResourceManager(1);

            irm.Value = 2;
            using (TransactionScope scope = new TransactionScope()) {
                Assert.AreEqual(ct, Transaction.Current, "#44");

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

            Assert.AreEqual(TransactionStatus.Aborted, ct.TransactionInformation.Status, "#45");
            Assert.AreEqual(ct, Transaction.Current, "#46");
            Assert.AreEqual(1, irm.Actual, "#47");
            Assert.AreEqual(1, irm.NumRollback, "#48");
            irm.Check(0, 0, 1, 0, "irm");
            Transaction.Current = oldTransaction;

            try {
                ct.Commit();
            } catch (TransactionAbortedException) {
                return;
            }
            Assert.Fail("Commit on an aborted transaction should fail");
        }
        public void NestedTransactionScope8a()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            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.AreEqual(20, irm2.Value, "#16a");

                scope.Complete();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            Assert.AreEqual(2, irm.Value, "#18a");
            irm.Check(0, 0, 0, 0, "irm");
        }
Example #7
0
        public void NestedTransactionScope9()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists (before)");
            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.AreEqual(irm.Value, 6, "#19");
                Assert.AreEqual(irm.Actual, 6, "#20");
                Assert.AreEqual(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "#21");

                scope.Complete();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists (after)");
            Assert.AreEqual(irm.Value, 6, "#22");
            irm.Check(2, 2, 0, 0, "irm");
        }
Example #8
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.IsTrue(ar.IsCompleted);
            try {
                CommittableTransaction ctx = ar as CommittableTransaction;
                ctx.EndCommit(ar);
            } catch (TransactionAbortedException) {
                irm.Check(1, 0, 0, 0, "irm");
                return;
            }

            Assert.Fail("EndCommit should've failed");
        }
        public void ExplicitTransaction15()
        {
            CommittableTransaction ct   = new CommittableTransaction();
            IntResourceManager     irm  = new IntResourceManager(1);
            IntResourceManager     irm2 = new IntResourceManager(3);

            Assert.IsNull(Transaction.Current);
            Transaction.Current = ct;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm.Value           = 2;
                    Transaction.Current = new CommittableTransaction();
                    irm2.Value          = 6;
                }
            }
            catch (InvalidOperationException)
            {
                irm.Check(0, 0, 1, 0, "irm");
                irm2.Check(0, 0, 1, 0, "irm2");
                Transaction.Current = null;
                return;
            }

            Assert.Fail("Should not be reached");
        }
Example #10
0
        public void Vol2_Rollback()
        {
            TransactionStatus status = TransactionStatus.Active;
            bool called = false;
            var  rm1    = new IntResourceManager(1)
            {
                Type = ResourceManagerType.Volatile
            };
            var rm2 = new IntResourceManager(1)
            {
                Type = ResourceManagerType.Volatile
            };

            using (var ts = new TransactionScope())
            {
                rm1.Value = 11;
                rm2.Value = 22;
                var tr = Transaction.Current;
                tr.TransactionCompleted += (s, e) => { called = true; status = e.Transaction.TransactionInformation.Status; };
                // Not calling ts.Complete() on purpose..
            }

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

            Assert.IsTrue(called, "TransactionCompleted event handler not called!");
            Assert.AreEqual(TransactionStatus.Aborted, status, "TransactionStatus != Aborted");
        }
Example #11
0
        public void Vol2SPC_Committed()
        {
            TransactionStatus status = TransactionStatus.Active;
            bool called = false;
            var  rm1    = new IntResourceManager(1)
            {
                UseSingle = true,
                Type      = ResourceManagerType.Volatile
            };
            var rm2 = new IntResourceManager(2)
            {
                UseSingle = true,
                Type      = ResourceManagerType.Volatile
            };

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

            // There can be only one *Single* PC enlistment,
            // so TM will downgrade both to normal enlistments.
            rm1.Check(0, 1, 1, 0, 0, 0, 0, "rm1");
            rm2.Check(0, 1, 1, 0, 0, 0, 0, "rm2");

            Assert.IsTrue(called, "TransactionCompleted event handler not called!");
            Assert.AreEqual(TransactionStatus.Committed, status, "TransactionStatus != Committed");
        }
Example #12
0
        public void Vol1_Throwing_On_Rollback()
        {
            bool called = false;
            TransactionStatus status = TransactionStatus.Active;
            Exception         ex     = null;
            var rm = new IntResourceManager(1)
            {
                FailRollback      = 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; };
                    // Not calling ts.Complete() on purpose..
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }

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

            // MS.NET wont call TransactionCompleted event in this particular case.
            Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.IsNotNull(ex, "Exception not thrown");
            // MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
            Assert.That(ex, InstanceOf(typeof(NotSupportedException)), "Invalid exception thrown");
        }
Example #13
0
        public void ExplicitTransaction6c()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;

            TransactionScope scope1 = new TransactionScope(TransactionScopeOption.RequiresNew);

            /* Enlist */
            irm.Value = 2;

            TransactionScope scope2 = new TransactionScope();

            try {
                scope1.Dispose();
            } catch (InvalidOperationException) {
                /* Error: TransactionScope nested incorrectly */
                irm.Check(0, 0, 1, 0, "irm");
                scope2.Dispose();
                Transaction.Current = null;
                return;
            }

            Assert.Fail("Commit should've failed");
        }
Example #14
0
        public void ExplicitTransaction10b()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            Transaction.Current = ct;
            irm.Value           = 2;
            Transaction.Current = null;

            TransactionScope scope = new TransactionScope(ct);

            Assert.AreEqual(ct, Transaction.Current, "ambient transaction");
            //scope2.Complete ();
            //scope2.Dispose ();
            IAsyncResult ar = ct.BeginCommit(null, null);

            try {
                ct.EndCommit(ar);
            }
            catch (TransactionAbortedException) {
                irm.Check(0, 0, 1, 0, "irm");
                Transaction.Current = null;
                return;
            }

            Transaction.Current = null;
            Assert.Fail();
        }
Example #15
0
        public void Async2()
        {
            IntResourceManager irm = new IntResourceManager(1);

            CommittableTransaction ct = new CommittableTransaction();

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

                //scope.Complete ();

                IAsyncResult ar = ct.BeginCommit(null, null);
                try
                {
                    ct.EndCommit(ar);
                }
                catch (TransactionAbortedException)
                {
                    irm.Check(0, 0, 1, 0, "irm");
                    return;
                }
            }
            Assert.Fail("EndCommit should've thrown an exception");
        }
Example #16
0
        public void NestedTransactionScope7()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            using (TransactionScope scope = new TransactionScope()) {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.RequiresNew)) {
                    irm2.Value = 20;

                    /* Not completing
                     * scope2.Complete();*/
                }

                /* irm2, rolled back*/
                irm2.Check(0, 0, 1, 0, "irm2");
                Assert.AreEqual(irm2.Value, 10, "#13");

                Assert.AreEqual(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "#14");

                scope.Complete();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            /* ..But irm got committed */
            Assert.AreEqual(irm.Value, 2, "#15");
            irm.Check(1, 1, 0, 0, "irm");
        }
Example #17
0
        public void NestedTransactionScope8()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            using (TransactionScope scope = new TransactionScope()) {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress)) {
                    /* Not transactional, so this WONT get committed */
                    irm2.Value = 20;
                    scope2.Complete();
                }
                irm2.Check(0, 0, 0, 0, "irm2");
                Assert.AreEqual(20, irm2.Value, "#16");
                Assert.AreEqual(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "#17");

                scope.Complete();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            Assert.AreEqual(irm.Value, 2, "#18");
            irm.Check(1, 1, 0, 0, "irm");
        }
Example #18
0
        public void NestedTransactionScope5()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            using (TransactionScope scope = new TransactionScope()) {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope()) {
                    irm2.Value = 20;
                    scope2.Complete();
                }

                Assert.AreEqual(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "#8");

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

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");

            Assert.AreEqual(irm.Value, 1, "#9");
            Assert.AreEqual(irm2.Value, 10, "#10");
            irm.Check(0, 0, 1, 0, "irm");
            irm2.Check(0, 0, 1, 0, "irm2");
        }
Example #19
0
        public void NestedTransactionScope6()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            using (TransactionScope scope = new TransactionScope()) {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.RequiresNew)) {
                    irm2.Value = 20;
                    scope2.Complete();
                }
                /* vr2, committed */
                irm2.Check(1, 1, 0, 0, "irm2");
                Assert.AreEqual(irm2.Value, 20);

                Assert.AreEqual(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "#11");

                scope.Complete();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            Assert.AreEqual(irm.Value, 2, "#12");
            irm.Check(1, 1, 0, 0, "irm");
        }
Example #20
0
        public void NestedTransactionScope4()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            using (TransactionScope scope = new TransactionScope()) {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope()) {
                    irm2.Value = 20;

                    /* Inner Tx not completed, Tx should get rolled back */
                    //scope2.Complete();
                }
                /* Both rolledback */
                irm.Check(0, 0, 1, 0, "irm");
                irm2.Check(0, 0, 1, 0, "irm2");
                Assert.AreEqual(TransactionStatus.Aborted, Transaction.Current.TransactionInformation.Status, "#5");
                //scope.Complete ();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");

            Assert.AreEqual(irm.Value, 1, "#6");
            Assert.AreEqual(irm2.Value, 10, "#7");
            irm.Check(0, 0, 1, 0, "irm");
        }
Example #21
0
        public void NestedTransactionScope3()
        {
            IntResourceManager irm  = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(10);

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            using (TransactionScope scope = new TransactionScope()) {
                irm.Value = 2;

                using (TransactionScope scope2 = new TransactionScope()) {
                    irm2.Value = 20;

                    scope2.Complete();
                }

                scope.Complete();
            }

            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            /* Both got committed */
            Assert.AreEqual(irm.Value, 2, "#3");
            Assert.AreEqual(irm2.Value, 20, "#4");
            irm.Check(1, 1, 0, 0, "irm");
            irm2.Check(1, 1, 0, 0, "irm2");
        }
Example #22
0
        public void ExplicitTransaction16()
        {
            CommittableTransaction ct   = new CommittableTransaction();
            IntResourceManager     irm0 = new IntResourceManager(3);
            IntResourceManager     irm  = new IntResourceManager(1);

            Assert.IsNull(Transaction.Current);

            Transaction.Current = ct;

            irm.FailPrepare       = true;
            irm.FailWithException = true;
            irm.Value             = 2;
            irm0.Value            = 6;

            try {
                ct.Commit();
            } catch (TransactionAbortedException e) {
                Assert.IsNotNull(e.InnerException, "Expected an InnerException of type NotSupportedException");
                Assert.AreEqual(typeof(NotSupportedException), e.InnerException.GetType(), "Inner exception should be NotSupportedException");
                irm.Check(1, 0, 0, 0, "irm");
                irm0.Check(0, 0, 1, 0, "irm0");
                Transaction.Current = null;
                return;
            }

            Assert.Fail("Should not be reached");
        }
        public void Vol0_Dur1_Fail()
        {
            IntResourceManager irm = new IntResourceManager(1);

            /* Durable resource enlisted with a IEnlistedNotification
             * object
             */
            irm.Volatile  = false;
            irm.FailSPC   = true;
            irm.UseSingle = true;
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm.Value = 2;

                    scope.Complete();
                }
            }
            catch (TransactionAbortedException)
            {
                irm.Check(1, 0, 0, 0, 0, "irm");
                return;
            }

            Assert.Fail();
        }
Example #24
0
        public void TransactionDispose()
        {
            CommittableTransaction ct  = new CommittableTransaction();
            IntResourceManager     irm = new IntResourceManager(1);

            irm.Type = ResourceManagerType.Durable;

            ct.Dispose();
            irm.Check(0, 0, 0, 0, "Dispose transaction");
        }
Example #25
0
        public void TransactionDispose()
        {
            CommittableTransaction ct  = new CommittableTransaction();
            IntResourceManager     irm = new IntResourceManager(1);

            irm.Volatile = false;

            ct.Dispose();
            irm.Check(0, 0, 0, 0, "Dispose transaction");
        }
Example #26
0
        public void Vol2SPC_Throwing_On_Commit()
        {
            TransactionStatus status = TransactionStatus.Active;
            bool      called         = false;
            Exception ex             = null;
            var       rm1            = new IntResourceManager(1)
            {
                UseSingle          = true,
                FailCommit         = true,
                FailWithException  = true,
                ThrowThisException = new InvalidOperationException("rm1"),
                Type = ResourceManagerType.Volatile,
            };
            var rm2 = new IntResourceManager(2)
            {
                UseSingle = true,
                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; status = e.Transaction.TransactionInformation.Status; };
                    ts.Complete();
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }

            // There can be only one *Single* PC enlistment,
            // so TM will downgrade both to normal enlistments.
            rm1.Check(0, 1, 1, 0, 0, 0, 0, "rm1");
            rm2.Check(0, 1, 0, 0, 0, 0, 0, "rm2");

            // MS.NET wont call TransactionCompleted event in this particular case.
            Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.IsNotNull(ex, "Exception not thrown");
#if MS_EXCEPTIONS_BEHAVIOR
            // MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
            Assert.AreEqual(rm1.ThrowThisException, ex, "Exception does not come from the expected RM");
#else
            // Mono wrapps the exception into a TransactionAbortedException.
            Assert.IsInstanceOfType(typeof(TransactionAbortedException), ex, "Invalid type of exception thrown");
            Assert.IsNotNull(ex.InnerException, "InnerException not thrown");
            Assert.AreEqual(rm1.ThrowThisException, ex.InnerException, "Exception does not come from the expected RM \n Ex: {0}", ex);
#endif
        }
Example #27
0
        public void Vol2_Throwing_On_First_Rollback_And_Second_Prepare()
        {
            TransactionStatus status = TransactionStatus.Active;
            bool      called         = false;
            Exception ex             = null;
            var       rm1            = new IntResourceManager(1)
            {
                FailRollback       = true,
                FailWithException  = true,
                ThrowThisException = new InvalidOperationException("rm1"),
                Type = ResourceManagerType.Volatile
            };
            var rm2 = new IntResourceManager(2)
            {
                FailPrepare        = true,
                FailWithException  = true,
                ThrowThisException = new InvalidOperationException("rm2"),
                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; status = e.Transaction.TransactionInformation.Status; };
                    ts.Complete();
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }

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

            // MS.NET wont call TransactionCompleted event in this particular case.
            Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.IsNotNull(ex, "Exception not thrown");
#if MS_EXCEPTIONS_BEHAVIOR
            // MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
            Assert.AreEqual(rm1.ThrowThisException, ex, "Exception does not come from the expected RM");
#else
            // Mono wrapps the exception into a TransactionAbortedException.
            Assert.That(ex, InstanceOf(typeof(TransactionAbortedException)), "Invalid type of exception thrown");
            Assert.IsNotNull(ex.InnerException, "InnerException not thrown");
            Assert.AreEqual(rm1.ThrowThisException, ex.InnerException, "Exception does not come from the expected RM \n Ex: {0}", ex);
#endif
        }
Example #28
0
        public void Vol0_Dur0_Pspe1()
        {
            IntResourceManager irm = new IntResourceManager(1);

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

                scope.Complete();
            }
            irm.Check(1, 0, 0, 0, 0, 1, 0, "irm");
        }
Example #29
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" );
		}
Example #30
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");
        }
		public void TransactionScopeAbort ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists");
			IntResourceManager irm = new IntResourceManager (1);
			using (TransactionScope scope = new TransactionScope ()) {
				Assert.IsNotNull (Transaction.Current, "Ambient transaction does not exist");
				Assert.AreEqual (TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "transaction is not active");

				irm.Value = 2;
				/* Not completing scope here */
			}
			irm.Check ( 0, 0, 1, 0, "irm");
			Assert.AreEqual (1, irm.Value);
			Assert.IsNull (Transaction.Current, "Ambient transaction exists");
		}
        public void TransactionScopeAbort()
        {
            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
            IntResourceManager irm = new IntResourceManager(1);

            using (TransactionScope scope = new TransactionScope()) {
                Assert.IsNotNull(Transaction.Current, "Ambient transaction does not exist");
                Assert.AreEqual(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status, "transaction is not active");

                irm.Value = 2;
                /* Not completing scope here */
            }
            irm.Check(0, 0, 1, 0, "irm");
            Assert.AreEqual(1, irm.Value);
            Assert.IsNull(Transaction.Current, "Ambient transaction exists");
        }
Example #33
0
		public void Async3 ()
		{
			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 );
			ct.EndCommit ( ar );

			irm.Check ( 1, 1, 0, 0, "irm" );
		}
		public void RMFail1 ()
		{
			IntResourceManager irm = new IntResourceManager (1);
			IntResourceManager irm2 = new IntResourceManager (10);
			IntResourceManager irm3 = new IntResourceManager (12);

			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			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.IsNull (Transaction.Current, "Ambient transaction exists (after)");
		}
		public void ExplicitTransaction10b ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

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

			TransactionScope scope = new TransactionScope ( ct );
			Assert.AreEqual ( ct, Transaction.Current, "ambient transaction" );
			//scope2.Complete ();
			//scope2.Dispose ();
			IAsyncResult ar = ct.BeginCommit ( null, null );
			try {
				ct.EndCommit (ar);
			}
			catch ( TransactionAbortedException) {
				irm.Check ( 0, 0, 1, 0, "irm" );
				Transaction.Current = null;
				return;
			}

			Transaction.Current = null;
			Assert.Fail ();
		}
Example #36
0
		public void TransactionDispose3 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager irm = new IntResourceManager (1);

			try {
				Transaction.Current = ct;
				irm.Value = 5;
				ct.Commit ();
				ct.Dispose ();
			} finally {
				Transaction.Current = null;
			}

			irm.Check (1, 1, 0, 0, "Dispose transaction");
			Assert.AreEqual (5, irm.Value);
		}
		public void ExplicitTransaction4 ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			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.AreEqual (ct, Transaction.Current, "#53");

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

			Assert.AreEqual (oldTransaction, Transaction.Current, "#54");
			Assert.AreEqual (TransactionStatus.Active, ct.TransactionInformation.Status, "#55");
			Assert.AreEqual (1, irm.Actual, "#56"); /* Actual value */

			ct.Commit ();
			Assert.AreEqual (2, irm.Actual, "#57"); /* New committed actual value */
			Assert.AreEqual (TransactionStatus.Committed, ct.TransactionInformation.Status, "#58");

			irm.Check ( 1, 1, 0, 0, "irm");
		}
Example #38
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;
			try {
				using (TransactionScope scope = new TransactionScope ()) {
					irm.Value = 2;

					scope.Complete ();
				}
			}
			catch (TransactionAbortedException) {
				irm.Check ( 1, 0, 0, 0, 0, 0, 0, "irm" );
				return;
			}

			Assert.Fail ();
		}
Example #39
0
		public void Vol1_Dur0_Pspe1 ()
		{
			IntResourceManager irm0 = new IntResourceManager (1);
			IntResourceManager irm1 = new IntResourceManager (1);
			irm1.Type = ResourceManagerType.Promotable;
			using (TransactionScope scope = new TransactionScope ()) {
				irm0.Value = 2;
				irm1.Value = 8;

				scope.Complete ();
			}
			irm1.Check ( 1, 0, 0, 0, 0, 1, 0, "irm1" );
		}
Example #40
0
		public void Vol2_Throwing_On_First_Rollback_And_Second_Prepare()
		{
			TransactionStatus status = TransactionStatus.Active;
			bool called = false;
			Exception ex = null;
			var rm1 = new IntResourceManager(1)
			{
				FailRollback = true,
				FailWithException = true,
				ThrowThisException = new InvalidOperationException("rm1"),
				Type = ResourceManagerType.Volatile
			};
			var rm2 = new IntResourceManager(2)
			{
				FailPrepare = true,
				FailWithException = true,
				ThrowThisException = new InvalidOperationException("rm2"),
				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; status = e.Transaction.TransactionInformation.Status; };
					ts.Complete();
				}
			}
			catch (Exception _ex)
			{
				ex = _ex;
			}

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

			// MS.NET wont call TransactionCompleted event in this particular case.
			Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
			Assert.IsNotNull(ex, "Exception not thrown");
#if MS_EXCEPTIONS_BEHAVIOR
			// MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
			Assert.AreEqual(rm1.ThrowThisException, ex, "Exception does not come from the expected RM");
#else
			// Mono wrapps the exception into a TransactionAbortedException.
			Assert.IsInstanceOfType(ex, typeof(TransactionAbortedException), "Invalid type of exception thrown");
			Assert.IsNotNull(ex.InnerException, "InnerException not thrown");
			Assert.AreEqual(rm1.ThrowThisException, ex.InnerException, "Exception does not come from the expected RM \n Ex: {0}", ex);
#endif
		}
Example #41
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.IsTrue(called, "TransactionCompleted event handler not called!");
			Assert.AreEqual(TransactionStatus.Committed, status, "TransactionStatus != Commited");
		}
		public void TransactionDispose ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager irm = new IntResourceManager (1);
			irm.Volatile = false;

			ct.Dispose ();
			irm.Check  (0, 0, 0, 0, "Dispose transaction");
		}
Example #43
0
		public void Vol2_Throwing_On_Rollback()
		{
			bool called = false;
			Exception ex = null;
			var rm1 = new IntResourceManager(1)
			{
				FailRollback = 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;
					// Not calling ts.Complete() on purpose..
				}
			}
			catch (Exception _ex)
			{
				ex = _ex;
			}

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

			// MS.NET wont call TransactionCompleted event in this particular case.
			Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
			Assert.IsNotNull(ex, "Exception not thrown");
			// MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
			Assert.AreEqual(rm1.ThrowThisException, ex, "Exception does not come from the expected RM \n Ex: {0}", ex);

		}
		public void NestedTransactionScope1 ()
		{
			IntResourceManager irm = new IntResourceManager (1);

			Assert.IsNull (Transaction.Current, "Ambient transaction exists");
			using (TransactionScope scope = new TransactionScope ()) {
				irm.Value = 2;

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

			Assert.IsNull (Transaction.Current, "Ambient transaction exists");
			/* Value = 2, got committed */
			Assert.AreEqual (irm.Value, 2, "#1");
			irm.Check ( 1, 1, 0, 0, "irm" );
		}
Example #45
0
		public void Vol2SPC_Throwing_On_Commit()
		{
			TransactionStatus status = TransactionStatus.Active;
			bool called = false;
			Exception ex = null;
			var rm1 = new IntResourceManager(1)
			{
				UseSingle = true,
				FailCommit = true,
				FailWithException = true,
				ThrowThisException = new InvalidOperationException("rm1"),
				Type = ResourceManagerType.Volatile,
			};
			var rm2 = new IntResourceManager(2)
			{
				UseSingle = true,
				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; status = e.Transaction.TransactionInformation.Status; };
					ts.Complete();
				}
			}
			catch (Exception _ex)
			{
				ex = _ex;
			}

			// There can be only one *Single* PC enlistment,
			// so TM will downgrade both to normal enlistments.
			rm1.Check(0, 1, 1, 0, 0, 0, 0, "rm1");
			rm2.Check(0, 1, 0, 0, 0, 0, 0, "rm2");

			// MS.NET wont call TransactionCompleted event in this particular case.
			Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
			Assert.IsNotNull(ex, "Exception not thrown");
#if MS_EXCEPTIONS_BEHAVIOR
			// MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
			Assert.AreEqual(rm1.ThrowThisException, ex, "Exception does not come from the expected RM");
#else
			// Mono wrapps the exception into a TransactionAbortedException.
			Assert.That (ex, InstanceOf( typeof(TransactionAbortedException)), "Invalid type of exception thrown");
			Assert.IsNotNull(ex.InnerException, "InnerException not thrown");
			Assert.AreEqual(rm1.ThrowThisException, ex.InnerException, "Exception does not come from the expected RM \n Ex: {0}", ex);
#endif
		}
Example #46
0
		public void Vol2_Throwing_On_First_Prepare()
		{
			TransactionStatus status = TransactionStatus.Active;
			bool called = false;
			Exception ex = null;
			var rm1 = new IntResourceManager(1)
			{
				FailPrepare = 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; status = e.Transaction.TransactionInformation.Status; };
					ts.Complete();
				}
			}
			catch (Exception _ex)
			{
				ex = _ex;
			}

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

			Assert.IsTrue(called, "TransactionCompleted event handler not called!");
			Assert.IsNotNull(ex, "Exception not thrown");
			Assert.That (ex, InstanceOf( typeof(TransactionAbortedException)), "Invalid exception thrown");
			Assert.IsNotNull(ex.InnerException, "InnerException is null");
			Assert.That (ex.InnerException, InstanceOf( typeof(InvalidOperationException)), "Invalid inner exception thrown");
			Assert.AreEqual(TransactionStatus.Aborted, status, "TransactionStatus != Aborted");
		}
Example #47
0
		public void Async4 ()
		{
			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 );
			ar.AsyncWaitHandle.WaitOne ();
			Assert.IsTrue ( ar.IsCompleted );

			irm.Check ( 1, 1, 0, 0, "irm" );
		}
Example #48
0
		public void Vol1_Throwing_On_Commit()
		{
			bool called = false;
			TransactionStatus status = TransactionStatus.Active;
			Exception ex = null;
			var rm = new IntResourceManager(1)
			{
				FailCommit = 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(0, 1, 1, 0, 0, 0, 0, "rm");

			// MS.NET wont call TransactionCompleted event in this particular case.
			Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
			Assert.IsNotNull(ex, "Exception not thrown");
#if MS_EXCEPTIONS_BEHAVIOR
			// MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
			Assert.IsInstanceOfType(typeof(NotSupportedException), ex, "Invalid exception thrown");
#else
			// Mono wrapps the exception into a TransactionAbortedException.
			Assert.IsInstanceOfType(ex, typeof(TransactionAbortedException), "Invalid type of exception thrown");
			Assert.IsNotNull(ex.InnerException, "InnerException not thrown");
            Assert.IsInstanceOfType(ex.InnerException, typeof(NotSupportedException), "Invalid type of inner exception thrown");
#endif
		}
Example #49
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.IsTrue ( ar.IsCompleted );
			try {
				CommittableTransaction ctx = ar as CommittableTransaction;
				ctx.EndCommit ( ar );
			} catch ( TransactionAbortedException ) {
				irm.Check ( 1, 0, 0, 0, "irm" );
				return;
			}

			Assert.Fail ("EndCommit should've failed");
		}
Example #50
0
		public void Vol1_Throwing_On_Rollback()
		{
			bool called = false;
			TransactionStatus status = TransactionStatus.Active;
			Exception ex = null;
			var rm = new IntResourceManager(1)
			{
				FailRollback = 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; };
					// Not calling ts.Complete() on purpose..
				}
			}
			catch (Exception _ex)
			{
				ex = _ex;
			}

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

			// MS.NET wont call TransactionCompleted event in this particular case.
			Assert.IsFalse(called, "TransactionCompleted event handler _was_ called!?!?!");
			Assert.IsNotNull(ex, "Exception not thrown");
			// MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
			Assert.IsInstanceOfType(ex, typeof(NotSupportedException), "Invalid exception thrown");
		}
		public void ExplicitTransaction6b ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

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

			TransactionScope scope1 = new TransactionScope ();
			/* Enlist */
			irm.Value = 2;

			scope1.Complete ();

			try {
				ct.Commit ();
			} catch (TransactionAbortedException) {
				irm.Check ( 0, 0, 1, 0, "irm" );
				
				scope1.Dispose ();
				Transaction.Current = null;
				return;
			}
			Assert.Fail ( "Commit should've failed" );
		}
Example #52
0
		public void Vol1_Throwing_On_Prepare()
		{
			bool called = false;
			TransactionStatus status = TransactionStatus.Active;
			Exception ex = null;
			var rm = new IntResourceManager(1)
			{
				FailPrepare = 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(0, 1, 0, 0, 0, 0, 0, "rm");

			Assert.IsTrue(called, "TransactionCompleted event handler not called!");
			Assert.IsNotNull(ex, "Exception not thrown");
			Assert.IsInstanceOfType(ex, typeof(TransactionAbortedException), "Invalid exception thrown");
			Assert.IsNotNull(ex.InnerException, "InnerException is null");
            Assert.IsInstanceOfType(ex.InnerException, typeof(NotSupportedException), "Invalid inner exception thrown");
			Assert.AreEqual(TransactionStatus.Aborted, status, "TransactionStatus != Aborted");
		}
Example #53
0
		public void TransactionDispose ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager irm = new IntResourceManager (1);
			irm.Type = ResourceManagerType.Durable;

			ct.Dispose ();
			irm.Check  (0, 0, 0, 0, "Dispose transaction");
		}
Example #54
0
		public void Vol2SPC_Committed()
		{
			TransactionStatus status = TransactionStatus.Active;
			bool called = false;
			var rm1 = new IntResourceManager(1)
			{
				UseSingle = true,
				Type = ResourceManagerType.Volatile
			};
			var rm2 = new IntResourceManager(2)
			{
				UseSingle = true,
				Type = ResourceManagerType.Volatile
			};

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

			// There can be only one *Single* PC enlistment,
			// so TM will downgrade both to normal enlistments.
			rm1.Check(0, 1, 1, 0, 0, 0, 0, "rm1");
			rm2.Check(0, 1, 1, 0, 0, 0, 0, "rm2");

			Assert.IsTrue(called, "TransactionCompleted event handler not called!");
			Assert.AreEqual(TransactionStatus.Committed, status, "TransactionStatus != Committed");
		}
		public void ExplicitTransaction5 ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			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.AreEqual (ct, Transaction.Current, "#59");

				irm.Value = 2;

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

			Assert.AreEqual (oldTransaction, Transaction.Current, "#60");
			Assert.AreEqual (TransactionStatus.Aborted, ct.TransactionInformation.Status, "#61");
			Assert.AreEqual (1, irm.Actual, "#62"); /* Actual value */

			irm.Check ( 0, 0, 1, 0, "irm");
		}
Example #56
0
		public void Vol2_Rollback()
		{
			TransactionStatus status = TransactionStatus.Active;
			bool called = false;
			var rm1 = new IntResourceManager(1)
			{
				Type = ResourceManagerType.Volatile
			};
			var rm2 = new IntResourceManager(1)
			{
				Type = ResourceManagerType.Volatile
			};

			using (var ts = new TransactionScope())
			{
				rm1.Value = 11;
				rm2.Value = 22;
				var tr = Transaction.Current;
				tr.TransactionCompleted += (s, e) => { called = true; status = e.Transaction.TransactionInformation.Status; };
				// Not calling ts.Complete() on purpose..
			}

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

			Assert.IsTrue(called, "TransactionCompleted event handler not called!");
			Assert.AreEqual(TransactionStatus.Aborted, status, "TransactionStatus != Aborted");
		}
		public void ExplicitTransaction2 ()
		{
			Assert.IsNull (Transaction.Current, "Ambient transaction exists (before)");
			CommittableTransaction ct = new CommittableTransaction ();
			Transaction oldTransaction = Transaction.Current;

			Transaction.Current = ct;

			IntResourceManager irm = new IntResourceManager (1);

			irm.Value = 2;
			using (TransactionScope scope = new TransactionScope ()) {
				Assert.AreEqual (ct, Transaction.Current, "#44");

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

			Assert.AreEqual (TransactionStatus.Aborted, ct.TransactionInformation.Status, "#45");
			Assert.AreEqual (ct, Transaction.Current, "#46");
			Assert.AreEqual (1, irm.Actual, "#47");
			Assert.AreEqual (1, irm.NumRollback, "#48");
			irm.Check ( 0, 0, 1, 0, "irm" );
			Transaction.Current = oldTransaction;

			try {
				ct.Commit ();
			} catch (TransactionAbortedException) {
				return;
			}
			Assert.Fail ("Commit on an aborted transaction should fail");
		}
Example #58
0
		public void Async2 ()
		{
			IntResourceManager irm = new IntResourceManager ( 1 );

			CommittableTransaction ct = new CommittableTransaction ();

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

				//scope.Complete ();

				IAsyncResult ar = ct.BeginCommit ( null, null);
				try {
					ct.EndCommit ( ar );
				}
				catch ( TransactionAbortedException) {
					irm.Check ( 0, 0, 1, 0, "irm" );
					return;
				}
			}
			Assert.Fail ( "EndCommit should've thrown an exception" );
		}
		public void ExplicitTransaction6c ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

			IntResourceManager irm = new IntResourceManager ( 1 );

			Transaction.Current = ct;

			TransactionScope scope1 = new TransactionScope (TransactionScopeOption.RequiresNew);
			/* Enlist */
			irm.Value = 2;

			TransactionScope scope2 = new TransactionScope ();
			try {
				scope1.Dispose ();
			} catch (InvalidOperationException) {
				/* Error: TransactionScope nested incorrectly */
				irm.Check ( 0, 0, 1, 0, "irm" );
				scope2.Dispose ();
				Transaction.Current = null;
				return;
			}

			Assert.Fail ("Commit should've failed");
		}
		public void ExplicitTransaction8a ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

			IntResourceManager irm = new IntResourceManager ( 1 );
			using ( TransactionScope scope = new TransactionScope ( ct ) ) {
				irm.Value = 2;
				scope.Complete ();
				/* FIXME: Why TransactionAbortedException ?? */
				try {
					ct.Commit ();
				}
				catch ( TransactionAbortedException) {
					irm.Check ( 0, 0, 1, 0, "irm" );
					return;
				}
				Assert.Fail ( "Should not be reached" );
			}
		}