-
Notifications
You must be signed in to change notification settings - Fork 27
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
Allow snapshot isolation to be used for the outbox #1643
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eda9956
Enable snapshot isolation to be used for the outbox
andreasohlund f525ad7
Enable snapshot on db
andreasohlund b2a2047
Update ci.yml
andreasohlund 06c00a6
Enable snapshot
andreasohlund b5cf967
Enable permutation for snapshot
andreasohlund 4cbc8e2
Explicit param for outbox mode
andreasohlund ab10b9c
Pass setting
andreasohlund 3afbea1
Run snapshot tests for all supported databases
andreasohlund 78e6a46
Hardcode pessimistic support
andreasohlund 3d5b003
Fix tests
andreasohlund 437e5de
Enable snapshot in transaction scope mode
andreasohlund c75ea36
Only sqlserver and postgres support snapshot
andreasohlund 86c38fd
Add accetance tests for snapshot
andreasohlund 700d1ce
Enable snapshot for atts
andreasohlund fe54411
Fix postgres
andreasohlund 645fd83
Fix parameter
andreasohlund 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
This file contains 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
This file contains 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
This file contains 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
57 changes: 57 additions & 0 deletions
57
src/MsSqlMicrosoftDataClientAcceptanceTests/When_outbox_in_ado_mode.cs
This file contains 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,57 @@ | ||
namespace NServiceBus.AcceptanceTests; | ||
|
||
using System.Data.Common; | ||
using System.Threading.Tasks; | ||
using System.Transactions; | ||
using Microsoft.Data.SqlClient; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
using Persistence.Sql; | ||
using IsolationLevel = System.Data.IsolationLevel; | ||
|
||
[TestFixture] | ||
public class When_outbox_in_ado_mode : NServiceBusAcceptanceTest | ||
andreasohlund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
[Test] | ||
public async Task Should_work_with_snapshot_isolation() | ||
{ | ||
var context = await Scenario.Define<Context>() | ||
.WithEndpoint<Endpoint>(b => b.When(s => s.SendLocal(new MyMessage())) | ||
.CustomConfig(c => c.EnableOutbox().TransactionIsolationLevel(IsolationLevel.Snapshot))) | ||
.Done(c => c.Done) | ||
.Run(); | ||
|
||
Assert.That(context.Transaction, Is.Not.Null, "Transaction should be available in handler"); | ||
Assert.That(context.IsolationLevel, Is.EqualTo(IsolationLevel.Snapshot), "IsolationLevel should be honored"); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool Done { get; set; } | ||
public DbTransaction Transaction { get; set; } | ||
public IsolationLevel IsolationLevel { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() => | ||
EndpointSetup<DefaultServer>(c => c.ConfigureTransport().TransportTransactionMode = TransportTransactionMode.ReceiveOnly); | ||
|
||
public class MyMessageHandler(Context context, ISqlStorageSession storageSession) : IHandleMessages<MyMessage> | ||
{ | ||
public Task Handle(MyMessage message, IMessageHandlerContext handlerContext) | ||
{ | ||
context.Transaction = storageSession.Transaction; | ||
context.IsolationLevel = storageSession.Transaction.IsolationLevel; | ||
context.Done = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
public class MyMessage : IMessage | ||
{ | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/MsSqlMicrosoftDataClientAcceptanceTests/When_outbox_in_transaction_scope_mode.cs
This file contains 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,57 @@ | ||
namespace NServiceBus.AcceptanceTests; | ||
|
||
using System.Threading.Tasks; | ||
using System.Transactions; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class When_outbox_in_transaction_scope_mode : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_work_with_snapshot_isolation() | ||
{ | ||
var context = await Scenario.Define<Context>() | ||
.WithEndpoint<Endpoint>(b => b.When(s => s.SendLocal(new MyMessage())) | ||
.CustomConfig(c => c.EnableOutbox().UseTransactionScope(IsolationLevel.Snapshot))) | ||
.Done(c => c.Done) | ||
.Run(); | ||
|
||
Assert.That(context.Transaction, Is.Not.Null, "Ambient transaction should be available in handler"); | ||
Assert.That(context.IsolationLevel, Is.EqualTo(IsolationLevel.Snapshot), "IsolationLevel should be honored"); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool Done { get; set; } | ||
public Transaction Transaction { get; set; } | ||
public IsolationLevel IsolationLevel { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() => | ||
EndpointSetup<DefaultServer>(c => c.ConfigureTransport().TransportTransactionMode = TransportTransactionMode.ReceiveOnly); | ||
|
||
public class MyMessageHandler(Context context) : IHandleMessages<MyMessage> | ||
{ | ||
public Task Handle(MyMessage message, IMessageHandlerContext handlerContext) | ||
{ | ||
context.Transaction = Transaction.Current; | ||
if (Transaction.Current != null) | ||
{ | ||
context.IsolationLevel = Transaction.Current.IsolationLevel; | ||
} | ||
|
||
context.Done = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
public class MyMessage : IMessage | ||
{ | ||
} | ||
} |
Oops, something went wrong.
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.
ReadCommited and Serializable are the isolation levels that we allow that all databases can handle