コード例 #1
0
        public async Task If_KeepAliveMode_OneTaskAndOneTokenAndIsUnavailableAndKeepAliveHasNotPassedElapsedTime_ThenIsDenied()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest = CreateKeepAliveStartRequest();

            startRequest.KeepAliveDeathThreshold = new TimeSpan(1, 0, 0);

            var secondRequest = CreateKeepAliveStartRequest();

            secondRequest.KeepAliveDeathThreshold = new TimeSpan(1, 0, 0);

            // ACT
            var sut           = CreateSut();
            var firstResponse = await sut.StartAsync(startRequest);

            executionHelper.SetKeepAlive(firstResponse.TaskExecutionId);

            Thread.Sleep(5000);

            var secondResponse = await sut.StartAsync(secondRequest);

            // ASSERT
            Assert.Equal(GrantStatus.Granted, firstResponse.GrantStatus);
            Assert.NotEqual("0", firstResponse.ExecutionTokenId);
            Assert.Equal(GrantStatus.Denied, secondResponse.GrantStatus);
            Assert.Equal("0", secondResponse.ExecutionTokenId);
        }
コード例 #2
0
        public void If_KeepAliveMode_TokenAvailableAndIsNotFirstInQueueButFirstHasExpiredTimeout_ThenRemoveBothFromQueueAndGrant()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            var keepAliveThreshold = new TimeSpan(0, 0, 5);

            // Create execution 1 and add it to the queue
            var taskExecutionId1 = executionHelper.InsertKeepAliveTaskExecution(taskDefinitionId, new TimeSpan(0, 0, 1), keepAliveThreshold);

            executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId);
            executionHelper.SetKeepAlive(taskExecutionId1);
            executionHelper.InsertIntoCriticalSectionQueue(taskDefinitionId, 1, taskExecutionId1);

            Thread.Sleep(6000);

            // Create execution 2 and add it to the queue
            var taskExecutionId2 = executionHelper.InsertKeepAliveTaskExecution(taskDefinitionId);

            executionHelper.SetKeepAlive(taskExecutionId2);
            executionHelper.InsertIntoCriticalSectionQueue(taskDefinitionId, 2, taskExecutionId2);

            // Create an available critical section token
            executionHelper.InsertAvailableCriticalSectionToken(taskDefinitionId, "0");

            var request = new StartCriticalSectionRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName),
                                                          taskExecutionId2,
                                                          TaskDeathMode.KeepAlive,
                                                          CriticalSectionType.User);

            request.KeepAliveDeathThreshold = keepAliveThreshold;

            // ACT
            var sut      = CreateSut();
            var response = sut.Start(request);

            // ASSERT
            var numberOfQueueRecordsForExecution1 = executionHelper.GetQueueCount(taskExecutionId1);
            var numberOfQueueRecordsForExecution2 = executionHelper.GetQueueCount(taskExecutionId2);

            Assert.AreEqual(0, numberOfQueueRecordsForExecution1);
            Assert.AreEqual(0, numberOfQueueRecordsForExecution2);
            Assert.AreEqual(GrantStatus.Granted, response.GrantStatus);
        }
コード例 #3
0
        public async Task If_KeepAliveMode_FiveConcurrentTasksAndFourTokensAndAllAreAvailable_ThenIsGrantFirstFourTasksAndDenyTheOther()
        {
            // ARRANGE
            int concurrencyLimit = 4;
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId, concurrencyLimit);

            var firstStartRequest  = CreateKeepAliveStartRequest(concurrencyLimit);
            var secondStartRequest = CreateKeepAliveStartRequest(concurrencyLimit);
            var thirdStartRequest  = CreateKeepAliveStartRequest(concurrencyLimit);
            var fourthStartRequest = CreateKeepAliveStartRequest(concurrencyLimit);
            var fifthStartRequest  = CreateKeepAliveStartRequest(concurrencyLimit);

            // ACT
            var sut           = CreateSut();
            var firstResponse = await sut.StartAsync(firstStartRequest);

            executionHelper.SetKeepAlive(firstResponse.TaskExecutionId);
            var secondResponse = await sut.StartAsync(secondStartRequest);

            executionHelper.SetKeepAlive(secondResponse.TaskExecutionId);
            var thirdResponse = await sut.StartAsync(thirdStartRequest);

            executionHelper.SetKeepAlive(thirdResponse.TaskExecutionId);
            var fourthResponse = await sut.StartAsync(fourthStartRequest);

            executionHelper.SetKeepAlive(fourthResponse.TaskExecutionId);
            var fifthResponse = await sut.StartAsync(fifthStartRequest);

            // ASSERT
            Assert.Equal(GrantStatus.Granted, firstResponse.GrantStatus);
            Assert.Equal(GrantStatus.Granted, secondResponse.GrantStatus);
            Assert.Equal(GrantStatus.Granted, thirdResponse.GrantStatus);
            Assert.Equal(GrantStatus.Granted, fourthResponse.GrantStatus);
            Assert.Equal(GrantStatus.Denied, fifthResponse.GrantStatus);
        }
コード例 #4
0
        private async Task RequestAndReturnTokenWithKeepAliveModeAsync(Tuple <int, TaskExecutionRepository> tuple)
        {
            var sut = tuple.Item2;

            for (int i = 0; i < 100; i++)
            {
                var firstStartRequest = CreateKeepAliveStartRequest();

                var firstStartResponse = await sut.StartAsync(firstStartRequest);

                var executionHelper = new ExecutionsHelper();
                executionHelper.SetKeepAlive(firstStartResponse.TaskExecutionId);

                if (firstStartResponse.GrantStatus == GrantStatus.Granted)
                {
                    var firstCompleteRequest  = new TaskExecutionCompleteRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName), firstStartResponse.TaskExecutionId, firstStartResponse.ExecutionTokenId);
                    var firstCompleteResponse = await sut.CompleteAsync(firstCompleteRequest);
                }
            }
        }
コード例 #5
0
        public void When_KeepAliveModeAndDateRange_DeadTasksPassedKeepAliveLimitPeriodAndLessThanBlockCountLimit_ThenReturnAllDeadBlocks()
        {
            // ARRANGE
            InsertDateRangeTestData(TaskDeathMode.KeepAlive);
            _executionHelper.SetKeepAlive(_taskExecution1, DateTime.UtcNow.AddMinutes(-250));

            int blockCountLimit = 5;
            var request         = CreateDeadBlockRequest(BlockType.DateRange, TaskDeathMode.KeepAlive, blockCountLimit);

            // ACT
            var sut        = CreateSut();
            var deadBlocks = sut.FindDeadRangeBlocks(request);

            // ASSERT
            Assert.AreEqual(3, deadBlocks.Count);
            Assert.IsTrue(deadBlocks.Any(x => x.RangeBlockId == _block2));
            Assert.IsTrue(deadBlocks.Any(x => x.RangeBlockId == _block3));
            Assert.IsTrue(deadBlocks.Any(x => x.RangeBlockId == _block5));
        }