|
From: <aye...@us...> - 2009-03-24 11:56:33
|
Revision: 4153
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4153&view=rev
Author: ayenderahien
Date: 2009-03-24 11:56:15 +0000 (Tue, 24 Mar 2009)
Log Message:
-----------
enhancing test case error reporting
adding passing test for NH-1709, but I don't think it reproduces the error well
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs
trunk/nhibernate/src/NHibernate.Test/TestCase.cs
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-03-24 11:27:18 UTC (rev 4152)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-03-24 11:56:15 UTC (rev 4153)
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
@@ -57,6 +58,31 @@
}
[Test]
+ public void Can_roll_back_transaction()
+ {
+ var tx = new TransactionScope();
+ using (var s = sessions.OpenSession())
+ {
+ new ForceEscalationToDistributedTx(true);//will rollback tx
+ s.Save(new Person
+ {
+ CreatedAt = DateTime.Today
+ });
+
+ tx.Complete();
+ }
+ try
+ {
+ tx.Dispose();
+ Assert.Fail("Expected tx abort");
+ }
+ catch (TransactionAbortedException)
+ {
+ //expected
+ }
+ }
+
+ [Test]
public void CanDeleteItemInDtc()
{
object id;
@@ -87,17 +113,28 @@
public class ForceEscalationToDistributedTx : IEnlistmentNotification
{
+ private readonly bool shouldRollBack;
private readonly int thread;
- public ForceEscalationToDistributedTx()
+
+ public ForceEscalationToDistributedTx(bool shouldRollBack)
{
+ this.shouldRollBack = shouldRollBack;
thread = Thread.CurrentThread.ManagedThreadId;
System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None);
}
+ public ForceEscalationToDistributedTx():this(false)
+ {
+
+ }
+
public void Prepare(PreparingEnlistment preparingEnlistment)
{
Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId);
- preparingEnlistment.Prepared();
+ if (shouldRollBack)
+ preparingEnlistment.ForceRollback();
+ else
+ preparingEnlistment.Prepared();
}
public void Commit(Enlistment enlistment)
Modified: trunk/nhibernate/src/NHibernate.Test/TestCase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2009-03-24 11:27:18 UTC (rev 4152)
+++ trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2009-03-24 11:56:15 UTC (rev 4153)
@@ -123,7 +123,8 @@
if (fail)
{
- Assert.Fail("Test didn't clean up after itself");
+ Assert.Fail("Test didn't clean up after itself. session closed: " + wasClosed + " database cleaned: "+ wasCleaned
+ + " connection closed: " + wereConnectionsClosed);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|