public void NestedTransactionScope6()
        {
            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.RequiresNew))
                {
                    irm2.Value = 20;
                    scope2.Complete();
                }
                /* vr2, committed */
                irm2.Check(1, 1, 0, 0, "irm2");
                Assert.Equal(irm2.Value, 20);

                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(irm.Value, 2);
            irm.Check(1, 1, 0, 0, "irm");
        }
        public void NestedTransactionScope4()
        {
            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())
                {
                    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.Equal(TransactionStatus.Aborted, Transaction.Current.TransactionInformation.Status);
                //scope.Complete ();
            }

            Assert.Null(Transaction.Current);

            Assert.Equal(irm.Value, 1);
            Assert.Equal(irm2.Value, 10);
            irm.Check(0, 0, 1, 0, "irm");
        }
        public void NestedTransactionScope5()
        {
            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())
                {
                    irm2.Value = 20;
                    scope2.Complete();
                }

                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

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

            Assert.Null(Transaction.Current);

            Assert.Equal(irm.Value, 1);
            Assert.Equal(irm2.Value, 10);
            irm.Check(0, 0, 1, 0, "irm");
            irm2.Check(0, 0, 1, 0, "irm2");
        }
        public void ExplicitTransaction16()
        {
            CommittableTransaction ct   = new CommittableTransaction();
            IntResourceManager     irm0 = new IntResourceManager(3);
            IntResourceManager     irm  = new IntResourceManager(1);

            Assert.Null(Transaction.Current);

            Transaction.Current = ct;
            try
            {
                irm.FailPrepare       = true;
                irm.FailWithException = true;
                irm.Value             = 2;
                irm0.Value            = 6;

                var e = Assert.Throws <TransactionAbortedException>(() => ct.Commit());
                Assert.NotNull(e.InnerException);
                Assert.IsType <NotSupportedException>(e.InnerException);
                irm.Check(1, 0, 0, 0, "irm");
                irm0.Check(0, 0, 1, 0, "irm0");
            }
            finally
            {
                Transaction.Current = null;
            }
        }
        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 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");
        }
        public void ExplicitTransaction15()
        {
            CommittableTransaction ct   = new CommittableTransaction();
            IntResourceManager     irm  = new IntResourceManager(1);
            IntResourceManager     irm2 = new IntResourceManager(3);

            Assert.Null(Transaction.Current);
            Transaction.Current = ct;
            try
            {
                Assert.Throws <InvalidOperationException>(() =>
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        irm.Value           = 2;
                        Transaction.Current = new CommittableTransaction();
                        irm2.Value          = 6;
                    }
                });
                irm.Check(0, 0, 1, 0, "irm");
                irm2.Check(0, 0, 1, 0, "irm2");
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Exemple #8
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 won't call TransactionCompleted event in this particular case.
            Assert.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.NotNull(ex);
            // MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
            Assert.IsType <NotSupportedException>(ex);
        }
Exemple #9
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 won't call TransactionCompleted event in this particular case.
            Assert.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.IsType <NotSupportedException>(ex);
        }
Exemple #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.True(called, "TransactionCompleted event handler not called!");
            Assert.Equal(TransactionStatus.Aborted, status);
        }
Exemple #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.True(called, "TransactionCompleted event handler not called!");
            Assert.Equal(TransactionStatus.Committed, status);
        }
        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());
        }
        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");
        }
        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;
            }
        }
        public void NestedTransactionScope7()
        {
            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.RequiresNew))
                {
                    irm2.Value = 20;

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

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

                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            /* ..But irm got committed */
            Assert.Equal(irm.Value, 2);
            irm.Check(1, 1, 0, 0, "irm");
        }
        public void NestedTransactionScope8()
        {
            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 = 20;
                    scope2.Complete();
                }
                irm2.Check(0, 0, 0, 0, "irm2");
                Assert.Equal(20, irm2.Value);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(irm.Value, 2);
            irm.Check(1, 1, 0, 0, "irm");
        }
        public void NestedTransactionScope3()
        {
            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())
                {
                    irm2.Value = 20;

                    scope2.Complete();
                }

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            /* Both got committed */
            Assert.Equal(irm.Value, 2);
            Assert.Equal(irm2.Value, 20);
            irm.Check(1, 1, 0, 0, "irm");
            irm2.Check(1, 1, 0, 0, "irm2");
        }
