public void Register(string functionId, BlobQueueRegistration registration)
        {
            if (_started)
            {
                throw new InvalidOperationException("Registrations may not be added while the shared listener is running.");
            }

            _executor.Register(functionId, registration);
        }
        public void Register(string functionId, BlobQueueRegistration registration)
        {
            if (_started)
            {
                throw new InvalidOperationException("Registrations may not be added while the shared listener is running.");
            }

            _executor.Register(functionId, registration);
        }
        private void RegisterWithSharedBlobQueueListenerAsync(
            SharedBlobQueueListener sharedBlobQueueListener,
            IStorageBlobClient blobClient)
        {
            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                Executor   = _executor,
                BlobClient = blobClient
            };

            sharedBlobQueueListener.Register(_functionId, registration);
        }
        private void RegisterWithSharedBlobQueueListenerAsync(
            SharedBlobQueueListener sharedBlobQueueListener,
            BlobServiceClient blobClient,
            QueueServiceClient queueClient)
        {
            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                Executor           = _executor,
                BlobServiceClient  = blobClient,
                QueueServiceClient = queueClient
            };

            sharedBlobQueueListener.Register(_functionDescriptor.Id, registration);
        }
Beispiel #5
0
            private CloudQueue GetPoisonQueue(CloudQueueMessage message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                var blobTriggerMessage = JsonConvert.DeserializeObject <BlobTriggerMessage>(message.AsString);

                BlobQueueRegistration registration = null;

                if (_executor.TryGetRegistration(blobTriggerMessage.FunctionId, out registration))
                {
                    IStorageQueue poisonQueue = registration.QueueClient.GetQueueReference(HostQueueNames.BlobTriggerPoisonQueue);
                    return(poisonQueue.SdkObject);
                }

                return(null);
            }
            private QueueClient GetPoisonQueue(QueueMessage message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                var blobTriggerMessage = JsonConvert.DeserializeObject <BlobTriggerMessage>(message.MessageText);

                BlobQueueRegistration registration = null;

                if (_executor.TryGetRegistration(blobTriggerMessage.FunctionId, out registration))
                {
                    var poisonQueue = registration.QueueServiceClient.GetQueueClient(HostQueueNames.BlobTriggerPoisonQueue);
                    return(poisonQueue);
                }

                return(null);
            }
