From: <fab...@us...> - 2009-05-13 23:07:17
|
Revision: 4295 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4295&view=rev Author: fabiomaulo Date: 2009-05-13 23:07:09 +0000 (Wed, 13 May 2009) Log Message: ----------- Fix NH-1767 (by James Kovacs) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs trunk/nhibernate/src/NHibernate.Test/SystemTransactions/TransactionNotificationFixture.cs Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-05-13 22:32:05 UTC (rev 4294) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-05-13 23:07:09 UTC (rev 4295) @@ -381,12 +381,16 @@ logger.DebugFormat("enlisted into DTC transaction: {0}", ambientTransation.IsolationLevel); AfterTransactionBegin(null); ambientTransation.TransactionCompleted += delegate(object sender, TransactionEventArgs e) - { - bool wasSuccessful = e.Transaction.TransactionInformation.Status == TransactionStatus.Committed; - AfterTransactionCompletion(wasSuccessful, null); - if (shouldCloseSessionOnDtcTransactionCompleted) - Dispose(true); - }; + { + bool wasSuccessful = e.Transaction.TransactionInformation.Status + == TransactionStatus.Committed; + AfterTransactionCompletion(wasSuccessful, null); + if (shouldCloseSessionOnDtcTransactionCompleted) + { + Dispose(true); + } + ambientTransation = null; + }; ambientTransation.EnlistVolatile(this, EnlistmentOptions.EnlistDuringPrepareRequired); } } Modified: trunk/nhibernate/src/NHibernate.Test/SystemTransactions/TransactionNotificationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/SystemTransactions/TransactionNotificationFixture.cs 2009-05-13 22:32:05 UTC (rev 4294) +++ trunk/nhibernate/src/NHibernate.Test/SystemTransactions/TransactionNotificationFixture.cs 2009-05-13 23:07:09 UTC (rev 4295) @@ -14,23 +14,23 @@ public class RecordingInterceptor : EmptyInterceptor { - public bool afterTransactionBeginCalled; - public bool afterTransactionCompletionCalled; - public bool beforeTransactionCompletionCalled; + public int afterTransactionBeginCalled; + public int afterTransactionCompletionCalled; + public int beforeTransactionCompletionCalled; public override void AfterTransactionBegin(ITransaction tx) { - afterTransactionBeginCalled = true; + afterTransactionBeginCalled++; } public override void AfterTransactionCompletion(ITransaction tx) { - afterTransactionCompletionCalled = true; + afterTransactionCompletionCalled++; } public override void BeforeTransactionCompletion(ITransaction tx) { - beforeTransactionCompletionCalled = true; + beforeTransactionCompletionCalled++; } } @@ -40,9 +40,9 @@ RecordingInterceptor interceptor = new RecordingInterceptor(); using (sessions.OpenSession(interceptor)) { - Assert.IsFalse(interceptor.afterTransactionBeginCalled); - Assert.IsFalse(interceptor.beforeTransactionCompletionCalled); - Assert.IsFalse(interceptor.afterTransactionCompletionCalled); + Assert.AreEqual(0, interceptor.afterTransactionBeginCalled); + Assert.AreEqual(0, interceptor.beforeTransactionCompletionCalled); + Assert.AreEqual(0, interceptor.afterTransactionCompletionCalled); } } @@ -53,9 +53,9 @@ using (new TransactionScope()) using (sessions.OpenSession(interceptor)) { - Assert.IsTrue(interceptor.afterTransactionBeginCalled); - Assert.IsFalse(interceptor.beforeTransactionCompletionCalled); - Assert.IsFalse(interceptor.afterTransactionCompletionCalled); + Assert.AreEqual(1, interceptor.afterTransactionBeginCalled); + Assert.AreEqual(0, interceptor.beforeTransactionCompletionCalled); + Assert.AreEqual(0, interceptor.afterTransactionCompletionCalled); } } @@ -70,8 +70,8 @@ scope.Complete(); } session.Dispose(); - Assert.IsTrue(interceptor.beforeTransactionCompletionCalled); - Assert.IsTrue(interceptor.afterTransactionCompletionCalled); + Assert.AreEqual(1, interceptor.beforeTransactionCompletionCalled); + Assert.AreEqual(1, interceptor.afterTransactionCompletionCalled); } @@ -83,9 +83,41 @@ using (sessions.OpenSession(interceptor)) { } - Assert.IsFalse(interceptor.beforeTransactionCompletionCalled); - Assert.IsTrue(interceptor.afterTransactionCompletionCalled); - + Assert.AreEqual(0, interceptor.beforeTransactionCompletionCalled); + Assert.AreEqual(2, interceptor.afterTransactionCompletionCalled); } + + [Test] + public void TwoTransactionScopesInsideOneSession() { + var interceptor = new RecordingInterceptor(); + using(var session = sessions.OpenSession(interceptor)) { + using(var scope = new TransactionScope()) { + session.CreateCriteria<object>().List(); + scope.Complete(); + } + + using(var scope = new TransactionScope()) { + session.CreateCriteria<object>().List(); + scope.Complete(); + } + } + Assert.AreEqual(2, interceptor.afterTransactionBeginCalled); + Assert.AreEqual(2, interceptor.beforeTransactionCompletionCalled); + Assert.AreEqual(2, interceptor.afterTransactionCompletionCalled); + } + + [Test] + public void OneTransactionScopesInsideOneSession() { + var interceptor = new RecordingInterceptor(); + using(var session = sessions.OpenSession(interceptor)) { + using(var scope = new TransactionScope()) { + session.CreateCriteria<object>().List(); + scope.Complete(); + } + } + Assert.AreEqual(1, interceptor.afterTransactionBeginCalled); + Assert.AreEqual(1, interceptor.beforeTransactionCompletionCalled); + Assert.AreEqual(1, interceptor.afterTransactionCompletionCalled); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |