-
Notifications
You must be signed in to change notification settings - Fork 16
Add transaction scope and distributed transaction tests #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IwanowM
wants to merge
2
commits into
nhibernate:master
Choose a base branch
from
IwanowM:before_transaction_completion_issue_from_nh5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
Src/NHibernate.Envers.Tests/Integration/Basic/TransactionScopeDistributed.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Transactions; | ||
using NHibernate.Envers.Configuration; | ||
using NHibernate.Envers.Tests.Entities; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Envers.Tests.Integration.Basic | ||
{ | ||
public class TransactionScopeDistributed : TestBase | ||
{ | ||
public TransactionScopeDistributed(AuditStrategyForTest strategyType) : base(strategyType) | ||
{ | ||
} | ||
|
||
#if NETCOREAPP2_0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe put the ignore on the complete class instead? |
||
[Ignore("Distributed transaction is not supported in Core.")] | ||
#endif | ||
[Test] | ||
public void ShouldNotThrowWhenDistributedTransaction() | ||
{ | ||
var entity = new StrTestEntity { Str = "data" }; | ||
|
||
Assert.DoesNotThrow(() => | ||
{ | ||
using (var distrTx = new TransactionScope()) | ||
{ | ||
// Simulation of durable resource enlistment | ||
using (var newSession = Session.SessionFactory.OpenSession()) | ||
{ | ||
newSession.FlushMode = FlushMode.Manual; | ||
newSession.Query<StrTestEntity>().FirstOrDefault(); | ||
} | ||
|
||
using (var newSession2 = Session.SessionFactory.OpenSession()) | ||
{ | ||
newSession2.FlushMode = FlushMode.Manual; | ||
newSession2.Save(entity); | ||
newSession2.Flush(); | ||
} | ||
|
||
distrTx.Complete(); | ||
} | ||
}); | ||
} | ||
|
||
#if NETCOREAPP2_0 | ||
[Ignore("Distributed transaction is not supported in Core.")] | ||
#endif | ||
[Test] | ||
public void ShouldNotThrowWhenDistributedTransactionWithAutoFlushMode() | ||
{ | ||
var entity = new StrTestEntity { Str = "data" }; | ||
|
||
Assert.DoesNotThrow(() => | ||
{ | ||
using (var distrTx = new TransactionScope()) | ||
{ | ||
using (var newSession = Session.SessionFactory.OpenSession()) | ||
{ | ||
newSession.FlushMode = FlushMode.Auto; | ||
newSession.Query<StrTestEntity>().FirstOrDefault(); | ||
} | ||
|
||
using (var newSession2 = Session.SessionFactory.OpenSession()) | ||
{ | ||
newSession2.FlushMode = FlushMode.Auto; | ||
newSession2.Save(entity); | ||
newSession2.Flush(); | ||
} | ||
|
||
distrTx.Complete(); | ||
} | ||
}); | ||
} | ||
|
||
#if NETCOREAPP2_0 | ||
[Ignore("Distributed transaction is not supported in Core.")] | ||
#endif | ||
[Test] | ||
public void ShouldNotThrowWhenDistributedTransactionWithNhTransaction() | ||
{ | ||
var entity = new StrTestEntity { Str = "data" }; | ||
|
||
Assert.DoesNotThrow(() => | ||
{ | ||
using (var distrTx = new TransactionScope()) | ||
{ | ||
using (var newSession = Session.SessionFactory.OpenSession()) | ||
{ | ||
newSession.Query<StrTestEntity>().FirstOrDefault(); | ||
} | ||
|
||
using (var newSession2 = Session.SessionFactory.OpenSession()) | ||
{ | ||
using (var nhTx = newSession2.BeginTransaction()) | ||
{ | ||
newSession2.Save(entity); | ||
newSession2.Flush(); | ||
nhTx.Commit(); | ||
} | ||
} | ||
|
||
distrTx.Complete(); | ||
} | ||
}); | ||
} | ||
|
||
protected override void Initialize() | ||
{ | ||
} | ||
|
||
protected override void AddToConfiguration(Cfg.Configuration configuration) | ||
{ | ||
ConfigurationKey.StoreDataAtDelete.SetUserValue(configuration, true); | ||
} | ||
|
||
protected override IEnumerable<string> Mappings | ||
{ | ||
get { return new[] {"Entities.Mapping.hbm.xml", "Integration.Collection.NoRevision.Mapping.hbm.xml"}; } | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Src/NHibernate.Envers.Tests/Integration/Basic/TransactionScopeTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Transactions; | ||
using NHibernate.Envers.Configuration; | ||
using NHibernate.Envers.Tests.Entities; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Envers.Tests.Integration.Basic | ||
{ | ||
public class TransactionScopeTest : TestBase | ||
{ | ||
public TransactionScopeTest(AuditStrategyForTest strategyType) : base(strategyType) | ||
{ | ||
} | ||
|
||
#if NETCOREAPP2_0 | ||
[Ignore("System.Transactions is not supported in Core. See https://github.com/dotnet/corefx/issues/19894")] | ||
#endif | ||
[Test] | ||
public void ShouldNotThrowIfUseConnectionOnSystemTransactionPrepareIsFalse() | ||
{ | ||
var entity = new StrTestEntity { Str = "data" }; | ||
|
||
Assert.DoesNotThrow(() => | ||
{ | ||
using (var distrTx = new TransactionScope()) | ||
{ | ||
using (var newSession = Session.SessionFactory.OpenSession()) | ||
{ | ||
newSession.FlushMode = FlushMode.Manual; | ||
newSession.Save(entity); | ||
newSession.Flush(); | ||
} | ||
distrTx.Complete(); | ||
} | ||
}); | ||
} | ||
|
||
protected override void Initialize() | ||
{ | ||
} | ||
|
||
protected override void AddToConfiguration(Cfg.Configuration configuration) | ||
{ | ||
ConfigurationKey.StoreDataAtDelete.SetUserValue(configuration, true); | ||
|
||
// It is recommended since NH 5 | ||
configuration.SetProperty(NHibernate.Cfg.Environment.UseConnectionOnSystemTransactionPrepare, "false"); | ||
} | ||
|
||
protected override IEnumerable<string> Mappings | ||
{ | ||
get { return new[] {"Entities.Mapping.hbm.xml", "Integration.Collection.NoRevision.Mapping.hbm.xml"}; } | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In NHibernate.Envers.Tests.Integration there is converted Hibernate Envers tests, so these tests suits better in NetSpecific.Integration instead.