Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"NServiceBus.RavenDB.ClusterWide.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"NServiceBus.RavenDB.PersistenceTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"NServiceBus.RavenDB.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"NServiceBus.RavenDB.TransactionalSession, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")]
namespace NServiceBus.Persistence.RavenDB
{
public interface IAsyncSessionProvider
Expand All @@ -20,6 +21,7 @@ namespace NServiceBus
{
public static class RavenDBOutboxExtensions
{
public static void EndpointName(this NServiceBus.Outbox.OutboxSettings configuration, string endpointName) { }
public static void SetFrequencyToRunDeduplicationDataCleanup(this NServiceBus.Outbox.OutboxSettings configuration, System.TimeSpan frequencyToRunDeduplicationDataCleanup) { }
public static void SetTimeToKeepDeduplicationData(this NServiceBus.Outbox.OutboxSettings configuration, System.TimeSpan timeToKeepDeduplicationData) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ namespace NServiceBus.TransactionalSession.AcceptanceTests
using System;
using System.Threading;
using System.Threading.Tasks;
using NServiceBus.AcceptanceTesting;
using NServiceBus.Features;
using Features;

public class CaptureServiceProviderStartupTask : FeatureStartupTask
{
public CaptureServiceProviderStartupTask(IServiceProvider serviceProvider, ScenarioContext context)
{
if (context is IInjectServiceProvider c)
{
c.ServiceProvider = serviceProvider;
}
}
public CaptureServiceProviderStartupTask(IServiceProvider serviceProvider, TransactionalSessionTestContext context, string endpointName) => context.RegisterServiceProvider(serviceProvider, endpointName);

protected override Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) => Task.CompletedTask;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace NServiceBus.TransactionalSession.AcceptanceTests;

using System;
using System.IO;
using System.Threading.Tasks;
using AcceptanceTesting;
using AcceptanceTesting.Customization;
using AcceptanceTesting.Support;
using Configuration.AdvancedExtensibility;
using NUnit.Framework;

public class DefaultServer : IEndpointSetupTemplate
{
public virtual async Task<EndpointConfiguration> GetConfiguration(RunDescriptor runDescriptor, EndpointCustomizationConfiguration endpointCustomization,
Func<EndpointConfiguration, Task> configurationBuilderCustomization)
{
var endpointConfiguration = new EndpointConfiguration(endpointCustomization.EndpointName);

endpointConfiguration.EnableInstallers();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.Recoverability()
.Delayed(delayed => delayed.NumberOfRetries(0))
.Immediate(immediate => immediate.NumberOfRetries(0));
endpointConfiguration.SendFailedMessagesTo("error");

var storageDir = Path.Combine(Path.GetTempPath(), "learn", TestContext.CurrentContext.Test.ID);

endpointConfiguration.UseTransport(new AcceptanceTestingTransport { StorageLocation = storageDir });

var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.EnableTransactionalSession();
persistence.SetDefaultDocumentStore(SetupFixture.DocumentStore);
persistence.SetMessageToDatabaseMappingConvention(headers =>
{
if (headers.TryGetValue("tenant-id", out var tenantValue))
{
return tenantValue;
}

return SetupFixture.DefaultDatabaseName;
});

endpointConfiguration.GetSettings().Set(persistence);

if (runDescriptor.ScenarioContext is TransactionalSessionTestContext testContext)
{
endpointConfiguration.RegisterStartupTask(sp => new CaptureServiceProviderStartupTask(sp, testContext, endpointCustomization.EndpointName));
}

await configurationBuilderCustomization(endpointConfiguration).ConfigureAwait(false);

// scan types at the end so that all types used by the configuration have been loaded into the AppDomain
endpointConfiguration.TypesToIncludeInScan(endpointCustomization.GetTypesScopedByTestClass());

return endpointConfiguration;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,53 +1,18 @@
namespace NServiceBus.TransactionalSession.AcceptanceTests
{
using System;
using System.IO;
using System.Threading.Tasks;
using AcceptanceTesting;
using AcceptanceTesting.Customization;
using AcceptanceTesting.Support;
using NUnit.Framework;
using Configuration.AdvancedExtensibility;

public class TransactionSessionDefaultServer : IEndpointSetupTemplate
public class TransactionSessionDefaultServer : DefaultServer
{
public virtual async Task<EndpointConfiguration> GetConfiguration(RunDescriptor runDescriptor, EndpointCustomizationConfiguration endpointCustomization,
Func<EndpointConfiguration, Task> configurationBuilderCustomization)
public override async Task<EndpointConfiguration> GetConfiguration(RunDescriptor runDescriptor, EndpointCustomizationConfiguration endpointCustomization, Func<EndpointConfiguration, Task> configurationBuilderCustomization)
{
var endpointConfiguration = new EndpointConfiguration(endpointCustomization.EndpointName);
var endpointConfiguration = await base.GetConfiguration(runDescriptor, endpointCustomization, configurationBuilderCustomization);

endpointConfiguration.EnableInstallers();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.Recoverability()
.Delayed(delayed => delayed.NumberOfRetries(0))
.Immediate(immediate => immediate.NumberOfRetries(0));
endpointConfiguration.SendFailedMessagesTo("error");

var storageDir = Path.Combine(Path.GetTempPath(), "learn", TestContext.CurrentContext.Test.ID);

endpointConfiguration.UseTransport(new AcceptanceTestingTransport
{
StorageLocation = storageDir
});

var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.EnableTransactionalSession();
persistence.SetDefaultDocumentStore(SetupFixture.DocumentStore);
persistence.SetMessageToDatabaseMappingConvention(headers =>
{
if (headers.TryGetValue("tenant-id", out var tenantValue))
{
return tenantValue;
}

return SetupFixture.DefaultDatabaseName;
});

endpointConfiguration.RegisterStartupTask(sp => new CaptureServiceProviderStartupTask(sp, runDescriptor.ScenarioContext));

await configurationBuilderCustomization(endpointConfiguration).ConfigureAwait(false);

// scan types at the end so that all types used by the configuration have been loaded into the AppDomain
endpointConfiguration.TypesToIncludeInScan(endpointCustomization.GetTypesScopedByTestClass());
endpointConfiguration.GetSettings().Get<PersistenceExtensions<RavenDBPersistence>>()
.EnableTransactionalSession();

return endpointConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace NServiceBus.TransactionalSession.AcceptanceTests;

using System;
using System.Collections.Concurrent;
using System.Reflection;
using AcceptanceTesting;

public class TransactionalSessionTestContext : ScenarioContext
{
public IServiceProvider ServiceProvider
{
get
{
var property = typeof(ScenarioContext).GetProperty("CurrentEndpoint", BindingFlags.NonPublic | BindingFlags.Static);

if (property!.GetValue(this) is not string endpointName)
{
throw new InvalidOperationException("Access to the service provider of the endpoint is only possible with in a When statement.");
}

if (!serviceProviders.TryGetValue(endpointName, out var serviceProvider))
{
throw new InvalidOperationException("Could not find service provider for endpoint " + endpointName);
}

return serviceProvider;
}
}

public void RegisterServiceProvider(IServiceProvider serviceProvider, string endpointName) => serviceProviders[endpointName] = serviceProvider;

readonly ConcurrentDictionary<string, IServiceProvider> serviceProviders = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace NServiceBus.TransactionalSession.AcceptanceTests;

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using AcceptanceTesting;
using AcceptanceTesting.Customization;
using Configuration.AdvancedExtensibility;
using NUnit.Framework;

public class When_using_outbox_send_only : NServiceBusAcceptanceTest
{
[Test()]
public async Task Should_send_messages_on_transactional_session_commit()
{
var context = await Scenario.Define<Context>()
.WithEndpoint<SendOnlyEndpoint>(s => s.When(async (_, ctx) =>
{
using var scope = ctx.ServiceProvider.CreateScope();
using var transactionalSession = scope.ServiceProvider.GetRequiredService<ITransactionalSession>();
await transactionalSession.Open(new RavenDbOpenSessionOptions());

var options = new SendOptions();

options.SetDestination(Conventions.EndpointNamingConvention.Invoke(typeof(AnotherEndpoint)));

await transactionalSession.Send(new SampleMessage(), options);

await transactionalSession.Commit(CancellationToken.None);
}))
.WithEndpoint<AnotherEndpoint>()
.WithEndpoint<ProcessorEndpoint>()
.Done(c => c.MessageReceived)
.Run();

Assert.That(context.MessageReceived, Is.True);
}

class Context : TransactionalSessionTestContext
{
public bool MessageReceived { get; set; }
}

class SendOnlyEndpoint : EndpointConfigurationBuilder
{
public SendOnlyEndpoint() => EndpointSetup<DefaultServer>(c =>
{
var persistence = c.GetSettings().Get<PersistenceExtensions<RavenDBPersistence>>();

var options = new TransactionalSessionOptions { ProcessorEndpoint = Conventions.EndpointNamingConvention.Invoke(typeof(ProcessorEndpoint)) };

persistence.EnableTransactionalSession(options);

c.EnableOutbox();
c.SendOnly();
});
}

class AnotherEndpoint : EndpointConfigurationBuilder
{
public AnotherEndpoint() => EndpointSetup<DefaultServer>();

class SampleHandler(Context testContext) : IHandleMessages<SampleMessage>
{
public Task Handle(SampleMessage message, IMessageHandlerContext context)
{
testContext.MessageReceived = true;

return Task.CompletedTask;
}
}
}

class ProcessorEndpoint : EndpointConfigurationBuilder
{
public ProcessorEndpoint() => EndpointSetup<TransactionSessionWithOutboxEndpoint>();
}

class SampleMessage : ICommand
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public async Task Should_store_data_on_correct_tenant()
Assert.That(context.Document.SessionId, Is.EqualTo(context.SessionId), "should have loaded the document from the correct tenant database");
}

public class Context : ScenarioContext, IInjectServiceProvider
public class Context : TransactionalSessionTestContext
{
public IServiceProvider ServiceProvider { get; set; }

public bool MessageReceived { get; set; }
public TestDocument Document { get; set; }
public string SessionId { get; set; }
Expand All @@ -52,18 +50,14 @@ public class MultitenantEndpoint : EndpointConfigurationBuilder
{
public MultitenantEndpoint() => EndpointSetup<TransactionSessionWithOutboxEndpoint>();

public class SampleMessageHandler : IHandleMessages<SampleMessage>
public class SampleMessageHandler(Context testContext) : IHandleMessages<SampleMessage>
{
public SampleMessageHandler(Context testContext) => this.testContext = testContext;

public async Task Handle(SampleMessage message, IMessageHandlerContext context)
{
testContext.MessageReceived = true;
var ravenSession = context.SynchronizedStorageSession.RavenSession();
testContext.Document = await ravenSession.LoadAsync<TestDocument>(message.DocumentId);
}

readonly Context testContext;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ public async Task Should_send_immediate_dispatch_messages_even_if_session_is_not
Assert.That(result.MessageReceived, Is.True);
}

class Context : ScenarioContext, IInjectServiceProvider
class Context : TransactionalSessionTestContext
{
public bool MessageReceived { get; set; }
public bool CompleteMessageReceived { get; set; }
public IServiceProvider ServiceProvider { get; set; }
public string SessionId { get; set; }
}

Expand All @@ -151,32 +150,24 @@ public AnEndpoint()
}
}

class SampleHandler : IHandleMessages<SampleMessage>
class SampleHandler(Context testContext) : IHandleMessages<SampleMessage>
{
public SampleHandler(Context testContext) => this.testContext = testContext;

public Task Handle(SampleMessage message, IMessageHandlerContext context)
{
testContext.MessageReceived = true;

return Task.CompletedTask;
}

readonly Context testContext;
}

class CompleteTestMessageHandler : IHandleMessages<CompleteTestMessage>
class CompleteTestMessageHandler(Context testContext) : IHandleMessages<CompleteTestMessage>
{
public CompleteTestMessageHandler(Context context) => testContext = context;

public Task Handle(CompleteTestMessage message, IMessageHandlerContext context)
{
testContext.CompleteMessageReceived = true;

return Task.CompletedTask;
}

readonly Context testContext;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace NServiceBus.TransactionalSession
public static class RavenDbTransactionalSessionExtensions
{
public static NServiceBus.PersistenceExtensions<NServiceBus.RavenDBPersistence> EnableTransactionalSession(this NServiceBus.PersistenceExtensions<NServiceBus.RavenDBPersistence> persistenceExtensions) { }
public static NServiceBus.PersistenceExtensions<NServiceBus.RavenDBPersistence> EnableTransactionalSession(this NServiceBus.PersistenceExtensions<NServiceBus.RavenDBPersistence> persistenceExtensions, NServiceBus.TransactionalSession.TransactionalSessionOptions transactionalSessionOptions) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.TransactionalSession" Version="3.2.1" />
<PackageReference Include="NServiceBus.TransactionalSession" Version="3.3.0" />
<PackageReference Include="Particular.Packaging" Version="4.2.2" PrivateAssets="All" />
</ItemGroup>

Expand Down
Loading