-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from Particular/warn-not-native
Warn not native
- Loading branch information
Showing
3 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
...NServiceBus.SqlServer.AcceptanceTests/NativeTimeouts/When_configuring_delayed_delivery.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,121 @@ | ||
namespace NServiceBus.AcceptanceTests.NativeTimeouts | ||
{ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using Features; | ||
using Logging; | ||
using NUnit.Framework; | ||
using Transport.SQLServer; | ||
|
||
public class When_configuring_delayed_delivery : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_warn_when_timeoutmanager_is_configured_without_native_delayed_delivery() | ||
{ | ||
Requires.MessageDrivenPubSub(); | ||
|
||
var context = await Scenario.Define<ScenarioContext>() | ||
.WithEndpoint<EndpointWithTimeoutManagerAndNotNative>() | ||
.Done(c => c.EndpointsStarted) | ||
.Run(); | ||
|
||
Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup"); | ||
|
||
var log = context.Logs.Single(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`.")); | ||
Assert.AreEqual(LogLevel.Warn, log.Level); | ||
} | ||
|
||
[Test] | ||
public async Task Should_not_warn_when_timeoutmanager_and_native_delayed_delivery_are_both_configured() | ||
{ | ||
Requires.MessageDrivenPubSub(); | ||
|
||
var context = await Scenario.Define<ScenarioContext>() | ||
.WithEndpoint<EndpointWithTimeoutManagerAndNative>() | ||
.Done(c => c.EndpointsStarted) | ||
.Run(); | ||
|
||
Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup"); | ||
|
||
Assert.IsEmpty(context.Logs.Where(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`."))); | ||
} | ||
|
||
[Test] | ||
public async Task Should_not_warn_when_only_native_delayed_delivery_is_configured() | ||
{ | ||
Requires.MessageDrivenPubSub(); | ||
|
||
var context = await Scenario.Define<ScenarioContext>() | ||
.WithEndpoint<EndpointWithOnlyNative>() | ||
.Done(c => c.EndpointsStarted) | ||
.Run(); | ||
|
||
Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup"); | ||
|
||
Assert.IsEmpty(context.Logs.Where(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`."))); | ||
} | ||
|
||
[Test] | ||
public async Task Should_not_warn_when_both_native_delayed_delivery_and_timeoutmanager_is_configured_with_compatibility_disabled() | ||
{ | ||
Requires.MessageDrivenPubSub(); | ||
|
||
var context = await Scenario.Define<ScenarioContext>() | ||
.WithEndpoint<EndpointWithTimeoutManagerAndNativeEnabledButCompatibilityDisabled>() | ||
.Done(c => c.EndpointsStarted) | ||
.Run(); | ||
|
||
Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup"); | ||
|
||
Assert.IsEmpty(context.Logs.Where(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`."))); | ||
} | ||
|
||
public class EndpointWithTimeoutManagerAndNotNative : EndpointConfigurationBuilder | ||
{ | ||
public EndpointWithTimeoutManagerAndNotNative() | ||
{ | ||
EndpointSetup<DefaultServer>(config => config.EnableFeature<TimeoutManager>()); | ||
} | ||
} | ||
|
||
public class EndpointWithTimeoutManagerAndNative : EndpointConfigurationBuilder | ||
{ | ||
public EndpointWithTimeoutManagerAndNative() | ||
{ | ||
EndpointSetup<DefaultServer>(config => | ||
{ | ||
config.EnableFeature<TimeoutManager>(); | ||
config.UseTransport<SqlServerTransport>().UseNativeDelayedDelivery(); | ||
}); | ||
} | ||
} | ||
|
||
public class EndpointWithOnlyNative : EndpointConfigurationBuilder | ||
{ | ||
public EndpointWithOnlyNative() | ||
{ | ||
EndpointSetup<DefaultServer>(config => | ||
{ | ||
var settings = config.UseTransport<SqlServerTransport>().UseNativeDelayedDelivery(); | ||
settings.DisableTimeoutManagerCompatibility(); | ||
}); | ||
} | ||
} | ||
|
||
public class EndpointWithTimeoutManagerAndNativeEnabledButCompatibilityDisabled : EndpointConfigurationBuilder | ||
{ | ||
public EndpointWithTimeoutManagerAndNativeEnabledButCompatibilityDisabled() | ||
{ | ||
EndpointSetup<DefaultServer>(config => | ||
{ | ||
config.EnableFeature<TimeoutManager>(); | ||
|
||
var settings = config.UseTransport<SqlServerTransport>().UseNativeDelayedDelivery(); | ||
settings.DisableTimeoutManagerCompatibility(); | ||
}); | ||
} | ||
} | ||
} | ||
} |
23 changes: 20 additions & 3 deletions
23
src/NServiceBus.SqlServer/DelayedDelivery/DelayedDeliveryInfrastructure.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 |
---|---|---|
@@ -1,17 +1,34 @@ | ||
namespace NServiceBus.Transport.SQLServer | ||
{ | ||
using Features; | ||
using Logging; | ||
using Settings; | ||
|
||
static class DelayedDeliveryInfrastructure | ||
{ | ||
public static StartupCheckResult CheckForInvalidSettings(SettingsHolder settings) | ||
{ | ||
var sendOnlyEndpoint = settings.GetOrDefault<bool>("Endpoint.SendOnly"); | ||
if (sendOnlyEndpoint) | ||
var delayedDeliverySettings = settings.GetOrDefault<DelayedDeliverySettings>(); | ||
if (delayedDeliverySettings != null) | ||
{ | ||
return StartupCheckResult.Failed("Native delayed delivery is only supported for endpoints capable of receiving messages."); | ||
var sendOnlyEndpoint = settings.GetOrDefault<bool>("Endpoint.SendOnly"); | ||
if (sendOnlyEndpoint) | ||
{ | ||
return StartupCheckResult.Failed("Native delayed delivery is only supported for endpoints capable of receiving messages."); | ||
} | ||
} | ||
else | ||
{ | ||
var timeoutManagerEnabled = settings.IsFeatureActive(typeof(TimeoutManager)); | ||
if (timeoutManagerEnabled) | ||
{ | ||
Logger.Warn("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`."); | ||
} | ||
} | ||
|
||
return StartupCheckResult.Success; | ||
} | ||
|
||
static ILog Logger = LogManager.GetLogger("DelayedDeliveryInfrastructure"); | ||
} | ||
} |
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