public async Task Should_handle_from_service_bus_queue() { var fakeHandler = A.Fake <ITestPumpCallback>(); A.CallTo(() => fakeHandler.Handle(A <TransportMessage> .Ignored, A <IEndpoint> .Ignored)).Returns(Task.CompletedTask); var pump = new AzureServiceBusMessagePump(fakeHandler.Handle, IntegrationTestFixture.QueueEndpoint, null, new AzureServiceBusMessagePumpSettings() { MaxConcurrentHandlers = 1, MaxCompletionImmediateRetry = 1 }); await pump.StartAsync(CancellationToken.None); var message = new TestMessage() { Id = Guid.NewGuid(), Description = "Test Handle Queue", MessageDate = DateTime.Now, Name = "Queue", }; var messageBytes = IntegrationTestFixture.Serialize(message); await IntegrationTestFixture.WriteToQueue(IntegrationTestFixture.QueueEndpoint, message.MessageType, messageBytes, null); await Task.Delay(3000); A.CallTo(() => fakeHandler.Handle( A <TransportMessage> .That.Matches(x => x.MessageTypeIdentifier.Equals(message.MessageType) && x.Data.SequenceEqual(messageBytes) ), A <IEndpoint> .That.Matches(x => x.Equals(IntegrationTestFixture.QueueEndpoint)) )).MustHaveHappenedOnceOrMore(); await pump.StopAsync(); }
public async Task Should_expire_on_service_bus_queue() { var message = new TestMessage() { Id = Guid.NewGuid(), Description = "Test Expire Queue", MessageDate = DateTime.Now, Name = "Queue Delay", }; var messageBytes = IntegrationTestFixture.Serialize(message); var fakeHandler = A.Fake <ITestMessageHandler>(); A.CallTo(() => fakeHandler.HandleMessage(A <Message> .Ignored, A <CancellationToken> .Ignored)).Returns(Task.CompletedTask); A.CallTo(() => fakeHandler.HandleException(A <ExceptionReceivedEventArgs> .Ignored)).Returns(Task.CompletedTask); var meta = new MessageMetaData(expiresAtUtc: DateTime.UtcNow.AddSeconds(10), messageId: message.Id.ToString()); await IntegrationTestFixture.Transport.Dispatch(message.MessageType, messageBytes, IntegrationTestFixture.QueueEndpoint, meta); await Task.Delay(12000); var client = IntegrationTestFixture.ReadFromQueue(IntegrationTestFixture.QueueEndpoint, fakeHandler); await Task.Delay(3000); A.CallTo(() => fakeHandler.HandleMessage( A <Message> .That.Matches(x => x.MessageId.Equals(message.Id.ToString()) && x.Body.SequenceEqual(messageBytes) ), A <CancellationToken> .Ignored )).MustNotHaveHappened(); await client.CloseAsync(); }
public async Task Should_dispatch_to_service_bus_topic() { var message = new TestMessage() { Description = "Test topic", Id = Guid.NewGuid(), MessageDate = DateTime.Now, Name = "Topic", }; var messageBytes = IntegrationTestFixture.Serialize(message); var fakeHandler = A.Fake <ITestMessageHandler>(); A.CallTo(() => fakeHandler.HandleMessage(A <Message> .Ignored, A <CancellationToken> .Ignored)).Returns(Task.CompletedTask); A.CallTo(() => fakeHandler.HandleException(A <ExceptionReceivedEventArgs> .Ignored)).Returns(Task.CompletedTask); var client = IntegrationTestFixture.ReadFromTopicSubscription(IntegrationTestFixture.SubscriptionEndpoint, fakeHandler); await IntegrationTestFixture.Transport.Dispatch(message.MessageType, messageBytes, IntegrationTestFixture.TopicEndpoint, new MessageMetaData(messageId : message.Id.ToString())); await Task.Delay(1000); A.CallTo(() => fakeHandler.HandleMessage( A <Message> .That.Matches(x => x.MessageId.Equals(message.Id.ToString()) && x.Body.SequenceEqual(messageBytes) ), A <CancellationToken> .Ignored )).MustHaveHappenedOnceOrMore(); await client.CloseAsync(); }
public override async Task InitializeAsync() { await base.InitializeAsync(); await IntegrationTestFixture.ClearQueue(IntegrationTestFixture.QueueEndpoint); }
public async Task Should_defer_and_queue_control_message() { var fakeHandler = A.Fake <ITestPumpCallback>(); A.CallTo(() => fakeHandler.Handle(A <TransportMessage> .Ignored, A <IEndpoint> .Ignored)) .Throws <Exception>().Twice() .Then.Returns(Task.CompletedTask); var deferRecoverabilityProvider = new AzureServiceBusDeferRecoverabilityProvider( new ConstantRetryStrategy(3) ); var wrappedRecoverability = A.Fake <IAzureServiceBusRecoverabilityProvider>(x => x.Wrapping(deferRecoverabilityProvider)); var pump = new AzureServiceBusMessagePump(fakeHandler.Handle, IntegrationTestFixture.QueueEndpoint, null, new AzureServiceBusMessagePumpSettings() { MaxConcurrentHandlers = 1, }, wrappedRecoverability ); await pump.StartAsync(CancellationToken.None); var message = new TestMessage() { Id = Guid.NewGuid(), Description = "Test Handle Deferred Retry", MessageDate = DateTime.Now, Name = "Queue Deferred Retry", }; var messageBytes = IntegrationTestFixture.Serialize(message); await IntegrationTestFixture.WriteToQueue(IntegrationTestFixture.QueueEndpoint, message.MessageType, messageBytes, null); await Task.Delay(11000); ///This doesn't seem to work because the Message may be getting reused so the value changes ////recover should have deferred and scheduled recover control message //A.CallTo(() => wrappedRecoverability.OnPreHandle( // A<RecoverabilityContext>.That.Matches(x => // x.Message.Label == ("ControlMessage.Recover") // ) //)).MustHaveHappenedTwiceExactly(); //handled exception by calling recover A.CallTo(() => wrappedRecoverability.Recover( A <RecoverabilityContext> .That.Matches(x => x.Message.Body.SequenceEqual(messageBytes) && x.Endpoint == IntegrationTestFixture.QueueEndpoint && !x.TempData.ContainsKey("ControlMessage") ) )).MustHaveHappenedOnceExactly(); A.CallTo(() => wrappedRecoverability.Recover( A <RecoverabilityContext> .That.Matches(x => x.Message.Body.SequenceEqual(messageBytes) && x.Endpoint == IntegrationTestFixture.QueueEndpoint && x.TempData.ContainsKey("ControlMessage") ) )).MustHaveHappenedOnceExactly(); // should have been called 2 times with failure then again with success of deferred message A.CallTo(() => fakeHandler.Handle( A <TransportMessage> .That.Matches(x => x.MessageTypeIdentifier.Equals(message.MessageType) && x.Data.SequenceEqual(messageBytes) ), A <IEndpoint> .That.Matches(x => x.Equals(IntegrationTestFixture.QueueEndpoint)) )).MustHaveHappened(3, Times.Exactly); await pump.StopAsync(); }