public void Vol1_Dur0_2PC () { IntResourceManager irm = new IntResourceManager (1); using (TransactionScope scope = new TransactionScope ()) { irm.Value = 2; scope.Complete (); } irm.Check2PC ("irm"); }
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 (); } }
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 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"); }
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" ); }
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(); } }); }
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); }); }
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(); }
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(); } }
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"); }
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"); }
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"); }
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 + "]"); } } }
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"); }
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"); }
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"); }
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(); } } }
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"); }
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(); }
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); }
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"); }
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 (); }
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 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 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" ); }
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" ); }
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" ); }
public PromotableSinglePhaseNotification(IntResourceManager resource) : base(resource) { }
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()); }
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 + "]" ); } }
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 + "]" ); }
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 () ); }
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" ); }
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" ); }
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"); }
public EnlistmentNotification(IntResourceManager resource) { this.resource = resource; }
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" ); }
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" ); }
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"); } }
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 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 (); } }
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" ); }