public void If_OverrideMode_TokenNotAvailableAndNothingInQueue_ThenAddToQueueAndDeny()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId);

            // Create execution 1 and assign critical section to it
            var taskExecutionId1 = executionHelper.InsertOverrideTaskExecution(taskDefinitionId);

            executionHelper.InsertUnavailableCriticalSectionToken(taskDefinitionId, taskExecutionId1);

            // Create second execution
            var taskExecutionId2 = executionHelper.InsertOverrideTaskExecution(taskDefinitionId);

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

            request.OverrideThreshold = new TimeSpan(0, 1, 0);

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

            // ASSERT
            var isInQueue = executionHelper.GetQueueCount(taskExecutionId2) == 1;

            Assert.AreEqual(true, isInQueue);
            Assert.AreEqual(GrantStatus.Denied, response.GrantStatus);
        }
        public async Task If_OverrideMode_TokenNotAvailableAndAlreadyInQueue_ThenDoNotAddToQueueAndDeny()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId);

            // Create execution 1 and assign critical section to it
            var taskExecutionId1 = executionHelper.InsertOverrideTaskExecution(taskDefinitionId);

            executionHelper.InsertUnavailableCriticalSectionToken(taskDefinitionId, taskExecutionId1);

            // Create second execution and insert into queue
            var taskExecutionId2 = executionHelper.InsertOverrideTaskExecution(taskDefinitionId);

            executionHelper.InsertIntoCriticalSectionQueue(taskDefinitionId, 1, taskExecutionId2);

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

            request.OverrideThreshold = new TimeSpan(0, 10, 0);

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

            // ASSERT
            var numberOfQueueRecords = executionHelper.GetQueueCount(taskExecutionId2);

            Assert.Equal(1, numberOfQueueRecords);
            Assert.Equal(GrantStatus.Denied, response.GrantStatus);
        }
Ejemplo n.º 3
0
        private void InsertDateRangeBlock()
        {
            _taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId);

            _baseDateTime = new DateTime(2016, 1, 1);
            var block1 = _blocksHelper.InsertDateRangeBlock(_taskDefinitionId, _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-30), DateTime.UtcNow).ToString();

            _blockExecutionId = _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(block1), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-25), BlockExecutionStatus.Started);
        }
Ejemplo n.º 4
0
        private void InsertDateRangeTestData(TaskDeathMode taskDeathMode)
        {
            var now = DateTime.UtcNow;

            if (taskDeathMode == TaskDeathMode.Override)
            {
                _taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId, OneMinuteSpan, now.AddMinutes(-250), now.AddMinutes(-179));
            }
            else
            {
                _taskExecution1 = _executionHelper.InsertKeepAliveTaskExecution(_taskDefinitionId, TwentySecondSpan, FiveMinuteSpan, now.AddMinutes(-250), now.AddMinutes(-179));
            }

            InsertDateRangeBlocksTestData();
        }
        public void If_OverrideMode_TokenAvailableAndIsFirstInQueue_ThenRemoveFromQueueAndGrant()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId);

            // Create execution 1 and create available critical section token
            var taskExecutionId1 = executionHelper.InsertOverrideTaskExecution(taskDefinitionId);

            executionHelper.InsertIntoCriticalSectionQueue(taskDefinitionId, 1, taskExecutionId1);
            executionHelper.InsertAvailableCriticalSectionToken(taskDefinitionId, "0");

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

            request.OverrideThreshold = new TimeSpan(0, 1, 0);

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

            // ASSERT
            var numberOfQueueRecords = executionHelper.GetQueueCount(taskExecutionId1);

            Assert.AreEqual(0, numberOfQueueRecords);
            Assert.AreEqual(GrantStatus.Granted, response.GrantStatus);
        }
        public void If_OverrideMode_TokenAvailableAndIsNotFirstInQueueButFirstHasExpiredTimeout_ThenRemoveBothFromQueueAndGrant()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

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

            // Create execution 1 and add it to the queue
            var taskExecutionId1 = executionHelper.InsertOverrideTaskExecution(taskDefinitionId, overrideThreshold);

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

            Thread.Sleep(6000);

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

            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.Override,
                                                          CriticalSectionType.User);

            request.OverrideThreshold = overrideThreshold;

            // 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);
        }
