From: <aye...@us...> - 2009-03-22 14:21:08
|
Revision: 4149 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4149&view=rev Author: ayenderahien Date: 2009-03-22 14:21:03 +0000 (Sun, 22 Mar 2009) Log Message: ----------- Fixing NH-1711 - Failure of DTC transaction with multiple durable enlistment will crash the process Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-18 16:36:27 UTC (rev 4148) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-22 14:21:03 UTC (rev 4149) @@ -258,14 +258,23 @@ void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) { - BeforeTransactionCompletion(null); - if (FlushMode != FlushMode.Never) - { - using (ConnectionManager.FlushingFromDtcTransaction) - Flush(); - } - preparingEnlistment.Prepared(); - logger.Debug("prepared for DTC transaction"); + try + { + BeforeTransactionCompletion(null); + if (FlushMode != FlushMode.Never) + { + using (ConnectionManager.FlushingFromDtcTransaction) + Flush(); + } + preparingEnlistment.Prepared(); + logger.Debug("prepared for DTC transaction"); + } + catch (Exception exception) + { + logger.Error("DTC transaction prepre phase failed", exception); + preparingEnlistment.ForceRollback(exception); + + } } void IEnlistmentNotification.Commit(Enlistment enlistment) Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs 2009-03-22 14:21:03 UTC (rev 4149) @@ -0,0 +1,90 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using System.Threading; +using System.Transactions; +using NHibernate.Criterion; +using NHibernate.Dialect; +using NHibernate.Exceptions; +using NHibernate.Impl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.DtcFailures +{ + using System.Collections; + + [TestFixture] + public class DtcFailuresFixture : TestCase + { + + protected override IList Mappings + { + get { return new string[] { "NHSpecificTest.DtcFailures.Mappings.hbm.xml" }; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + [Test] + public void WillNotCrashOnDtcPrepareFailure() + { + var tx = new TransactionScope(); + using (var s = sessions.OpenSession()) + { + s.Save(new Person + { + CreatedAt = DateTime.MinValue // will cause SQL date failure + }); + } + + new ForceEscalationToDistributedTx(); + + tx.Complete(); + try + { + tx.Dispose(); + Assert.Fail("Expected failure"); + } + catch (AssertionException) + { + throw; + } + catch (Exception) + { + } + } + + public class ForceEscalationToDistributedTx : IEnlistmentNotification + { + private readonly int thread; + public ForceEscalationToDistributedTx() + { + thread = Thread.CurrentThread.ManagedThreadId; + System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); + } + + public void Prepare(PreparingEnlistment preparingEnlistment) + { + Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); + preparingEnlistment.Prepared(); + } + + public void Commit(Enlistment enlistment) + { + enlistment.Done(); + } + + public void Rollback(Enlistment enlistment) + { + enlistment.Done(); + } + + public void InDoubt(Enlistment enlistment) + { + enlistment.Done(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml 2009-03-22 14:21:03 UTC (rev 4149) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.DtcFailures" + assembly="NHibernate.Test"> + + <class name="Person"> + <id name="Id"> + <generator class="hilo"/> + </id> + <property name="CreatedAt"/> + + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs 2009-03-22 14:21:03 UTC (rev 4149) @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System; + +namespace NHibernate.Test.NHSpecificTest.DtcFailures +{ + public class Person + { + private int id; + + public virtual DateTime CreatedAt { get; set; } + + public virtual int Id + { + get { return id; } + set { id = value; } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 16:36:27 UTC (rev 4148) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-22 14:21:03 UTC (rev 4149) @@ -292,6 +292,8 @@ <Compile Include="GenericTest\SetGeneric\SetGenericFixture.cs" /> <Compile Include="HQL\Animal.cs" /> <Compile Include="HQL\BaseFunctionFixture.cs" /> + <Compile Include="NHSpecificTest\DtcFailures\FutureCriteriaFixture.cs" /> + <Compile Include="NHSpecificTest\DtcFailures\Person.cs" /> <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> @@ -1685,6 +1687,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\DtcFailures\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1694\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1706\Mappings.hbm.xml" /> <EmbeddedResource Include="Stateless\Naturalness.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |