public async Task CompleteProcessingMessageAsync_Failure_PropagatesException()
        {
            _options.AutoComplete = false;

            Message        message           = new Message();
            var            functionException = new InvalidOperationException("Kaboom!");
            FunctionResult result            = new FunctionResult(functionException);
            var            ex = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await _processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
            });

            Assert.Same(functionException, ex);
        }
        public void CompleteProcessingMessageAsync_Failure_PropagatesException()
        {
            ServiceBusReceivedMessage message = ServiceBusModelFactory.ServiceBusReceivedMessage();
            var            functionException  = new InvalidOperationException("Kaboom!");
            FunctionResult result             = new FunctionResult(functionException);
            var            client             = new ServiceBusClient("Endpoint = sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=");
            var            actions            = new ServiceBusMessageActions(client.CreateReceiver("test-entity"));
            var            ex = Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await _processor.CompleteProcessingMessageAsync(actions, message, result, CancellationToken.None);
            });

            Assert.AreSame(functionException, ex);
        }
        public async Task CompleteProcessingMessageAsync_Success_CompletesMessage_WhenAutoCompleteFalse()
        {
            _options.AutoComplete = false;

            Message        message = new Message();
            FunctionResult result  = new FunctionResult(true);
            var            ex      = await Assert.ThrowsAsync <FormatException>(async() =>
            {
                await _processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
            });

            // The service bus APIs aren't unit testable, so in this test suite
            // we rely on exception stacks to verify APIs are called as expected.
            // this verifies that we initiated the completion
            Assert.True(ex.ToString().Contains("Microsoft.Azure.ServiceBus.Core.MessageReceiver.OnCompleteAsync"));
        }
Exemple #4
0
        public async Task CompleteProcessingMessageAsync_DefaultOnMessageOptions()
        {
            MessageProcessor processor = new MessageProcessor(new OnMessageOptions());

            BrokeredMessage message = new BrokeredMessage();
            FunctionResult  result  = new FunctionResult(true);
            await processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
        }
        public async Task CompleteProcessingMessageAsync_DefaultOnMessageOptions()
        {
            MessageProcessor processor = new MessageProcessor(new OnMessageOptions());

            BrokeredMessage message = new BrokeredMessage();
            FunctionResult result = new FunctionResult(true);
            await processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
        }
Exemple #6
0
        internal async Task ProcessMessageAsync(BrokeredMessage message, CancellationToken cancellationToken)
        {
            if (!await _messageProcessor.BeginProcessingMessageAsync(message, cancellationToken))
            {
                return;
            }

            FunctionResult result = await _triggerExecutor.ExecuteAsync(message, cancellationToken);

            await _messageProcessor.CompleteProcessingMessageAsync(message, result, cancellationToken);
        }
        internal async Task ProcessMessageAsync(Message message, CancellationToken cancellationToken)
        {
            using (CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _cancellationTokenSource.Token))
            {
                if (!await _messageProcessor.BeginProcessingMessageAsync(message, linkedCts.Token))
                {
                    return;
                }

                ServiceBusTriggerInput input = ServiceBusTriggerInput.CreateSingle(message);
                input.MessageReceiver = Receiver;

                TriggeredFunctionData data   = input.GetTriggerFunctionData();
                FunctionResult        result = await _triggerExecutor.TryExecuteAsync(data, linkedCts.Token);

                await _messageProcessor.CompleteProcessingMessageAsync(message, result, linkedCts.Token);
            }
        }
Exemple #8
0
        public async Task CompleteProcessingMessageAsync_Failure_AbandonsMessage()
        {
            OnMessageOptions options = new OnMessageOptions
            {
                AutoComplete = false
            };
            MessageProcessor processor = new MessageProcessor(options);

            BrokeredMessage message = new BrokeredMessage();
            FunctionResult  result  = new FunctionResult(false);
            var             ex      = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
            });

            // this verifies that we initiated the abandon
            Assert.True(ex.ToString().Contains("Microsoft.ServiceBus.Messaging.BrokeredMessage.BeginAbandon"));
        }
        public async Task CompleteProcessingMessageAsync_Failure_AbandonsMessage()
        {
            OnMessageOptions options = new OnMessageOptions
            {
                AutoComplete = false
            };
            MessageProcessor processor = new MessageProcessor(options);

            BrokeredMessage message = new BrokeredMessage();
            FunctionResult result = new FunctionResult(false);
            var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
            {
                await processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
            });

            // this verifies that we initiated the abandon
            Assert.True(ex.ToString().Contains("Microsoft.ServiceBus.Messaging.BrokeredMessage.BeginAbandon"));
        }