Exemple #18
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");
        }
Exemple #19
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");
        }
        public void ExplicitTransaction8()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

            using (TransactionScope scope = new TransactionScope(ct))
            {
                irm.Value = 2;
                Assert.Throws <TransactionAbortedException>(() => ct.Commit()); /* FIXME: Why TransactionAbortedException ?? */
                irm.Check(0, 0, 1, 0, "irm");
            }
        }
Exemple #21
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");
        }
Exemple #22
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 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");
        }
        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);
        }
Exemple #25
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 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);
        }
        public void NestedTransactionScope2()
        {
            IntResourceManager irm = new IntResourceManager(1);

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

                /* Not-Completing this scope */
            }

            Assert.Null(Transaction.Current);
            /* Value = 2, got rolledback */
            Assert.Equal(1, irm.Value);
            irm.Check(0, 0, 1, 0, "irm");
        }
        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);
        }
Exemple #28
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);
                Assert.Throws <TransactionAbortedException>(() => ct.EndCommit(ar));
                irm.Check(0, 0, 1, 0, "irm");
            }
        }
Exemple #29
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 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);
        }
        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(2, irm.Value);
            irm.Check(1, 1, 0, 0, "irm");
        }
Exemple #31
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");
        }
Exemple #32
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.True(called, "TransactionCompleted event handler not called!");
            Assert.NotNull(ex);
            Assert.IsType <TransactionAbortedException>(ex);
            Assert.NotNull(ex.InnerException);
            Assert.IsType <InvalidOperationException>(ex.InnerException);
            Assert.Equal(TransactionStatus.Aborted, status);
        }
Exemple #33
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;
            }
        }
        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");
        }
        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());
        }
        public void ExplicitTransaction15()
        {
            CommittableTransaction ct = new CommittableTransaction();
            IntResourceManager irm = new IntResourceManager(1);
            IntResourceManager irm2 = new IntResourceManager(3);

            Assert.Null(Transaction.Current);
            Transaction.Current = ct;
            try
            {
                Assert.Throws<InvalidOperationException>(() =>
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        irm.Value = 2;
                        Transaction.Current = new CommittableTransaction();
                        irm2.Value = 6;
                    }
                });
                irm.Check(0, 0, 1, 0, "irm");
                irm2.Check(0, 0, 1, 0, "irm2");
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Exemple #37
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);
        }
Exemple #38
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.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.IsType<NotSupportedException>(ex);
        }
