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
@@ -0,0 +1,47 @@
using System.Diagnostics;
using IntegrationTests;
using JasperFx.Core;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Wolverine;
using Wolverine.ComplianceTests.Compliance;
using Wolverine.Postgresql;
using Wolverine.Tracking;

namespace PostgresqlTests.Bugs;

public class Bug_1516_get_the_schema_names_right : PostgresqlContext
{
[Fact]
public async Task get_the_bleeping_schema_names_right()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(o =>
{
o.PersistMessagesWithPostgresql(Servers.PostgresConnectionString, "ops")
.SchemaName("ops")
.EnableMessageTransport(x => x.TransportSchemaName("queues").AutoProvision());

o.PublishAllMessages().ToPostgresqlQueue("outbound");
o.ListenToPostgresqlQueue("outbound");
}).StartAsync();

var tracked = await host.TrackActivity().IncludeExternalTransports().Timeout(30.Seconds())
.SendMessageAndWaitAsync(new TraceMessage { Name = "Tom Landry" });

tracked.Executed.SingleMessage<TraceMessage>().Name.ShouldBe("Tom Landry");
}
}

public class TraceMessage
{
public string Name { get; set; }
}

public class TraceHandler
{
public void Handle(TraceMessage message)
{
Debug.WriteLine("Got message with " + message.Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ public interface IPostgresqlBackedPersistence
/// </summary>
internal class PostgresqlBackedPersistence : IPostgresqlBackedPersistence, IWolverineExtension
{
public PostgresqlBackedPersistence(DurabilitySettings settings)
private readonly WolverineOptions _options;

public PostgresqlBackedPersistence(DurabilitySettings settings, WolverineOptions options)
{
_options = options;
EnvelopeStorageSchemaName = settings.MessageStorageSchemaName ?? "wolverine";
}

internal bool AlreadyIncluded { get; set; }

// Gotta have one or the other. Maybe even just DbDataSource here
public NpgsqlDataSource? DataSource { get; set; }
Expand Down Expand Up @@ -227,7 +232,17 @@ public IPostgresqlBackedPersistence EnableMessageTransport(Action<PostgresqlPers
{
if (configure != null)
{
_transportConfigurations.Add(configure);
if (AlreadyIncluded)
{
var transport = _options.Transports.GetOrCreate<PostgresqlTransport>();

var expression = new PostgresqlPersistenceExpression(transport, _options);
configure(expression);
}
else
{
_transportConfigurations.Add(configure);
}
}
return this;
}
Expand All @@ -240,6 +255,7 @@ IPostgresqlBackedPersistence IPostgresqlBackedPersistence.OverrideAutoCreateReso

IPostgresqlBackedPersistence IPostgresqlBackedPersistence.SchemaName(string schemaName)
{
schemaName.AssertValidSchemaName();
EnvelopeStorageSchemaName = schemaName;
return this;
}
Expand Down Expand Up @@ -305,4 +321,6 @@ IPostgresqlBackedPersistence IPostgresqlBackedPersistence.UseMasterTableTenancy(
/// This is any default connection strings by tenant that should be loaded at start up time
/// </summary>
public StaticConnectionStringSource? TenantConnections { get; set; }


}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ internal static void AssertValidSchemaName(this string schemaName)
public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this WolverineOptions options, string connectionString,
string? schemaName = null)
{
var persistence = new PostgresqlBackedPersistence(options.Durability)
var persistence = new PostgresqlBackedPersistence(options.Durability, options)
{
ConnectionString = connectionString,
AlreadyIncluded = true
};

if (schemaName.IsNotEmpty())
Expand All @@ -62,7 +63,7 @@ public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this Wo
public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this WolverineOptions options, NpgsqlDataSource dataSource,
string? schemaName = null)
{
var persistence = new PostgresqlBackedPersistence(options.Durability)
var persistence = new PostgresqlBackedPersistence(options.Durability, options)
{
DataSource = dataSource
};
Expand All @@ -75,6 +76,8 @@ public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this Wo

options.Include(persistence);

persistence.AlreadyIncluded = true;

return persistence;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public async ValueTask ConfigureAsync(IWolverineRuntime runtime)
store.AddTable(queue.ScheduledTable);
}

MessageStorageSchemaName = store.SchemaName;

Store = store;
}
else if (runtime.Storage is MultiTenantedMessageStore tenants)
Expand All @@ -57,6 +59,8 @@ await source.ConfigureDatabaseAsync(messageStore =>
{
if (messageStore is PostgresqlMessageStore s)
{
MessageStorageSchemaName = s.SchemaName;

foreach (var queue in Queues)
{
s.AddTable(queue.QueueTable);
Expand Down
Loading