Ejemplo n.º 7
0
        private void InsertBlocks()
        {
            _taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId);

            _baseDateTime = new DateTime(2016, 1, 1);
            var dateRange1 = new DateRange()
            {
                FromDate = _baseDateTime.AddMinutes(-20), ToDate = _baseDateTime
            };

            _block1 = _blocksHelper.InsertListBlock(_taskDefinitionId, DateTime.UtcNow, JsonGenericSerializer.Serialize <DateRange>(dateRange1)).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block1), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-25), BlockExecutionStatus.Failed);

            Thread.Sleep(10);
            var dateRange2 = new DateRange()
            {
                FromDate = _baseDateTime.AddMinutes(-30), ToDate = _baseDateTime
            };

            _block2 = _blocksHelper.InsertListBlock(_taskDefinitionId, DateTime.UtcNow, JsonGenericSerializer.Serialize <DateRange>(dateRange2)).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block2), _baseDateTime.AddMinutes(-30), _baseDateTime.AddMinutes(-30), _baseDateTime.AddMinutes(-35), BlockExecutionStatus.Started);

            Thread.Sleep(10);
            var dateRange3 = new DateRange()
            {
                FromDate = _baseDateTime.AddMinutes(-40), ToDate = _baseDateTime
            };

            _block3 = _blocksHelper.InsertListBlock(_taskDefinitionId, DateTime.UtcNow, JsonGenericSerializer.Serialize <DateRange>(dateRange3)).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block3), _baseDateTime.AddMinutes(-40), _baseDateTime.AddMinutes(-40), _baseDateTime.AddMinutes(-45), BlockExecutionStatus.NotStarted);

            Thread.Sleep(10);
            var dateRange4 = new DateRange()
            {
                FromDate = _baseDateTime.AddMinutes(-50), ToDate = _baseDateTime
            };

            _block4 = _blocksHelper.InsertListBlock(_taskDefinitionId, DateTime.UtcNow, JsonGenericSerializer.Serialize <DateRange>(dateRange4)).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block4), _baseDateTime.AddMinutes(-50), _baseDateTime.AddMinutes(-50), _baseDateTime.AddMinutes(-55), BlockExecutionStatus.Completed);

            Thread.Sleep(10);
            var dateRange5 = new DateRange()
            {
                FromDate = _baseDateTime.AddMinutes(-60), ToDate = _baseDateTime
            };

            _block5 = _blocksHelper.InsertListBlock(_taskDefinitionId, DateTime.UtcNow, JsonGenericSerializer.Serialize <DateRange>(dateRange5)).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block5), _baseDateTime.AddMinutes(-60), _baseDateTime.AddMinutes(-60), _baseDateTime.AddMinutes(-65), BlockExecutionStatus.Started);
        }
Ejemplo n.º 8
0
        private void InsertBlocks()
        {
            _taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId);

            _baseDateTime = new DateTime(2016, 1, 1);
            _block1       = _blocksHelper.InsertNumericRangeBlock(_taskDefinitionId, 1000, 1100, DateTime.UtcNow).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block1), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-25), BlockExecutionStatus.Failed);
            Thread.Sleep(10);
            _block2 = _blocksHelper.InsertNumericRangeBlock(_taskDefinitionId, 900, 1200, DateTime.UtcNow).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block2), _baseDateTime.AddMinutes(-30), _baseDateTime.AddMinutes(-30), _baseDateTime.AddMinutes(-35), BlockExecutionStatus.Started);
            Thread.Sleep(10);
            _block3 = _blocksHelper.InsertNumericRangeBlock(_taskDefinitionId, 800, 900, DateTime.UtcNow).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block3), _baseDateTime.AddMinutes(-40), _baseDateTime.AddMinutes(-40), _baseDateTime.AddMinutes(-45), BlockExecutionStatus.NotStarted);
            Thread.Sleep(10);
            _block4 = _blocksHelper.InsertNumericRangeBlock(_taskDefinitionId, 700, 800, DateTime.UtcNow).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block4), _baseDateTime.AddMinutes(-50), _baseDateTime.AddMinutes(-50), _baseDateTime.AddMinutes(-55), BlockExecutionStatus.Completed);
            Thread.Sleep(10);
            _block5 = _blocksHelper.InsertNumericRangeBlock(_taskDefinitionId, 600, 700, DateTime.UtcNow).ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block5), _baseDateTime.AddMinutes(-60), _baseDateTime.AddMinutes(-60), _baseDateTime.AddMinutes(-65), BlockExecutionStatus.Started);
        }
