Пример #1
0
        public async Task ProcessThresholdsExceeded_InProc_ReturnsExpectedResult(ThrottleState throttleState, bool expected)
        {
            var status = new ConcurrencyThrottleAggregateStatus
            {
                State = throttleState
            };

            if (throttleState == ThrottleState.Enabled)
            {
                status.EnabledThrottles = new List <string> {
                    "CPU", "Memory"
                }.AsReadOnly();
            }
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);

            mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(status);

            var mockScriptHostManager = new Mock <IScriptHostManager>(MockBehavior.Strict);
            var scriptHostManagerServiceProviderMock = mockScriptHostManager.As <IServiceProvider>();

            scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IFunctionInvocationDispatcherFactory))).Returns(null);
            scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IConcurrencyThrottleManager))).Returns(mockConcurrencyThrottleManager.Object);
            _serviceProviderMock.Setup(p => p.GetService(typeof(IScriptHostManager))).Returns(mockScriptHostManager.Object);

            Collection <string> exceededCounters = new Collection <string>();
            bool result = await _performanceManager.ProcessThresholdsExceeded(_logger);

            Assert.Equal(expected, result);
        }
Пример #2
0
        public async Task ProcessThresholdsExceeded_OutOfProc_ReturnsExpectedResult(ThrottleState throttleState, bool expected)
        {
            var status = new ConcurrencyThrottleAggregateStatus
            {
                State = throttleState
            };

            if (throttleState == ThrottleState.Enabled)
            {
                status.EnabledThrottles = new List <string> {
                    "CPU", "Memory"
                }.AsReadOnly();
            }
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);

            mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(status);

            var workerStatuses = new Dictionary <string, WorkerStatus>();

            for (int i = 0; i < 3; i++)
            {
                var workerStatus = new WorkerStatus
                {
                    Latency = TimeSpan.FromMilliseconds(25)
                };
                workerStatuses.Add(Guid.NewGuid().ToString(), workerStatus);
            }

            var mockDispatcher = new Mock <IFunctionInvocationDispatcher>(MockBehavior.Strict);

            mockDispatcher.SetupGet(p => p.State).Returns(FunctionInvocationDispatcherState.Initialized);
            mockDispatcher.Setup(p => p.GetWorkerStatusesAsync()).ReturnsAsync(workerStatuses);
            var mockDispatcherFactory = new Mock <IFunctionInvocationDispatcherFactory>(MockBehavior.Strict);

            mockDispatcherFactory.Setup(p => p.GetFunctionDispatcher()).Returns(mockDispatcher.Object);
            var mockScriptHostManager = new Mock <IScriptHostManager>(MockBehavior.Strict);
            var scriptHostManagerServiceProviderMock = mockScriptHostManager.As <IServiceProvider>();

            scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IFunctionInvocationDispatcherFactory))).Returns(mockDispatcherFactory.Object);
            scriptHostManagerServiceProviderMock.Setup(p => p.GetService(typeof(IConcurrencyThrottleManager))).Returns(mockConcurrencyThrottleManager.Object);
            _serviceProviderMock.Setup(p => p.GetService(typeof(IScriptHostManager))).Returns(mockScriptHostManager.Object);

            Collection <string> exceededCounters = new Collection <string>();
            bool result = await _performanceManager.ProcessThresholdsExceeded(_logger);

            Assert.Equal(expected, result);

            mockDispatcher.VerifyAll();
        }
        public void GetMessageReceiveCount_DynamicConcurrencyEnabled_ReturnsExpectedValue()
        {
            var concurrencyOptions = new ConcurrencyOptions
            {
                DynamicConcurrencyEnabled = true
            };
            var throttleStatus = new ConcurrencyThrottleAggregateStatus {
                State = ThrottleState.Disabled
            };
            var optionsWrapper = new OptionsWrapper <ConcurrencyOptions>(concurrencyOptions);
            var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict);

            mockConcurrencyThrottleManager.Setup(p => p.GetStatus()).Returns(() => throttleStatus);
            var concurrencyManager = new ConcurrencyManager(optionsWrapper, _loggerFactory, mockConcurrencyThrottleManager.Object);
            var localListener      = new QueueListener(_mockQueue.Object, null, _mockTriggerExecutor.Object, _mockExceptionDispatcher.Object, _loggerFactory, null, _queuesOptions, _mockQueueProcessor.Object, new FunctionDescriptor {
                Id = TestFunctionId
            }, concurrencyManager);

            int result = localListener.GetMessageReceiveCount();

            Assert.AreEqual(1, result);
        }