VoteRollback() 공개 메소드

Votes rollback for the currently executing operation.
/// The requested transaction context state change is invalid. ///
public VoteRollback ( ) : void
리턴 void
예제 #1
0
		private static async Task ExecuteNode(TransactionContextTestNode node)
		{
			if (node.Parent == null)
				Assert.That(TransactionContext.CurrentTransactionContext, Is.Null);

			var tcs = new TaskCompletionSource<TransactionContextState>();

			using (var tx = new TransactionContext(node.Affinity))
			{
				Assert.That(TransactionContext.CurrentTransactionContext, Is.EqualTo(tx));
				Assert.That(tx.IsController, Is.EqualTo(node.IsController));

				if (node.IsController)
				{
					tx.StateChanged +=
						(s, e) =>
						{
							if (e.NewState == TransactionContextState.Exited)
								tcs.SetResult(e.OldState);
						};
				}

				await node.ExecuteOperation().ConfigureAwait(false);

				if (node.Children != null)
				{
					foreach (var child in node.Children)
						await ExecuteNode(child).ConfigureAwait(false);
				}

				if (node.VoteAction == VoteAction.VoteCommit)
					tx.VoteCommit();
				else if (node.VoteAction == VoteAction.VoteRollback)
					tx.VoteRollback();
			}

			if (node.Parent == null)
				Assert.That(TransactionContext.CurrentTransactionContext, Is.Null);

			if (node.IsController)
			{
				var actualCommitState = await tcs.Task.ConfigureAwait(false);
				Assert.That(actualCommitState, Is.EqualTo(node.GetExpectedCommitState()));
			}
		}
		public static void ValidStateTransitionTest_ToBeCommitted_ToBeRollbacked(TransactionContextAffinity affinity)
		{
			using (var context = new TransactionContext(affinity))
			{
				context.VoteCommit();
				Assert.AreEqual(TransactionContextState.ToBeCommitted, context.State);

				context.VoteRollback();
				Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State);
			}
		}
		public static void ValidStateTransitionTest_ToBeRollbacked_ToBeRollbacked(TransactionContextAffinity affinity)
		{
			using (var context = new TransactionContext(affinity))
			{
				context.VoteRollback();
				Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State);

				context.StateChanged +=
					(sender, e) =>
					{
						if (e.NewState == TransactionContextState.ToBeCommitted)
							Assert.Fail("Changed event should not be raised again");
					};

				context.VoteRollback();
				Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State);
			}
		}
		public static void InvalidStateTransitionTest_Exited_ToBeRollbacked(TransactionContextAffinity affinity)
		{
			var ex = Assert.Throws<InvalidOperationException>(
				() =>
				{
					using (var context = new TransactionContext(affinity))
					{
						context.Exit();
						Assert.AreEqual(TransactionContextState.Exited, context.State);

						context.VoteRollback();
					}
				});
		}