Exemple #39
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.True(called, "TransactionCompleted event handler not called!");
            Assert.NotNull(ex);
            Assert.IsType<TransactionAbortedException>(ex);
            Assert.NotNull(ex.InnerException);
            Assert.IsType<NotSupportedException>(ex.InnerException);
            Assert.Equal(TransactionStatus.Aborted, status);
        }
        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");
            }
        }
        public void NestedTransactionScope7()
        {
            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.RequiresNew))
                {
                    irm2.Value = 20;
                    /* Not completing 
					 scope2.Complete();*/
                }

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

                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            /* ..But irm got committed */
            Assert.Equal(irm.Value, 2);
            irm.Check(1, 1, 0, 0, "irm");
        }
        public void NestedTransactionScope6()
        {
            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.RequiresNew))
                {
                    irm2.Value = 20;
                    scope2.Complete();
                }
                /* vr2, committed */
                irm2.Check(1, 1, 0, 0, "irm2");
                Assert.Equal(irm2.Value, 20);

                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(irm.Value, 2);
            irm.Check(1, 1, 0, 0, "irm");
        }
        public void NestedTransactionScope5()
        {
            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())
                {
                    irm2.Value = 20;
                    scope2.Complete();
                }

                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);
                /* Not completing outer scope
				scope.Complete (); */
            }

            Assert.Null(Transaction.Current);

            Assert.Equal(irm.Value, 1);
            Assert.Equal(irm2.Value, 10);
            irm.Check(0, 0, 1, 0, "irm");
            irm2.Check(0, 0, 1, 0, "irm2");
        }
        public void NestedTransactionScope4()
        {
            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())
                {
                    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.Equal(TransactionStatus.Aborted, Transaction.Current.TransactionInformation.Status);
                //scope.Complete ();
            }

            Assert.Null(Transaction.Current);

            Assert.Equal(irm.Value, 1);
            Assert.Equal(irm2.Value, 10);
            irm.Check(0, 0, 1, 0, "irm");
        }
        public void NestedTransactionScope3()
        {
            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())
                {
                    irm2.Value = 20;

                    scope2.Complete();
                }

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            /* Both got committed */
            Assert.Equal(irm.Value, 2);
            Assert.Equal(irm2.Value, 20);
            irm.Check(1, 1, 0, 0, "irm");
            irm2.Check(1, 1, 0, 0, "irm2");
        }
        public void NestedTransactionScope2()
        {
            IntResourceManager irm = new IntResourceManager(1);
            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope())
            {
                irm.Value = 2;

                /* Not-Completing this scope */
            }

            Assert.Null(Transaction.Current);
            /* Value = 2, got rolledback */
            Assert.Equal(irm.Value, 1);
            irm.Check(0, 0, 1, 0, "irm");
        }
        public void ExplicitTransaction16()
        {
            CommittableTransaction ct = new CommittableTransaction();
            IntResourceManager irm0 = new IntResourceManager(3);
            IntResourceManager irm = new IntResourceManager(1);

            Assert.Null(Transaction.Current);

            Transaction.Current = ct;
            try
            {
                irm.FailPrepare = true;
                irm.FailWithException = true;
                irm.Value = 2;
                irm0.Value = 6;

                var e = Assert.Throws<TransactionAbortedException>(() => ct.Commit());
                Assert.NotNull(e.InnerException);
                Assert.IsType<NotSupportedException>(e.InnerException);
                irm.Check(1, 0, 0, 0, "irm");
                irm0.Check(0, 0, 1, 0, "irm0");
            }
            finally
            {
                Transaction.Current = null;
            }
        }
        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;
            }
        }
        public void ExplicitTransaction6c()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

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

                TransactionScope scope2 = new TransactionScope();
                Assert.Throws<InvalidOperationException>(() => scope1.Dispose());
                irm.Check(0, 0, 1, 0, "irm");
                scope2.Dispose();
            }
            finally
            {
                Transaction.Current = null;
            }
        }
Exemple #50
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.Equal(5, irm.Value);
        }
        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");
        }
Exemple #52
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.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.NotNull(ex);
            Assert.Equal(rm1.ThrowThisException, ex);
        }
Exemple #53
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.True(called, "TransactionCompleted event handler not called!");
            Assert.Equal(TransactionStatus.Committed, status);
        }
Exemple #54
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.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.NotNull(ex);
            // MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
            Assert.IsType<NotSupportedException>(ex);
        }
Exemple #55
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.True(called, "TransactionCompleted event handler not called!");
            Assert.Equal(TransactionStatus.Aborted, status);
        }
        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");
        }
        public void NestedTransactionScope8()
        {
            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 = 20;
                    scope2.Complete();
                }
                irm2.Check(0, 0, 0, 0, "irm2");
                Assert.Equal(20, irm2.Value);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);

                scope.Complete();
            }

            Assert.Null(Transaction.Current);
            Assert.Equal(irm.Value, 2);
            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.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 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");
        }
Exemple #60
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.False(called, "TransactionCompleted event handler _was_ called!?!?!");
            Assert.NotNull(ex);
            // MS.NET will relay the exception thrown by RM instead of wrapping it on a TransactionAbortedException.
            Assert.Equal(rm1.ThrowThisException, ex);
        }