-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to configure whether to use the native timeout manager
- Loading branch information
1 parent
6385d6a
commit 1862883
Showing
7 changed files
with
213 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.WindowsAzure.Storage; | ||
using NUnit.Framework; | ||
using Rebus.Activation; | ||
using Rebus.AzureStorage.Transport; | ||
using Rebus.Config; | ||
using Rebus.Logging; | ||
using Rebus.Persistence.InMem; | ||
using Rebus.Tests.Contracts; | ||
using Rebus.Tests.Contracts.Extensions; | ||
using Rebus.Timeouts; | ||
// ReSharper disable ArgumentsStyleNamedExpression | ||
|
||
namespace Rebus.AzureStorage.Tests | ||
{ | ||
[TestFixture] | ||
public class AlternativeTimeoutManager : FixtureBase | ||
{ | ||
static readonly string QueueName = TestConfig.GetName("input"); | ||
static readonly string TimeoutManagerQueueName = TestConfig.GetName("timeouts"); | ||
|
||
BuiltinHandlerActivator _activator; | ||
CloudStorageAccount _storageAccount; | ||
|
||
protected override void SetUp() | ||
{ | ||
_storageAccount = CloudStorageAccount.Parse(AzureStorageFactoryBase.ConnectionString); | ||
|
||
new AzureStorageQueuesTransport(_storageAccount, QueueName, new NullLoggerFactory(), new AzureStorageQueuesTransportOptions()).PurgeInputQueue(); | ||
new AzureStorageQueuesTransport(_storageAccount, TimeoutManagerQueueName, new NullLoggerFactory(), new AzureStorageQueuesTransportOptions()).PurgeInputQueue(); | ||
|
||
_activator = new BuiltinHandlerActivator(); | ||
|
||
Using(_activator); | ||
} | ||
|
||
[Test] | ||
public async Task CanUseAlternativeTimeoutManager() | ||
{ | ||
var gotTheString = new ManualResetEvent(false); | ||
|
||
_activator.Handle<string>(async str => | ||
{ | ||
Console.WriteLine($"Received string: '{str}'"); | ||
gotTheString.Set(); | ||
}); | ||
|
||
var bus = Configure.With(_activator) | ||
.Transport(t => | ||
{ | ||
var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; | ||
t.UseAzureStorageQueues(_storageAccount, QueueName, options: options); | ||
}) | ||
.Timeouts(t => t.Register(c => new InMemoryTimeoutManager())) | ||
.Start(); | ||
|
||
await bus.DeferLocal(TimeSpan.FromSeconds(5), "hej med dig min ven!!!!!"); | ||
|
||
gotTheString.WaitOrDie(TimeSpan.FromSeconds(10), "Did not receive the string withing 10 s timeout"); | ||
} | ||
|
||
[Test] | ||
public async Task CanUseDedicatedAlternativeTimeoutManager() | ||
{ | ||
// start the timeout manager | ||
Configure.With(Using(new BuiltinHandlerActivator())) | ||
.Transport(t => | ||
{ | ||
var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; | ||
t.UseAzureStorageQueues(_storageAccount, TimeoutManagerQueueName, options: options); | ||
}) | ||
.Timeouts(t => t.Register(c => new InMemoryTimeoutManager())) | ||
.Start(); | ||
|
||
var gotTheString = new ManualResetEvent(false); | ||
|
||
_activator.Handle<string>(async str => | ||
{ | ||
Console.WriteLine($"Received string: '{str}'"); | ||
gotTheString.Set(); | ||
}); | ||
|
||
var bus = Configure.With(_activator) | ||
.Transport(t => | ||
{ | ||
var options = new AzureStorageQueuesTransportOptions { UseNativeDeferredMessages = false }; | ||
t.UseAzureStorageQueues(_storageAccount, QueueName, options: options); | ||
}) | ||
.Timeouts(t => t.UseExternalTimeoutManager(TimeoutManagerQueueName)) | ||
.Start(); | ||
|
||
await bus.DeferLocal(TimeSpan.FromSeconds(5), "hej med dig min ven!!!!!"); | ||
|
||
gotTheString.WaitOrDie(TimeSpan.FromSeconds(10), "Did not receive the string withing 10 s timeout"); | ||
|
||
//// don't dispose too quickly, or else we'll get annoying errors in the log | ||
//await Task.Delay(TimeSpan.FromSeconds(0.5)); | ||
} | ||
} | ||
} |
36 changes: 1 addition & 35 deletions
36
Rebus.AzureStorage.Tests/Transport/AzureStorageQueuesTransportBasicSendReceive.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,45 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Rebus.AzureStorage.Transport; | ||
using Rebus.Messages; | ||
using NUnit.Framework; | ||
using Rebus.Tests.Contracts.Transports; | ||
using Rebus.Time; | ||
#pragma warning disable 1998 | ||
|
||
namespace Rebus.AzureStorage.Tests.Transport | ||
{ | ||
[TestFixture] | ||
public class AzureStorageQueuesTransportBasicSendReceive : BasicSendReceive<AzureStorageQueuesTransportFactory> | ||
{ | ||
[Test] | ||
public async Task GetQueueVisibilityDelayOrNull_NeverReturnsNegativeTimespans() | ||
{ | ||
var sendInstant = DateTimeOffset.Now; | ||
var deferDate = sendInstant.AddMilliseconds(-350); | ||
RebusTimeMachine.FakeIt(sendInstant); | ||
var result = AzureStorageQueuesTransport.GetQueueVisibilityDelayOrNull(new Dictionary<string, string> | ||
{ | ||
{Headers.DeferredUntil, deferDate.ToString("O")} | ||
}); | ||
RebusTimeMachine.Reset(); | ||
Assert.Null(result); | ||
|
||
} | ||
[Test] | ||
public async Task GetQueueVisibilityDelayOrNull_StillReturnsPositiveTimespans() | ||
{ | ||
var sendInstant = DateTimeOffset.Now; | ||
var deferDate = sendInstant.AddMilliseconds(350); | ||
RebusTimeMachine.FakeIt(sendInstant); | ||
var result = AzureStorageQueuesTransport.GetQueueVisibilityDelayOrNull(new Dictionary<string, string> | ||
{ | ||
{Headers.DeferredUntil, deferDate.ToString("O")} | ||
}); | ||
RebusTimeMachine.Reset(); | ||
Assert.AreEqual(result, TimeSpan.FromMilliseconds(350)); | ||
|
||
} | ||
} | ||
} |
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
Oops, something went wrong.