Esempio n. 1
0
		public void Vol1_Dur0_2PC ()
		{
			IntResourceManager irm = new IntResourceManager (1);

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

				scope.Complete ();
			}
			irm.Check2PC ("irm");
		}
Esempio n. 2
0
		public void Vol1_Dur0_Fail3 ()
		{
			IntResourceManager irm = new IntResourceManager (1);
			irm.UseSingle = true;
			irm.FailSPC = true;

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

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

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

			irm.Check ( 0, 0, 0, 1, 0, 0, 0, "irm" );
		}
Esempio n. 4
0
		public void AsyncFail1 ()
		{
			IntResourceManager irm = new IntResourceManager ( 1 );

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

			/* Enlist */
			irm.Value = 2;

			IAsyncResult ar = ct.BeginCommit ( null, null );
			IAsyncResult ar2 = ct.BeginCommit ( null, null );
		}
		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");
		}
Esempio n. 6
0
		public void AsyncFail2 ()
		{
			IntResourceManager irm = new IntResourceManager ( 1 );

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

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

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

			ct.EndCommit ( ar );
		}
		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" );
		}
Esempio n. 8
0
		public void Vol1_Dur0_Fail2 ()
		{
		    ExceptionAssert.Throws<TransactionAbortedException>(
		        delegate
		            {
			            IntResourceManager irm = new IntResourceManager(1);

			            irm.FailPrepare = true;

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

				            scope.Complete();
                        }
                    });
		}
Esempio n. 9
0
		public void AsyncFail1 ()
		{
            ExceptionAssert.Throws<InvalidOperationException>(
		        delegate
		            {
		                IntResourceManager irm = new IntResourceManager(1);

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

		                /* Enlist */
		                irm.Value = 2;

		                IAsyncResult ar = ct.BeginCommit(null, null);
		                IAsyncResult ar2 = ct.BeginCommit(null, null);
		            });
		}
Esempio n. 10
0
        public void Vol2_Dur1_Fail1()
        {
            IntResourceManager [] irm = new IntResourceManager [4];
            irm [0] = new IntResourceManager(1);
            irm [1] = new IntResourceManager(3);
            irm [2] = new IntResourceManager(5);
            irm [3] = new IntResourceManager(7);

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

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

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

                    scope.Complete();
                }
            }
            catch (TransactionAbortedException) {
                irm [0].CheckSPC("irm [0]");
                /* Volatile RMs get 2PC Prepare, and then get rolled back */
                for (int i = 1; i < 4; i++)
                {
                    irm [i].Check(0, 1, 0, 1, 0, 0, 0, "irm [" + i + "]");
                }

                return;
            }

            Assert.Fail();
        }
Esempio n. 11
0
        public void Vol0_Dur2()
        {
            IntResourceManager [] irm = new IntResourceManager [2];
            irm [0] = new IntResourceManager(1);
            irm [1] = new IntResourceManager(3);

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

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

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

                scope.Complete();
            }
        }
        public void NestedTransactionScope13()
        {
            IntResourceManager irm = new IntResourceManager(1);

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

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

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

                scope.Complete();
            }
        }
Esempio n. 13
0
        public void ExplicitTransaction14()
        {
            CommittableTransaction ct  = new CommittableTransaction();
            IntResourceManager     irm = new IntResourceManager(1);

            Assert.IsNull(Transaction.Current);
            Transaction.Current = ct;
            irm.Value           = 2;

            ct.Commit();

            Assert.AreEqual(TransactionStatus.Committed, ct.TransactionInformation.Status);
            try {
                ct.BeginCommit(null, null);
            }
            catch (Exception) {
                Transaction.Current = null;
                return;
            }
            Assert.Fail("Should not be reached");
        }
Esempio n. 14
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");
        }
Esempio n. 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");
        }
        public void ExplicitTransaction8()
        {
            CommittableTransaction ct = new CommittableTransaction();

            IntResourceManager irm = new IntResourceManager(1);

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

            irm [0].Volatile          = false;
            irm [0].FailSPC           = true;
            irm [0].FailWithException = true;

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

            /* Durable RM irm[2] does on SPC, so
             * all volatile RMs get Rollback */
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    irm [0].Value = 2;
                    irm [1].Value = 6;

                    scope.Complete();
                }
            }
            catch (TransactionAbortedException e)
            {
                Assert.IsNotNull(e.InnerException, "Expected e.InnerException == NotSupportedException, but got None");
                Assert.AreEqual(typeof(NotSupportedException), e.InnerException.GetType(), "Expected e.InnerException == NotSupportedException, but got " + e.GetType());

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

            Assert.Fail("Expected TransactionAbortedException");
        }
