BeginCommit() публичный Метод

public BeginCommit ( AsyncCallback asyncCallback, object asyncState ) : IAsyncResult
asyncCallback AsyncCallback
asyncState object
Результат IAsyncResult
Пример #1
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 );
		}
Пример #2
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);
		            });
		}
Пример #3
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 );
		}
Пример #4
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 () );
		}
Пример #5
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");
		}
Пример #6
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" );
		}
Пример #7
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" );
		}
Пример #8
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" );
		}
Пример #9
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 );
		}
		public void ExplicitTransaction13 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();
			IntResourceManager irm = new IntResourceManager ( 1 );

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

			try {
				ct.Commit ();
			} catch ( TransactionAbortedException ) {
				Assert.AreEqual ( TransactionStatus.Aborted, ct.TransactionInformation.Status );
				try {
					ct.BeginCommit ( null, null );
				} catch (Exception) {
					Transaction.Current = null;
					return;
				}
				Assert.Fail ( "Should not be reached(2)" );
			}
			Assert.Fail ("Should not be reached");
		}
		public void ExplicitTransaction12 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

			IntResourceManager irm = new IntResourceManager ( 1 );
			irm.FailPrepare = true;
			ct.BeginCommit ( null, null );
			ct.EndCommit ( null );
		}
		public void ExplicitTransaction10b ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

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

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

			Transaction.Current = null;
			Assert.Fail ();
		}
		public void ExplicitTransaction9 ()
		{
			CommittableTransaction ct = new CommittableTransaction ();

			IntResourceManager irm = new IntResourceManager ( 1 );
			ct.BeginCommit ( null, null );
			ct.BeginCommit ( null, null );
		}
		public void ExplicitTransaction9 ()
		{
		    ExceptionAssert.Throws<InvalidOperationException>(
		        delegate
		            {
		                CommittableTransaction ct = new CommittableTransaction();

		                IntResourceManager irm = new IntResourceManager(1);
		                ct.BeginCommit(null, null);
		                ct.BeginCommit(null, null);
		            });
		}
		public void ExplicitTransaction12 ()
		{
		    ExceptionAssert.Throws<ArgumentException>(
		        delegate
		            {
		                CommittableTransaction ct = new CommittableTransaction();

		                IntResourceManager irm = new IntResourceManager(1);
		                irm.FailPrepare = true;
		                ct.BeginCommit(null, null);
		                ct.EndCommit(null);
		            });
		}