-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…6533) * Bring in two acceptance tests from the v7 work for the transactional session * Name param the same * Move saga manifests to the saga persister and introduce the synchronized storage session feature
- Loading branch information
1 parent
cdd3a3d
commit bc839e8
Showing
14 changed files
with
199 additions
and
31 deletions.
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
58 changes: 58 additions & 0 deletions
58
...eBus.AcceptanceTests/Core/Persistence/When_a_persistence_provides_synchronized_session.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,58 @@ | ||
namespace NServiceBus.AcceptanceTests.Core.Persistence | ||
{ | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using NServiceBus.Persistence; | ||
using NUnit.Framework; | ||
|
||
public class When_a_persistence_provides_synchronized_session : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Synchronized_session_should_be_of_exact_type_provided_by_persistence() | ||
{ | ||
var result = await Scenario.Define<Context>() | ||
.WithEndpoint<Endpoint>(e => e.When(b => b.SendLocal(new MyMessage()))) | ||
.Done(c => c.MessageReceived) | ||
.Run(); | ||
|
||
Assert.IsNotNull(result.SynchronizedStorageSessionInstanceInContainer); | ||
Assert.IsNotNull(result.SynchronizedStorageSessionInstanceInHandlingContext); | ||
Assert.AreSame(result.SynchronizedStorageSessionInstanceInContainer, result.SynchronizedStorageSessionInstanceInHandlingContext); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public ISynchronizedStorageSession SynchronizedStorageSessionInstanceInContainer { get; set; } | ||
public ISynchronizedStorageSession SynchronizedStorageSessionInstanceInHandlingContext { get; set; } | ||
public bool MessageReceived { get; set; } | ||
} | ||
|
||
class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() => EndpointSetup<DefaultServer>(); | ||
|
||
class MyMessageHandler : IHandleMessages<MyMessage> | ||
{ | ||
public MyMessageHandler(Context testContext, ISynchronizedStorageSession storageSession) | ||
{ | ||
this.testContext = testContext; | ||
testContext.SynchronizedStorageSessionInstanceInContainer = storageSession; | ||
} | ||
|
||
public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
{ | ||
testContext.SynchronizedStorageSessionInstanceInHandlingContext = context.SynchronizedStorageSession; | ||
testContext.MessageReceived = true; | ||
return Task.FromResult(0); | ||
} | ||
|
||
readonly Context testContext; | ||
} | ||
} | ||
|
||
public class MyMessage : IMessage | ||
{ | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...sts/Core/Reliability/SynchronizedStorage/When_opening_storage_session_outside_pipeline.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,92 @@ | ||
namespace NServiceBus.AcceptanceTests.Reliability.SynchronizedStorage | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using Extensibility; | ||
using Features; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
using Persistence; | ||
|
||
public class When_opening_storage_session_outside_pipeline : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_provide_adapted_session_with_same_scope() | ||
{ | ||
var context = await Scenario.Define<Context>() | ||
.WithEndpoint<Endpoint>() | ||
.Done(c => c.Done) | ||
.Run(); | ||
|
||
Assert.True(context.SessionNotNullAfterOpening, "The adapted session was null after opening the session."); | ||
Assert.True(context.StorageSessionEqual, "The scoped storage session should be equal."); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool StorageSessionEqual { get; set; } | ||
public bool SessionNotNullAfterOpening { get; set; } | ||
public bool Done { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.EnableFeature<Bootstrapper>(); | ||
}); | ||
} | ||
|
||
public class Bootstrapper : Feature | ||
{ | ||
public Bootstrapper() => EnableByDefault(); | ||
|
||
protected override void Setup(FeatureConfigurationContext context) | ||
{ | ||
context.RegisterStartupTask(b => new MyTask(b.GetRequiredService<Context>(), b)); | ||
} | ||
|
||
public class MyTask : FeatureStartupTask | ||
{ | ||
public MyTask(Context scenarioContext, IServiceProvider provider) | ||
{ | ||
this.provider = provider; | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) | ||
{ | ||
using (var scope = provider.CreateScope()) | ||
using (var completableSynchronizedStorageSession = | ||
scope.ServiceProvider.GetRequiredService<ICompletableSynchronizedStorageSession>()) | ||
{ | ||
await completableSynchronizedStorageSession.Open(new ContextBag(), cancellationToken); | ||
|
||
scenarioContext.SessionNotNullAfterOpening = | ||
scope.ServiceProvider.GetService<ISynchronizedStorageSession>() != null; | ||
|
||
var synchronizedStorage = scope.ServiceProvider.GetService<ISynchronizedStorageSession>(); | ||
|
||
scenarioContext.StorageSessionEqual = | ||
completableSynchronizedStorageSession == synchronizedStorage; | ||
|
||
await completableSynchronizedStorageSession.CompleteAsync(cancellationToken); | ||
} | ||
|
||
scenarioContext.Done = true; | ||
} | ||
|
||
protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => Task.CompletedTask; | ||
|
||
readonly Context scenarioContext; | ||
readonly IServiceProvider provider; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/NServiceBus.Core/Persistence/Learning/LearningSynchronizedStorage.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,19 @@ | ||
namespace NServiceBus | ||
{ | ||
using Features; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Persistence; | ||
|
||
sealed class LearningSynchronizedStorage : Feature | ||
{ | ||
public LearningSynchronizedStorage() | ||
{ | ||
DependsOn<SynchronizedStorage>(); | ||
} | ||
|
||
protected internal override void Setup(FeatureConfigurationContext context) | ||
{ | ||
context.Services.AddScoped<ICompletableSynchronizedStorageSession, LearningSynchronizedStorageSession>(); | ||
} | ||
} | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
...nceTests/ApprovalFiles/When_endpoint_is_warmed_up.Make_sure_things_are_in_DI.approved.txt
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