-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Processing a control message causes the outbox to throw a null refere…
…nce exception (#738) (#754) * Reproduce the bug * Cleanup * Improve requesting partition key not to be mapped * Fix bug * Move test and align configs * Flip around logic * Move the test file * Add tests and checks for missing table name * Share table name check test and fix validation * Make missing partition key test shared as well * Move to extension method * More succinct check --------- Co-authored-by: danielmarbach <[email protected]> # Conflicts: # src/LogicalOutbox.StorageTable.AcceptanceTests/ConfigureAzureTablePersistence.cs # src/NServiceBus.Persistence.AzureTable/Outbox/LogicalOutboxBehavior.cs # src/NServiceBus.Persistence.AzureTable/Outbox/OutboxPersister.cs # src/PhysicalOutbox.StorageTable.AcceptanceTests/ConfigureAzureTablePersistence.cs Co-authored-by: Andreas Öhlund <[email protected]>
- Loading branch information
1 parent
556b6c2
commit 8735632
Showing
11 changed files
with
335 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
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.Persistence.AzureTable/Outbox/SetAsDispatchedHolderExtensions.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 @@ | ||
#nullable enable | ||
|
||
namespace NServiceBus.Persistence.AzureTable | ||
{ | ||
using System; | ||
|
||
static class SetAsDispatchedHolderExtensions | ||
{ | ||
public static void ThrowIfTableClientIsNotSet(this SetAsDispatchedHolder setAsDispatchedHolder) | ||
{ | ||
if (setAsDispatchedHolder.TableHolder is { Table: not null }) | ||
{ | ||
return; | ||
} | ||
|
||
throw new Exception($"For the outbox to work a table name must be configured. Either configure a default one using '{nameof(ConfigureAzureStorage.DefaultTable)}' or set one via a behavior calling `context.Extensions.Set(new {nameof(TableInformation)}(\"SomeTableName\"))`"); | ||
} | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
src/PhysicalOutbox.StorageTable.AcceptanceTests/When_using_outbox_control_message.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,82 @@ | ||
namespace NServiceBus.AcceptanceTests | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using NServiceBus.AcceptanceTesting.Support; | ||
using NServiceBus.Features; | ||
using NServiceBus.Pipeline; | ||
using NServiceBus.Routing; | ||
using NServiceBus.Transport; | ||
using NServiceBus.Unicast.Transport; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class When_using_outbox_control_message : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_work() | ||
{ | ||
var runSettings = new RunSettings(); | ||
runSettings.DoNotRegisterDefaultPartitionKeyProvider(); | ||
|
||
var context = await Scenario.Define<Context>() | ||
.WithEndpoint<Endpoint>() | ||
.Done(c => c.ProcessedControlMessage) | ||
.Run(runSettings) | ||
.ConfigureAwait(false); | ||
|
||
Assert.True(context.ProcessedControlMessage); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool ProcessedControlMessage { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() => | ||
EndpointSetup<DefaultServer>((config, runDescriptor) => | ||
{ | ||
config.EnableOutbox(); | ||
config.ConfigureTransport().TransportTransactionMode = TransportTransactionMode.ReceiveOnly; | ||
config.RegisterStartupTask<ControlMessageSender>(); | ||
config.Pipeline.Register(new ControlMessageBehavior(runDescriptor.ScenarioContext as Context), "Checks that the control message was processed successfully"); | ||
}); | ||
|
||
class ControlMessageSender : FeatureStartupTask | ||
{ | ||
public ControlMessageSender(IMessageDispatcher dispatcher) => this.dispatcher = dispatcher; | ||
|
||
protected override Task OnStart(IMessageSession session, CancellationToken cancellationToken = default) | ||
{ | ||
var controlMessage = ControlMessageFactory.Create(MessageIntent.Subscribe); | ||
var messageOperation = new TransportOperation(controlMessage, new UnicastAddressTag(AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(Endpoint)))); | ||
|
||
return dispatcher.Dispatch(new TransportOperations(messageOperation), new TransportTransaction(), cancellationToken); | ||
} | ||
|
||
protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => Task.CompletedTask; | ||
|
||
readonly IMessageDispatcher dispatcher; | ||
} | ||
|
||
class ControlMessageBehavior : Behavior<IIncomingPhysicalMessageContext> | ||
{ | ||
public ControlMessageBehavior(Context testContext) => this.testContext = testContext; | ||
|
||
public override async Task Invoke(IIncomingPhysicalMessageContext context, Func<Task> next) | ||
{ | ||
await next(); | ||
|
||
testContext.ProcessedControlMessage = true; | ||
} | ||
|
||
readonly Context testContext; | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/SharedAcceptanceTests.RequirePartitionKey/DoNotRegisterDefaultPartitionKeyProvider.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,9 @@ | ||
namespace NServiceBus.AcceptanceTests | ||
{ | ||
class DoNotRegisterDefaultPartitionKeyProvider | ||
{ | ||
public DoNotRegisterDefaultPartitionKeyProvider() | ||
{ | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/SharedAcceptanceTests.RequirePartitionKey/DoNotRegisterDefaultTableNameProvider.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,9 @@ | ||
namespace NServiceBus.AcceptanceTests | ||
{ | ||
class DoNotRegisterDefaultTableNameProvider | ||
{ | ||
public DoNotRegisterDefaultTableNameProvider() | ||
{ | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/SharedAcceptanceTests.RequirePartitionKey/RunSettingsExtensionsRequirePartitionKey.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,13 @@ | ||
namespace NServiceBus.AcceptanceTests | ||
{ | ||
using NServiceBus.AcceptanceTesting.Support; | ||
|
||
public static partial class RunSettingsExtensions | ||
{ | ||
public static void DoNotRegisterDefaultPartitionKeyProvider(this RunSettings runSettings) => | ||
runSettings.Set(new DoNotRegisterDefaultPartitionKeyProvider()); | ||
|
||
public static void DoNotRegisterDefaultTableNameProvider(this RunSettings runSettings) => | ||
runSettings.Set(new DoNotRegisterDefaultTableNameProvider()); | ||
} | ||
} |
Oops, something went wrong.