Esempio n. 18
0
        public void Vol2_Dur1_Fail2()
        {
            IntResourceManager [] irm = new IntResourceManager [4];
            irm [0] = new IntResourceManager(1);
            irm [1] = new IntResourceManager(3);
            irm [2] = new IntResourceManager(5);
            irm [3] = new IntResourceManager(7);

            irm [0].Volatile  = false;
            irm [0].IgnoreSPC = true;

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

            /* Durable RM irm[2] does on SPC, so
             * all volatile RMs get Rollback */
            try {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 5))) {
                    irm [0].Value = 2;
                    irm [1].Value = 6;
                    irm [2].Value = 10;
                    irm [3].Value = 14;

                    scope.Complete();
                }
            }
            catch (TransactionAbortedException) {
                irm [0].CheckSPC("irm [0]");

                /* Volatile RMs get 2PC Prepare, and then get rolled back */
                for (int i = 1; i < 4; i++)
                {
                    irm [i].Check(0, 1, 0, 1, 0, "irm [" + i + "]");
                }
            }
        }
Esempio n. 19
0
        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");
        }
        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");
        }
Esempio n. 21
0
        public void Vol1SPC_Throwing_On_Commit()
        {
            bool              called = false;
            Exception         ex     = null;
            TransactionStatus status = TransactionStatus.Active;
            var rm = new IntResourceManager(1)
            {
                UseSingle         = true,
                FailSPC           = true,
                FailWithException = true,
                Type = ResourceManagerType.Volatile
            };

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

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

            Assert.IsTrue(called, "TransactionCompleted event handler not called!");
            Assert.AreEqual(TransactionStatus.Aborted, status, "TransactionStatus != Aborted");
            Assert.IsNotNull(ex, "Exception not thrown");
            Assert.IsInstanceOfType(typeof(TransactionAbortedException), ex, "Invalid exception thrown");
            Assert.IsNotNull(ex.InnerException, "InnerException is null");
            Assert.IsInstanceOfType(typeof(NotSupportedException), ex.InnerException, "Invalid inner exception thrown");
        }
Esempio n. 22
0
        public void Async1()
        {
            IntResourceManager irm = new IntResourceManager(1);

            CommittableTransaction ct = new CommittableTransaction();

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

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

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

            Assert.IsTrue(called, "callback not called");
            Assert.AreEqual(5, state, "State not received back");

            if (delayedException != null)
            {
                throw new Exception("", delayedException);
            }
        }
        public void RMFail2()
        {
            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(TransactionScopeOption.Required, new TimeSpan(0, 0, 30)))
                {
                    irm.Value  = 2;
                    irm2.Value = 20;
                    irm3.Value = 24;

                    /* irm2 wont call Prepared or ForceRollback in
                     * its Prepare (), so TransactionManager will timeout
                     * waiting for it
                     */
                    irm2.IgnorePrepare = true;
                    scope.Complete();
                }
            }
            catch (TransactionAbortedException e)
            {
                /* FIXME: Not working right now.. no timeout exception thrown! */

                Assert.IsNotNull(e.InnerException, "innerexception is null");
                Assert.AreEqual(typeof(TimeoutException), e.InnerException.GetType(), "#32");

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

            Assert.Fail("Expected TransactionAbortedException (TimeoutException)");
        }
        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");
        }
Esempio n. 25
0
        public void NestedTransactionScope12()
        {
            IntResourceManager irm = new IntResourceManager(1);

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

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

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

                using (TransactionScope scope3 = new TransactionScope(TransactionScopeOption.RequiresNew)) {
                    /* Using RequiresNew here, so outer transaction
                     * being aborted doesn't matter
                     */
                    scope3.Complete();
                }
            }
        }
Esempio n. 26
0
        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");
        }
Esempio n. 27
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();
        }
Esempio n. 28
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);
		}
Esempio n. 29
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");
		}
Esempio n. 30
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 ();
		}
Esempio n. 31
0
		public void Async1 ()
		{
			IntResourceManager irm = new IntResourceManager ( 1 );

			CommittableTransaction ct = new CommittableTransaction ();
			/* Set ambient Tx */
			Transaction.Current = ct;
			/* Enlist */
			irm.Value = 2;

			callback = new AsyncCallback (CommitCallback);
			IAsyncResult ar = ct.BeginCommit ( callback, 5);
			mr.WaitOne (new TimeSpan (0, 2, 0), true);

			Assert.IsTrue (called, "callback not called" );
			Assert.AreEqual ( 5, state, "State not received back");

			if ( delayedException != null )
				throw new Exception ("", delayedException );
		}
Esempio n. 32
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" );
		}
