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,13 +1,12 @@
namespace NServiceBus.Transport.PostgreSql.AcceptanceTests
{
using NServiceBus.AcceptanceTests.EndpointTemplates;
using PostgreSql;
namespace NServiceBus.Transport.PostgreSql.AcceptanceTests;

using NServiceBus.AcceptanceTests.EndpointTemplates;
using PostgreSql;

public class CustomizedServer : DefaultServer
public class CustomizedServer : DefaultServer
{
public CustomizedServer(PostgreSqlTransport transport)
{
public CustomizedServer(PostgreSqlTransport transport)
{
TransportConfiguration = new ConfigureEndpointPostgreSqlTransport(transport);
}
TransportConfiguration = new ConfigureEndpointPostgreSqlTransport(transport);
}
}
Original file line number Diff line number Diff line change
@@ -1,92 +1,91 @@
namespace NServiceBus.Transport.SqlServer.AcceptanceTests.MultiSchema
{
using System;
using System.Threading.Tasks;
using AcceptanceTesting;
using NServiceBus.AcceptanceTests;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NUnit.Framework;
namespace NServiceBus.Transport.SqlServer.AcceptanceTests.MultiSchema;

using System;
using System.Threading.Tasks;
using AcceptanceTesting;
using NServiceBus.AcceptanceTests;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NUnit.Framework;

public class When_custom_schema_configured_for_error_queue : NServiceBusAcceptanceTest
public class When_custom_schema_configured_for_error_queue : NServiceBusAcceptanceTest
{
[Test]
public async Task Error_should_be_sent_to_table_in_configured_schema()
{
[Test]
public async Task Error_should_be_sent_to_table_in_configured_schema()
{
var ctx = await Scenario.Define<Context>()
.WithEndpoint<Sender>(b =>
{
b.DoNotFailOnErrorMessages();
b.When((bus, c) => bus.SendLocal(new Message()));
})
.WithEndpoint<ErrorSpy>()
.Done(c => c.FailedMessageProcessed)
.Run();
var ctx = await Scenario.Define<Context>()
.WithEndpoint<Sender>(b =>
{
b.DoNotFailOnErrorMessages();
b.When((bus, c) => bus.SendLocal(new Message()));
})
.WithEndpoint<ErrorSpy>()
.Done(c => c.FailedMessageProcessed)
.Run();

Assert.That(ctx.FailedMessageProcessed, Is.True, "Message should be moved to error queue in custom schema");
}
Assert.That(ctx.FailedMessageProcessed, Is.True, "Message should be moved to error queue in custom schema");
}

public class Context : ScenarioContext
{
public bool FailedMessageProcessed { get; set; }
}
public class Context : ScenarioContext
{
public bool FailedMessageProcessed { get; set; }
}

public class Sender : EndpointConfigurationBuilder
public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
public Sender()
EndpointSetup<DefaultServer>(c =>
{
EndpointSetup<DefaultServer>(c =>
{
var errorSpyName = AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(ErrorSpy));
var errorSpyName = AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(ErrorSpy));

c.SendFailedMessagesTo(errorSpyName);
c.SendFailedMessagesTo(errorSpyName);

c.Recoverability()
.Immediate(i => i.NumberOfRetries(0))
.Delayed(d => d.NumberOfRetries(0));
c.Recoverability()
.Immediate(i => i.NumberOfRetries(0))
.Delayed(d => d.NumberOfRetries(0));

var transport = c.ConfigureSqlServerTransport();
transport.Schema.UseSchemaForQueue(errorSpyName, ErrorSpySchema);
});
}
var transport = c.ConfigureSqlServerTransport();
transport.Schema.UseSchemaForQueue(errorSpyName, ErrorSpySchema);
});
}

class Handler : IHandleMessages<Message>
class Handler : IHandleMessages<Message>
{
public Task Handle(Message message, IMessageHandlerContext context)
{
public Task Handle(Message message, IMessageHandlerContext context)
{
throw new Exception("Simulated exception");
}
throw new Exception("Simulated exception");
}
}
}

public class ErrorSpy : EndpointConfigurationBuilder
public class ErrorSpy : EndpointConfigurationBuilder
{
public ErrorSpy()
{
public ErrorSpy()
EndpointSetup<DefaultServer>(c =>
{
EndpointSetup<DefaultServer>(c =>
{
c.ConfigureSqlServerTransport().DefaultSchema = ErrorSpySchema;
});
}
c.ConfigureSqlServerTransport().DefaultSchema = ErrorSpySchema;
});
}

class Handler : IHandleMessages<Message>
class Handler : IHandleMessages<Message>
{
readonly Context scenarioContext;
public Handler(Context scenarioContext)
{
readonly Context scenarioContext;
public Handler(Context scenarioContext)
{
this.scenarioContext = scenarioContext;
}
this.scenarioContext = scenarioContext;
}

public Task Handle(Message message, IMessageHandlerContext context)
{
scenarioContext.FailedMessageProcessed = true;
public Task Handle(Message message, IMessageHandlerContext context)
{
scenarioContext.FailedMessageProcessed = true;

return Task.FromResult(0);
}
return Task.FromResult(0);
}
}
}

public class Message : ICommand { }
public class Message : ICommand { }

const string ErrorSpySchema = "receiver";
}
const string ErrorSpySchema = "receiver";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="3.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="10.0.0-alpha.21" GeneratePathProperty="true" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="10.0.0-alpha.24" GeneratePathProperty="true" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.11.2" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,93 +1,92 @@
namespace NServiceBus.AcceptanceTests
namespace NServiceBus.AcceptanceTests;

using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using AcceptanceTesting;
using AcceptanceTesting.Customization;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;