Beispiel #7
0
        private IListener CreateQueueMessageToTriggerExecutionListener(
            ISharedContextProvider sharedContextProvider,
            SharedQueueWatcher sharedQueueWatcher,
            IStorageQueueClient queueClient,
            IStorageQueue hostBlobTriggerQueue,
            IStorageBlobClient blobClient,
            IBlobWrittenWatcher blobWrittenWatcher)
        {
            SharedBlobQueueListener sharedListener = sharedContextProvider.GetOrCreate <SharedBlobQueueListener>(
                new SharedBlobQueueListenerFactory(sharedQueueWatcher, queueClient, hostBlobTriggerQueue,
                                                   _queueConfiguration, _backgroundExceptionDispatcher, _trace, blobWrittenWatcher));

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                Executor   = _executor,
                BlobClient = blobClient
            };

            sharedListener.Register(_functionId, registration);

            return(new BlobListener(sharedListener));
        }
 public void Register(string functionId, BlobQueueRegistration registration)
 {
     _registrations.AddOrUpdate(functionId, registration, (i1, i2) => registration);
 }
        public void ExecuteAsync_IfMessageIsFunctionIdIsRegistered_GetsETag(BlobType expectedBlobType)
        {
            // Arrange
            string expectedContainerName = "container";
            string expectedBlobName = TestBlobName;
            string functionId = "FunctionId";
            Mock<IBlobETagReader> mock = new Mock<IBlobETagReader>(MockBehavior.Strict);
            mock.Setup(r => r.GetETagAsync(It.Is<IStorageBlob>(b => b.BlobType == (StorageBlobType)expectedBlobType &&
                    b.Name == expectedBlobName && b.Container.Name == expectedContainerName),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.FromResult("ETag"))
                .Verifiable();
            IBlobETagReader eTagReader = mock.Object;
            BlobQueueTriggerExecutor product = CreateProductUnderTest(eTagReader);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = CreateClient(),
                Executor = CreateDummyTriggeredFunctionExecutor()
            };
            product.Register(functionId, registration);

            BlobTriggerMessage triggerMessage = new BlobTriggerMessage
            {
                FunctionId = functionId,
                BlobType = (StorageBlobType)expectedBlobType,
                ContainerName = expectedContainerName,
                BlobName = expectedBlobName,
                ETag = "OriginalETag"

            };
            IStorageQueueMessage message = CreateMessage(triggerMessage);

            // Act
            Task task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            task.WaitUntilCompleted();
            mock.Verify();
        }
        public void ExecuteAsync_IfInnerExecutorFails_ReturnsFailureResult()
        {
            // Arrange
            string functionId = "FunctionId";
            string matchingETag = "ETag";
            IBlobETagReader eTagReader = CreateStubETagReader(matchingETag);
            IBlobCausalityReader causalityReader = CreateStubCausalityReader();

            FunctionResult expectedResult = new FunctionResult(false);
            Mock<ITriggeredFunctionExecutor> mock = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict);
            mock.Setup(e => e.TryExecuteAsync(
                It.IsAny<TriggeredFunctionData>(), It.IsAny<CancellationToken>()))
                .ReturnsAsync(expectedResult)
                .Verifiable();

            BlobQueueTriggerExecutor product = CreateProductUnderTest(eTagReader, causalityReader);

            ITriggeredFunctionExecutor innerExecutor = mock.Object;
            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = CreateClient(),
                Executor = innerExecutor
            };
            product.Register(functionId, registration);

            IStorageQueueMessage message = CreateMessage(functionId, matchingETag);

            // Act
            Task<FunctionResult> task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            Assert.False(task.Result.Succeeded);
        }
        public async Task ExecuteAsync_IfBlobIsUnchanged_CallsInnerExecutor()
        {
            // Arrange
            string functionId = "FunctionId";
            string matchingETag = "ETag";
            Guid expectedParentId = Guid.NewGuid();
            IStorageQueueMessage message = CreateMessage(functionId, matchingETag);
            IBlobETagReader eTagReader = CreateStubETagReader(matchingETag);
            IBlobCausalityReader causalityReader = CreateStubCausalityReader(expectedParentId);

            FunctionResult expectedResult = new FunctionResult(true);
            Mock<ITriggeredFunctionExecutor> mock = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict);
            mock.Setup(e => e.TryExecuteAsync(It.IsAny<TriggeredFunctionData>(), It.IsAny<CancellationToken>()))
                .Callback<TriggeredFunctionData, CancellationToken>(
                (mockInput, mockCancellationToken) =>
                {
                    Assert.Equal(expectedParentId, mockInput.ParentId);

                    StorageBlockBlob resultBlob = (StorageBlockBlob)mockInput.TriggerValue;
                    Assert.Equal(TestBlobName, resultBlob.Name);
                })
                .ReturnsAsync(expectedResult)
                .Verifiable();

            ITriggeredFunctionExecutor innerExecutor = mock.Object;
            BlobQueueTriggerExecutor product = CreateProductUnderTest(eTagReader, causalityReader);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = CreateClient(),
                Executor = innerExecutor
            };
            product.Register(functionId, registration);

            // Act
            FunctionResult result = await product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            Assert.Same(expectedResult, result);
            mock.Verify();
        }
        public void ExecuteAsync_IfBlobHasChanged_NotifiesWatcherAndReturnsSuccessResult()
        {
            // Arrange
            string functionId = "FunctionId";
            IBlobETagReader eTagReader = CreateStubETagReader("NewETag");
            Mock<IBlobWrittenWatcher> mock = new Mock<IBlobWrittenWatcher>(MockBehavior.Strict);
            mock.Setup(w => w.Notify(It.IsAny<IStorageBlob>()))
                .Verifiable();
            IBlobWrittenWatcher blobWrittenWatcher = mock.Object;
            BlobQueueTriggerExecutor product = CreateProductUnderTest(eTagReader, blobWrittenWatcher);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = CreateClient(),
                Executor = CreateDummyTriggeredFunctionExecutor()
            };
            product.Register(functionId, registration);

            IStorageQueueMessage message = CreateMessage(functionId, "OriginalETag");

            // Act
            Task<FunctionResult> task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            task.WaitUntilCompleted();
            mock.Verify();
            Assert.True(task.Result.Succeeded);
        }
        public void ExecuteAsync_IfBlobHasBeenDeleted_ReturnsSuccessResult()
        {
            // Arrange
            string functionId = "FunctionId";
            IBlobETagReader eTagReader = CreateStubETagReader(null);
            BlobQueueTriggerExecutor product = CreateProductUnderTest(eTagReader);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = CreateClient(),
                Executor = CreateDummyTriggeredFunctionExecutor()
            };
            product.Register(functionId, registration);

            IStorageQueueMessage message = CreateMessage(functionId, "OriginalETag");

            // Act
            Task<FunctionResult> task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            Assert.True(task.Result.Succeeded);
        }
 public bool TryGetRegistration(string functionId, out BlobQueueRegistration registration)
 {
     return(_registrations.TryGetValue(functionId, out registration));
 }
        private IListener CreateQueueMessageToTriggerExecutionListener(
            ISharedContextProvider sharedContextProvider,
            SharedQueueWatcher sharedQueueWatcher,
            IStorageQueueClient queueClient,
            IStorageQueue hostBlobTriggerQueue,
            IStorageBlobClient blobClient,
            IBlobWrittenWatcher blobWrittenWatcher)
        {
            SharedBlobQueueListener sharedListener = sharedContextProvider.GetOrCreate<SharedBlobQueueListener>(
                new SharedBlobQueueListenerFactory(sharedQueueWatcher, queueClient, hostBlobTriggerQueue,
                    _queueConfiguration, _backgroundExceptionDispatcher, _trace, blobWrittenWatcher));

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                Executor = _executor,
                BlobClient = blobClient
            };

            sharedListener.Register(_functionId, registration);

            return new BlobListener(sharedListener);
        }
Beispiel #16
0
        private void RegisterWithSharedBlobQueueListenerAsync(
            SharedBlobQueueListener sharedBlobQueueListener,
            IStorageBlobClient blobClient)
        {
            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                Executor = _executor,
                BlobClient = blobClient
            };

            sharedBlobQueueListener.Register(_functionId, registration);
        }