Esempio n. 33
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" );
		}
Esempio n. 34
0
		public void Vol2_Dur1_Fail4 ()
		{
			IntResourceManager [] irm = new IntResourceManager [2];
			irm [0] = new IntResourceManager ( 1 );
			irm [1] = new IntResourceManager ( 3 );

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

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

			/* Durable RM irm[2] does on SPC, so
			 * all volatile RMs get Rollback */
			try {
				using ( TransactionScope scope = new TransactionScope () ) {
					irm [0].Value = 2;
					irm [1].Value = 6;

					scope.Complete ();
				}
			}
			catch ( TransactionAbortedException e) {
				Assert.IsNotNull ( e.InnerException, "Expected e.InnerException == NotSupportedException, but got None");
				Assert.AreEqual ( typeof ( NotSupportedException ), e.InnerException.GetType (), "Expected e.InnerException == NotSupportedException, but got " + e.GetType () );

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

			Assert.Fail ( "Expected TransactionAbortedException" );
		}
Esempio n. 35
0
		public void Vol2_Dur1_Fail3 ()
		{
			IntResourceManager [] irm = new IntResourceManager [4];
			irm [0] = new IntResourceManager ( 1 );
			irm [1] = new IntResourceManager ( 3 );
			irm [2] = new IntResourceManager ( 5 );
			irm [3] = new IntResourceManager ( 7 );

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

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

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

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

				/* irm [1] & [2] get prepare,
				 * [2] -> ForceRollback,
				 * [1] & [3] get rollback,
				 * [0](durable) gets rollback */
				irm [1].Check ( 0, 1, 0, 1, 0, 0, 0, "irm [1]" );
				irm [2].Check ( 0, 1, 0, 0, 0, 0, 0, "irm [2]" );
				irm [3].Check ( 0, 0, 0, 1, 0, 0, 0, "irm [3]" );

				return;
			}

			Assert.Fail ( "Expected TransactionAbortedException" );
		}
Esempio n. 36
0
 public PromotableSinglePhaseNotification(IntResourceManager resource)
     : base(resource)
 {
 }
Esempio n. 37
0
		public void Vol2_Dur1_Fail2b()
		{
			TransactionAbortedException exception = null;
			IntResourceManager[] irm = new IntResourceManager[4];
			irm[0] = new IntResourceManager(1);
			irm[1] = new IntResourceManager(3);
			irm[2] = new IntResourceManager(5);
			irm[3] = new IntResourceManager(7);

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

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

			/* Durable RM irm[2] does on SPC, so
			 * all volatile RMs get Rollback */
			try
			{
				using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 5)))
				{
					irm[0].Value = 2;
					irm[1].Value = 6;
					irm[2].Value = 10;
					irm[3].Value = 14;

					scope.Complete();
				}
			}
			catch (TransactionAbortedException ex)
			{
				irm[0].CheckSPC("irm [0]");

				/* Volatile RMs get 2PC Prepare, and then get rolled back */
				for (int i = 1; i < 4; i++)
					irm[i].Check(0, 1, 0, 1, 0, 0, 0, "irm [" + i + "]");

				exception = ex;
			}

			Assert.IsNotNull(exception, "Expected TransactionAbortedException not thrown!");
			Assert.IsNotNull(exception.InnerException, "TransactionAbortedException has no inner exception!");
			Assert.AreEqual(typeof(TimeoutException), exception.InnerException.GetType());
		}
Esempio n. 38
0
		public void Vol2_Dur1_Fail1 ()
		{
			IntResourceManager [] irm = new IntResourceManager [4];
			irm [0] = new IntResourceManager (1);
			irm [1] = new IntResourceManager (3);
			irm [2] = new IntResourceManager (5);
			irm [3] = new IntResourceManager (7);

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

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

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

					scope.Complete ();
				}
			}
			catch (TransactionAbortedException) {
				irm [0].CheckSPC ( "irm [0]" );
				/* Volatile RMs get 2PC Prepare, and then get rolled back */
				for (int i = 1; i < 4; i++)
					irm [i].Check ( 0, 1, 0, 1, 0, 0, 0, "irm [" + i + "]" );
			}
		}
Esempio n. 39
0
		public void Vol2_Dur1 ()
		{
			IntResourceManager [] irm = new IntResourceManager [4];
			irm [0] = new IntResourceManager ( 1 );
			irm [1] = new IntResourceManager ( 3 );
			irm [2] = new IntResourceManager ( 5 );
			irm [3] = new IntResourceManager ( 7 );

			irm [0].Type = ResourceManagerType.Durable;
			for ( int i = 0; i < 4; i++ )
				irm [i].UseSingle = true;

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

				scope.Complete ();
			}

			irm [0].CheckSPC ( "irm [0]" );

			/* Volatile RMs get 2PC */
			for (int i = 1; i < 4; i++)
				irm [i].Check2PC ( "irm [" + i + "]" );
		}