Ejemplo n.º 9
0
        private void InsertBlocks()
        {
            _taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId);

            _baseDateTime = new DateTime(2016, 1, 1);
            _block1       = _blocksHelper.InsertObjectBlock(_taskDefinitionId, DateTime.UtcNow, "Testing1").ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block1), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-20), _baseDateTime.AddMinutes(-25), BlockExecutionStatus.Failed);
            Thread.Sleep(10);
            _block2 = _blocksHelper.InsertObjectBlock(_taskDefinitionId, DateTime.UtcNow, "Testing2").ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block2), _baseDateTime.AddMinutes(-30), _baseDateTime.AddMinutes(-30), _baseDateTime.AddMinutes(-35), BlockExecutionStatus.Started);
            Thread.Sleep(10);
            _block3 = _blocksHelper.InsertObjectBlock(_taskDefinitionId, DateTime.UtcNow, "Testing3").ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block3), _baseDateTime.AddMinutes(-40), _baseDateTime.AddMinutes(-40), _baseDateTime.AddMinutes(-45), BlockExecutionStatus.NotStarted);
            Thread.Sleep(10);
            _block4 = _blocksHelper.InsertObjectBlock(_taskDefinitionId, DateTime.UtcNow, "Testing4").ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block4), _baseDateTime.AddMinutes(-50), _baseDateTime.AddMinutes(-50), _baseDateTime.AddMinutes(-55), BlockExecutionStatus.Completed);
            Thread.Sleep(10);
            _block5 = _blocksHelper.InsertObjectBlock(_taskDefinitionId, DateTime.UtcNow, "Testing5").ToString();
            _blocksHelper.InsertBlockExecution(_taskExecution1, long.Parse(_block5), _baseDateTime.AddMinutes(-60), _baseDateTime.AddMinutes(-60), _baseDateTime.AddMinutes(-65), BlockExecutionStatus.Started);
        }
        public void If_OverrideMode_TokenAvailableAndNothingInQueue_ThenGrant()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
            var taskExecutionId  = executionHelper.InsertOverrideTaskExecution(taskDefinitionId);

            executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId);

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

            request.OverrideThreshold = new TimeSpan(0, 1, 0);

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

            // ASSERT
            Assert.AreEqual(GrantStatus.Granted, response.GrantStatus);
        }
Ejemplo n.º 11
0
        public void When_FailedDateRangeBlocksExistInTargetPeriodAndNumberIsLessThanBlocksLimit_ThenReturnAllFailedBlocks()
        {
            // ARRANGE
            var now            = DateTime.UtcNow;
            var taskExecution1 = _executionHelper.InsertOverrideTaskExecution(_taskDefinitionId, new TimeSpan(0, 1, 0), now.AddMinutes(-12), now.AddMinutes(-1));
            var block1         = _blocksHelper.InsertDateRangeBlock(_taskDefinitionId, now.AddMinutes(-2), now.AddMinutes(-1));
            var block2         = _blocksHelper.InsertDateRangeBlock(_taskDefinitionId, now.AddMinutes(-12), now.AddMinutes(-11));

            _blocksHelper.InsertBlockExecution(taskExecution1, block1, now.AddMinutes(-2), now.AddMinutes(-2), now.AddMinutes(-1), BlockExecutionStatus.Failed);
            _blocksHelper.InsertBlockExecution(taskExecution1, block2, now.AddMinutes(-12), now.AddMinutes(-12), now.AddMinutes(-11), BlockExecutionStatus.Completed);

            var request = new FindFailedBlocksRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName),
                                                      "1",
                                                      BlockType.DateRange,
                                                      DateTime.UtcNow.AddMinutes(-20),
                                                      DateTime.UtcNow,
                                                      2,
                                                      3);

            // ACT
            var sut          = CreateSut();
            var failedBlocks = sut.FindFailedRangeBlocks(request);

            // ASSERT
            Assert.AreEqual(1, failedBlocks.Count);
            Assert.AreEqual(block1.ToString(), failedBlocks[0].RangeBlockId);
        }