public void EnlistDuringPhase0(EnlistmentOptions enlistmentOption, Phase1Vote phase1Vote, bool expectPhase0EnlistSuccess, bool commit, EnlistmentOutcome expectedOutcome, TransactionStatus expectedTxStatus) { Transaction tx = null; AutoResetEvent outcomeEvent = null; try { using (TransactionScope ts = new TransactionScope()) { tx = Transaction.Current.Clone(); outcomeEvent = new AutoResetEvent(false); TestEnlistment enlistment = new TestEnlistment(phase1Vote, expectedOutcome, true, expectPhase0EnlistSuccess, outcomeEvent); tx.EnlistVolatile(enlistment, enlistmentOption); if (commit) { ts.Complete(); } } } catch (TransactionInDoubtException) { Assert.Equal(TransactionStatus.InDoubt, expectedTxStatus); } catch (TransactionAbortedException) { Assert.Equal(TransactionStatus.Aborted, expectedTxStatus); } Assert.True(outcomeEvent.WaitOne(TimeSpan.FromSeconds(MaxTransactionCommitTimeoutInSeconds))); Assert.NotNull(tx); Assert.Equal(expectedTxStatus, tx.TransactionInformation.Status); }
public void EnlistVolatile(int volatileCount, EnlistmentOptions enlistmentOption, Phase1Vote volatilePhase1Vote, Phase1Vote lastPhase1Vote, bool commit, EnlistmentOutcome expectedEnlistmentOutcome, TransactionStatus expectedTxStatus) { AutoResetEvent[] outcomeEvents = null; Transaction tx = null; try { using (TransactionScope ts = new TransactionScope()) { tx = Transaction.Current.Clone(); if (volatileCount > 0) { TestEnlistment[] volatiles = new TestEnlistment[volatileCount]; outcomeEvents = new AutoResetEvent[volatileCount]; for (int i = 0; i < volatileCount - 1; i++) { outcomeEvents[i] = new AutoResetEvent(false); volatiles[i] = new TestEnlistment(volatilePhase1Vote, expectedEnlistmentOutcome, false, true, outcomeEvents[i]); tx.EnlistVolatile(volatiles[i], enlistmentOption); } outcomeEvents[volatileCount - 1] = new AutoResetEvent(false); volatiles[volatileCount - 1] = new TestEnlistment(lastPhase1Vote, expectedEnlistmentOutcome, false, true, outcomeEvents[volatileCount - 1]); tx.EnlistVolatile(volatiles[volatileCount - 1], enlistmentOption); } if (commit) { ts.Complete(); } } } catch (TransactionInDoubtException) { Assert.Equal(TransactionStatus.InDoubt, expectedTxStatus); } catch (TransactionAbortedException) { Assert.Equal(TransactionStatus.Aborted, expectedTxStatus); } Task.Run(() => // in case current thread is STA thread, where WaitHandle.WaitAll isn't supported { Assert.True(WaitHandle.WaitAll(outcomeEvents, TimeSpan.FromSeconds(MaxTransactionCommitTimeoutInSeconds))); }).GetAwaiter().GetResult(); Assert.NotNull(tx); Assert.Equal(expectedTxStatus, tx.TransactionInformation.Status); }
public void TwoPhaseDurable(int volatileCount, EnlistmentOptions volatileEnlistmentOption, EnlistmentOptions durableEnlistmentOption, Phase1Vote volatilePhase1Vote, bool commit, EnlistmentOutcome expectedVolatileOutcome, EnlistmentOutcome expectedDurableOutcome, TransactionStatus expectedTxStatus) { Transaction tx = null; try { using (TransactionScope ts = new TransactionScope()) { tx = Transaction.Current.Clone(); if (volatileCount > 0) { TestEnlistment[] volatiles = new TestEnlistment[volatileCount]; for (int i = 0; i < volatileCount; i++) { // It doesn't matter what we specify for SinglePhaseVote. volatiles[i] = new TestEnlistment(volatilePhase1Vote, expectedVolatileOutcome); tx.EnlistVolatile(volatiles[i], volatileEnlistmentOption); } } TestEnlistment durable = new TestEnlistment(Phase1Vote.Prepared, expectedDurableOutcome); // TODO: Issue #10353 - This needs to change once we have promotion support. Assert.Throws <PlatformNotSupportedException>(() => // Creation of two phase durable enlistment attempts to promote to MSDTC { tx.EnlistDurable(Guid.NewGuid(), durable, durableEnlistmentOption); }); if (commit) { ts.Complete(); } } } catch (TransactionInDoubtException) { Assert.Equal(TransactionStatus.InDoubt, expectedTxStatus); } catch (TransactionAbortedException) { Assert.Equal(TransactionStatus.Aborted, expectedTxStatus); } Assert.NotNull(tx); Assert.Equal(expectedTxStatus, tx.TransactionInformation.Status); }
public void Prepare(PreparingEnlistment preparingEnlistment) { switch (_phase1Vote) { case Phase1Vote.Prepared: { if (_volatileEnlistDuringPrepare) { TestEnlistment newVol = new TestEnlistment(_phase1Vote, _expectedOutcome); try { _txToEnlist.EnlistVolatile(newVol, EnlistmentOptions.None); Assert.True(_expectEnlistToSucceed); } catch (Exception) { Assert.False(_expectEnlistToSucceed); } } preparingEnlistment.Prepared(); break; } case Phase1Vote.ForceRollback: { if (_outcomeReceived != null) { _outcomeReceived.Set(); } preparingEnlistment.ForceRollback(); break; } case Phase1Vote.Done: { if (_outcomeReceived != null) { _outcomeReceived.Set(); } preparingEnlistment.Done(); break; } } }
public void Prepare(PreparingEnlistment preparingEnlistment) { switch (_phase1Vote) { case Phase1Vote.Prepared: { if (_volatileEnlistDuringPrepare) { TestEnlistment newVol = new TestEnlistment(_phase1Vote, _expectedOutcome); try { _txToEnlist.EnlistVolatile(newVol, EnlistmentOptions.None); Assert.Equal(_expectEnlistToSucceed, true); } catch (Exception) { Assert.Equal(_expectEnlistToSucceed, false); } } preparingEnlistment.Prepared(); break; } case Phase1Vote.ForceRollback: { if (_outcomeReceived != null) { _outcomeReceived.Set(); } preparingEnlistment.ForceRollback(); break; } case Phase1Vote.Done: { if (_outcomeReceived != null) { _outcomeReceived.Set(); } preparingEnlistment.Done(); break; } } }
public void TwoPhaseDurable(int volatileCount, EnlistmentOptions volatileEnlistmentOption, EnlistmentOptions durableEnlistmentOption, Phase1Vote volatilePhase1Vote, Phase1Vote durablePhase1Vote, bool commit, EnlistmentOutcome expectedVolatileOutcome, EnlistmentOutcome expectedDurableOutcome, TransactionStatus expectedTxStatus) { Transaction tx = null; try { using (TransactionScope ts = new TransactionScope()) { tx = Transaction.Current.Clone(); if (volatileCount > 0) { TestEnlistment[] volatiles = new TestEnlistment[volatileCount]; for (int i = 0; i < volatileCount; i++) { // It doesn't matter what we specify for SinglePhaseVote. volatiles[i] = new TestEnlistment(volatilePhase1Vote, expectedVolatileOutcome); tx.EnlistVolatile(volatiles[i], volatileEnlistmentOption); } } TestEnlistment durable = new TestEnlistment(Phase1Vote.Prepared, expectedDurableOutcome); // TODO: Issue #10353 - This needs to change once we have promotion support. Assert.Throws<PlatformNotSupportedException>(() => // Creation of two phase durable enlistment attempts to promote to MSDTC { tx.EnlistDurable(Guid.NewGuid(), durable, durableEnlistmentOption); }); if (commit) { ts.Complete(); } } } catch (TransactionInDoubtException) { Assert.Equal(expectedTxStatus, TransactionStatus.InDoubt); } catch (TransactionAbortedException) { Assert.Equal(expectedTxStatus, TransactionStatus.Aborted); } Assert.NotNull(tx); Assert.Equal(expectedTxStatus, tx.TransactionInformation.Status); }
public void EnlistVolatile(int volatileCount, EnlistmentOptions enlistmentOption, Phase1Vote volatilePhase1Vote, Phase1Vote lastPhase1Vote, bool commit, EnlistmentOutcome expectedEnlistmentOutcome, TransactionStatus expectedTxStatus) { AutoResetEvent[] outcomeEvents = null; Transaction tx = null; try { using (TransactionScope ts = new TransactionScope()) { tx = Transaction.Current.Clone(); if (volatileCount > 0) { TestEnlistment[] volatiles = new TestEnlistment[volatileCount]; outcomeEvents = new AutoResetEvent[volatileCount]; for (int i = 0; i < volatileCount-1; i++) { outcomeEvents[i] = new AutoResetEvent(false); volatiles[i] = new TestEnlistment(volatilePhase1Vote, expectedEnlistmentOutcome, false, true, outcomeEvents[i]); tx.EnlistVolatile(volatiles[i], enlistmentOption); } outcomeEvents[volatileCount-1] = new AutoResetEvent(false); volatiles[volatileCount - 1] = new TestEnlistment(lastPhase1Vote, expectedEnlistmentOutcome, false, true, outcomeEvents[volatileCount-1]); tx.EnlistVolatile(volatiles[volatileCount - 1], enlistmentOption); } if (commit) { ts.Complete(); } } } catch (TransactionInDoubtException) { Assert.Equal(expectedTxStatus, TransactionStatus.InDoubt); } catch (TransactionAbortedException) { Assert.Equal(expectedTxStatus, TransactionStatus.Aborted); } Assert.True(AutoResetEvent.WaitAll(outcomeEvents, TimeSpan.FromSeconds(MaxTransactionCommitTimeoutInSeconds))); Assert.NotNull(tx); Assert.Equal(expectedTxStatus, tx.TransactionInformation.Status); }
public void EnlistDuringPhase0(EnlistmentOptions enlistmentOption, EnlistmentOptions phase0EnlistmentOption, Phase1Vote phase1Vote, bool expectPhase0EnlistSuccess, bool commit, EnlistmentOutcome expectedOutcome, TransactionStatus expectedTxStatus) { Transaction tx = null; AutoResetEvent outcomeEvent = null; try { using (TransactionScope ts = new TransactionScope()) { tx = Transaction.Current.Clone(); outcomeEvent = new AutoResetEvent(false); TestEnlistment enlistment = new TestEnlistment(phase1Vote, expectedOutcome, true, expectPhase0EnlistSuccess, outcomeEvent); tx.EnlistVolatile(enlistment, enlistmentOption); if (commit) { ts.Complete(); } } } catch (TransactionInDoubtException) { Assert.Equal(expectedTxStatus, TransactionStatus.InDoubt); } catch (TransactionAbortedException) { Assert.Equal(expectedTxStatus, TransactionStatus.Aborted); } Assert.True(outcomeEvent.WaitOne(TimeSpan.FromSeconds(MaxTransactionCommitTimeoutInSeconds))); Assert.NotNull(tx); Assert.Equal(expectedTxStatus, tx.TransactionInformation.Status); }