/// <summary>
/// Base class for all the NSB test that sets up our conventions
/// </summary>
[TestFixture]
public abstract class NServiceBusAcceptanceTest
{
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using AcceptanceTesting;
using AcceptanceTesting.Customization;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;

/// <summary>
/// Base class for all the NSB test that sets up our conventions
/// </summary>
[TestFixture]
public abstract class NServiceBusAcceptanceTest
[SetUp]
public void SetUp()
{
[SetUp]
public void SetUp()
Conventions.EndpointNamingConvention = t =>
{
Conventions.EndpointNamingConvention = t =>
{
var classAndEndpoint = t.FullName.Split('.').Last();
var classAndEndpoint = t.FullName.Split('.').Last();

var testName = classAndEndpoint.Split('+').First();
var testName = classAndEndpoint.Split('+').First();

testName = testName.Replace("When_", "");
testName = testName.Replace("When_", "");

var endpointBuilder = classAndEndpoint.Split('+').Last();
var endpointBuilder = classAndEndpoint.Split('+').Last();

testName = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(testName);
testName = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(testName);

testName = testName.Replace("_", "");
testName = testName.Replace("_", "");

var fullTestName = testName + "#" + endpointBuilder;
var fullTestName = testName + "#" + endpointBuilder;

// Max length for table name is 63. We need to reserve space for the:
// - ".delayed" - suffix (8)
// - "_Seq_seq" suffix for auto-created sequence backing up the Seq column (8)
// - hashcode (8)
// In summary, we can use 63-8-8-8=39
var charactersToConsider = int.Min(fullTestName.Length, 39);
// Max length for table name is 63. We need to reserve space for the:
// - ".delayed" - suffix (8)
// - "_Seq_seq" suffix for auto-created sequence backing up the Seq column (8)
// - hashcode (8)
// In summary, we can use 63-8-8-8=39
var charactersToConsider = int.Min(fullTestName.Length, 39);

return $"{fullTestName.Substring(0, charactersToConsider)}{CreateDeterministicHash(fullTestName):X8}";
};
}
return $"{fullTestName.Substring(0, charactersToConsider)}{CreateDeterministicHash(fullTestName):X8}";
};
}

public static uint CreateDeterministicHash(string input)
public static uint CreateDeterministicHash(string input)
{
using (var provider = MD5.Create())
{
using (var provider = MD5.Create())
{
var inputBytes = Encoding.Default.GetBytes(input);
var hashBytes = provider.ComputeHash(inputBytes);
// generate a guid from the hash:
return BitConverter.ToUInt32(hashBytes, 0) % 1000000;
}
var inputBytes = Encoding.Default.GetBytes(input);
var hashBytes = provider.ComputeHash(inputBytes);
// generate a guid from the hash:
return BitConverter.ToUInt32(hashBytes, 0) % 1000000;
}
}

[TearDown]
public void TearDown()
[TearDown]
public void TearDown()
{
if (!TestExecutionContext.CurrentContext.TryGetRunDescriptor(out var runDescriptor))
{
if (!TestExecutionContext.CurrentContext.TryGetRunDescriptor(out var runDescriptor))
{
return;
}
return;
}

var scenarioContext = runDescriptor.ScenarioContext;
var scenarioContext = runDescriptor.ScenarioContext;

if (Environment.GetEnvironmentVariable("CI") != "true" || Environment.GetEnvironmentVariable("VERBOSE_TEST_LOGGING")?.ToLower() == "true")
{
TestContext.Out.WriteLine($@"Test settings:
if (Environment.GetEnvironmentVariable("CI") != "true" || Environment.GetEnvironmentVariable("VERBOSE_TEST_LOGGING")?.ToLower() == "true")
{
TestContext.Out.WriteLine($@"Test settings:
{string.Join(Environment.NewLine, runDescriptor.Settings.Select(setting => $" {setting.Key}: {setting.Value}"))}");

TestContext.Out.WriteLine($@"Context:
TestContext.Out.WriteLine($@"Context:
{string.Join(Environment.NewLine, scenarioContext.GetType().GetProperties().Select(p => $"{p.Name} = {p.GetValue(scenarioContext, null)}"))}");
}
}

if (TestExecutionContext.CurrentContext.CurrentResult.ResultState == ResultState.Failure || TestExecutionContext.CurrentContext.CurrentResult.ResultState == ResultState.Error)
if (TestExecutionContext.CurrentContext.CurrentResult.ResultState == ResultState.Failure || TestExecutionContext.CurrentContext.CurrentResult.ResultState == ResultState.Error)
{
TestContext.Out.WriteLine(string.Empty);
TestContext.Out.WriteLine($"Log entries (log level: {scenarioContext.LogLevel}):");
TestContext.Out.WriteLine("--- Start log entries ---------------------------------------------------");
foreach (var logEntry in scenarioContext.Logs)
{
TestContext.Out.WriteLine(string.Empty);
TestContext.Out.WriteLine($"Log entries (log level: {scenarioContext.LogLevel}):");
TestContext.Out.WriteLine("--- Start log entries ---------------------------------------------------");
foreach (var logEntry in scenarioContext.Logs)
{
TestContext.Out.WriteLine($"{logEntry.Timestamp:T} {logEntry.Level} {logEntry.Endpoint ?? TestContext.CurrentContext.Test.Name}: {logEntry.Message}");
}
TestContext.Out.WriteLine("--- End log entries ---------------------------------------------------");
TestContext.Out.WriteLine($"{logEntry.Timestamp:T} {logEntry.Level} {logEntry.Endpoint ?? TestContext.CurrentContext.Test.Name}: {logEntry.Message}");
}
TestContext.Out.WriteLine("--- End log entries ---------------------------------------------------");
}
}
}
}
Loading
Loading