Exemple #10
0
        internal async Task ProcessMessageAsync(ProcessMessageEventArgs args)
        {
            using (CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(args.CancellationToken, _cancellationTokenSource.Token))
            {
                var actions = new ServiceBusMessageActions(args);
                if (!await _messageProcessor.BeginProcessingMessageAsync(actions, args.Message, linkedCts.Token).ConfigureAwait(false))
                {
                    return;
                }

                ServiceBusTriggerInput input = ServiceBusTriggerInput.CreateSingle(args.Message);
                input.MessageActions = actions;

                TriggeredFunctionData data   = input.GetTriggerFunctionData();
                FunctionResult        result = await _triggerExecutor.TryExecuteAsync(data, linkedCts.Token).ConfigureAwait(false);

                await _messageProcessor.CompleteProcessingMessageAsync(actions, args.Message, result, linkedCts.Token).ConfigureAwait(false);
            }
        }
Exemple #11
0
        public async Task CompleteProcessingMessageAsync_Success_CompletesMessage_WhenAutoCompleteFalse()
        {
            OnMessageOptions options = new OnMessageOptions
            {
                AutoComplete = false
            };
            MessageProcessor processor = new MessageProcessor(options);

            BrokeredMessage message = new BrokeredMessage();
            FunctionResult  result  = new FunctionResult(true);
            var             ex      = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
            });

            // The service bus APIs aren't unit testable, so in this test suite
            // we rely on exception stacks to verify APIs are called as expected.
            // this verifies that we initiated the completion
            Assert.True(ex.ToString().Contains("Microsoft.ServiceBus.Messaging.BrokeredMessage.BeginComplete"));
        }
        public async Task CompleteProcessingMessageAsync_Success_CompletesMessage_WhenAutoCompleteFalse()
        {
            OnMessageOptions options = new OnMessageOptions
            {
                AutoComplete = false
            };
            MessageProcessor processor = new MessageProcessor(options);

            BrokeredMessage message = new BrokeredMessage();
            FunctionResult result = new FunctionResult(true);
            var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
            {
                await processor.CompleteProcessingMessageAsync(message, result, CancellationToken.None);
            });

            // The service bus APIs aren't unit testable, so in this test suite
            // we rely on exception stacks to verify APIs are called as expected.
            // this verifies that we initiated the completion
            Assert.True(ex.ToString().Contains("Microsoft.ServiceBus.Messaging.BrokeredMessage.BeginComplete"));
        }
        internal async Task ProcessMessageAsync(ProcessMessageEventArgs args)
        {
            using (CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(args.CancellationToken, _cancellationTokenSource.Token))
            {
                //TODO consider using internals visible or exposing the Receiver property instead of reflection
                ServiceBusReceiver receiver = (ServiceBusReceiver)typeof(ProcessMessageEventArgs).GetField("_receiver", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(args);

                if (!await _messageProcessor.BeginProcessingMessageAsync(receiver, args.Message, linkedCts.Token).ConfigureAwait(false))
                {
                    return;
                }

                ServiceBusTriggerInput input = ServiceBusTriggerInput.CreateSingle(args.Message);
                input.Receiver = receiver;

                TriggeredFunctionData data   = input.GetTriggerFunctionData();
                FunctionResult        result = await _triggerExecutor.TryExecuteAsync(data, linkedCts.Token).ConfigureAwait(false);

                await _messageProcessor.CompleteProcessingMessageAsync(receiver, args.Message, result, linkedCts.Token).ConfigureAwait(false);
            }
        }