Esempio n. 40
0
		public void AsyncFail3 ()
		{
			delayedException = null;
			IntResourceManager irm = new IntResourceManager ( 1 );

			CommittableTransaction ct = new CommittableTransaction ();
			/* Set ambient Tx */
			Transaction.Current = ct;
			
			/* Enlist */
			irm.Value = 2;
			irm.FailPrepare = true;

			callback = new AsyncCallback (CommitCallback);
			IAsyncResult ar = ct.BeginCommit ( callback, 5 );
			mr.WaitOne (new TimeSpan (0, 0, 60), true);

			Assert.IsTrue ( called, "callback not called" );
			Assert.AreEqual ( 5, state, "state not preserved" );

			if ( delayedException.GetType () != typeof ( TransactionAbortedException ) )
				Assert.Fail ( "Expected TransactionAbortedException, got {0}", delayedException.GetType () );
		}
Esempio n. 41
0
		public void Vol2_Dur0_SPC ()
		{
			IntResourceManager irm = new IntResourceManager (1);
			IntResourceManager irm2 = new IntResourceManager (3);

			irm.UseSingle = true;
			irm2.UseSingle = true;
			using (TransactionScope scope = new TransactionScope ()) {
				irm.Value = 2;
				irm2.Value = 6;

				scope.Complete ();
			}
			irm.Check2PC ( "irm" );
			irm2.Check2PC ( "irm2" );
		}
Esempio n. 42
0
		public void Vol2_Dur1_Fail5 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager [] irm = new IntResourceManager [2];
			irm [0] = new IntResourceManager ( 1 );
			irm [1] = new IntResourceManager ( 3 );

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

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

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

				scope.Complete ();
			}

			try {
				ct.Commit ();
			}
			catch ( TransactionAbortedException e ) {
				Assert.IsNotNull ( e.InnerException, "Expected e.InnerException == NotSupportedException, but got None" );
				Assert.AreEqual ( typeof ( NotSupportedException ), e.InnerException.GetType (), "Expected e.InnerException == NotSupportedException, but got " + e.GetType () );

				irm [0].Check ( 1, 0, 0, 0, 0, 0, 0, "irm [0]" );
				irm [1].Check ( 0, 1, 0, 1, 0, 0, 0, "irm [1]" );
				try {
					ct.Commit ();
				}
				catch (InvalidOperationException x ) {
					Assert.IsNull ( x.InnerException);
					Transaction.Current = null;
					return;
				}
				Assert.Fail ( "Should not be reached" );
			}

			Assert.Fail ( "Expected TransactionAbortedException" );
		}
Esempio n. 43
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");
		}
Esempio n. 44
0
 public EnlistmentNotification(IntResourceManager resource)
 {
     this.resource = resource;
 }
Esempio n. 45
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" );
		}
Esempio n. 46
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" );
		}
Esempio n. 47
0
		public void Vol0_Dur0_Pspe2 ()
		{
			IntResourceManager irm0 = new IntResourceManager (1);
			IntResourceManager irm1 = new IntResourceManager (1);
			irm0.Type = ResourceManagerType.Promotable;
			irm1.Type = ResourceManagerType.Promotable;
			using (TransactionScope scope = new TransactionScope ()) {
				irm0.Value = 8;
				irm1.Value = 2;
				Assert.AreEqual(0, irm1.NumEnlistFailed, "PSPE enlist did not fail although PSPE RM was already enlisted");
			}
		}
Esempio n. 48
0
		public void Vol0_Dur2 ()
		{
			IntResourceManager [] irm = new IntResourceManager [2];
			irm [0] = new IntResourceManager ( 1 );
			irm [1] = new IntResourceManager ( 3 );

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

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

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

				scope.Complete ();
			}
		}
Esempio n. 49
0
		public void Vol0_Dur1_2PC ()
		{
			IntResourceManager irm = new IntResourceManager (1);

			/* Durable resource enlisted with a IEnlistedNotification
			 * object
			 */
			irm.Type = ResourceManagerType.Durable;

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

				scope.Complete ();
			}
		}
Esempio n. 50
0
		public void Vol0_Dur1 ()
		{
			IntResourceManager irm = new IntResourceManager (1);
			irm.Type = ResourceManagerType.Durable;
			irm.UseSingle = true;

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

				scope.Complete ();
			}

			irm.CheckSPC ( "irm" );
		}