Skip to content

Commit

Permalink
Merge branch 'hotfix-6.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Feb 23, 2016
2 parents e7705de + 9f20f16 commit 4505037
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packaging/nuget/nservicebus.nhibernate.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependencies>
<dependency id="Iesi.Collections" version="[4.0.1.4000, 5.0.0)" />
<dependency id="NHibernate" version="[4.0.1.4000, 5.0.0)" />
<dependency id="NServiceBus" version="[5.0.6, 6.0.0)" />
<dependency id="NServiceBus" version="[5.2.8, 6.0.0)" />
</dependencies>
</metadata>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<Compile Include="ConfigureNHibernatePersistence.cs" />
<Compile Include="Issue_67.cs" />
<Compile Include="When_outbox_is_enabled.cs" />
<Compile Include="When_using_NHibernate_persistence_without_DTC.cs" />
<Compile Include="When_user_supplies_NH_Configuration.cs" />
<Compile Include="When_using_hbms.cs" />
<Compile Include="When_saga_contains_nested_collection_without_parent_relation.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace NServiceBus.AcceptanceTests.Basic
{
using System;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NServiceBus.Persistence.NHibernate;
using NUnit.Framework;

public class When_using_NHibernate_persistence_without_DTC : NServiceBusAcceptanceTest
{
[Test]
public void Should_be_able_to_retrieve_database_transaction()
{
var context = new Context
{
Id = Guid.NewGuid()
};

Scenario.Define(context)
.WithEndpoint<Sender>(b => b.Given((bus, c) =>
{
bus.Send<MyMessage>(m=>
{
m.Id = c.Id;
});
}))
.WithEndpoint<Receiver>()
.Done(c => c.Received)
.Run();
}

public class Context : ScenarioContext
{
public bool Received { get; set; }

public Guid Id { get; set; }
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
EndpointSetup<DefaultServer>()
.AddMapping<MyMessage>(typeof(Receiver));
}
}

public class Receiver : EndpointConfigurationBuilder
{
public Receiver()
{
EndpointSetup<DefaultServer>(c =>
{
c.Transactions().DisableDistributedTransactions();
});
}

public class MyMessageHandler : IHandleMessages<MyMessage>
{
public Context Context { get; set; }

public NHibernateStorageContext StorageContext { get; set; }

public void Handle(MyMessage message)
{
if (Context.Id != message.Id)
return;

Assert.IsNotNull(StorageContext.DatabaseTransaction);
Context.Received = true;
}
}
}

public class MyMessage : IMessage
{
public Guid Id { get; set; }
}
}
}
12 changes: 6 additions & 6 deletions src/NServiceBus.NHibernate/NHibernateStorageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public IDbTransaction DatabaseTransaction
{
using (var command = Connection.CreateCommand())
{
Lazy<ITransaction> lazy;
if (pipelineExecutor.CurrentContext.TryGet(string.Format("LazyNHibernateTransaction-{0}", connectionString), out lazy))
ITransaction transaction;
if (pipelineExecutor.CurrentContext.TryGet(string.Format("LazyNHibernateTransaction-{0}", connectionString), out transaction))
{
lazy.Value.Enlist(command);
transaction.Enlist(command);
return command.Transaction;
}
}
Expand Down Expand Up @@ -80,10 +80,10 @@ public ITransaction Transaction
{
get
{
Lazy<ITransaction> lazy;
if (pipelineExecutor.CurrentContext.TryGet(string.Format("LazyNHibernateTransaction-{0}", connectionString), out lazy))
ITransaction transaction;
if (pipelineExecutor.CurrentContext.TryGet(string.Format("LazyNHibernateTransaction-{0}", connectionString), out transaction))
{
return lazy.Value;
return transaction;
}

throw new InvalidOperationException("No transaction available");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void PerformCleanup(object state)
if (cleanupFailures >= 10)
{
criticalError.Raise("Failed to clean expired Outbox records after 10 consecutive unsuccessful attempts. The most likely cause of this is connectivity issues with your database.", ex);
throw;
cleanupFailures = 0;
}
}
}
Expand Down

0 comments on commit 4505037

Please sign in to comment.