Exemple #1
0
        public void If_TryStartWithHeader_ThenHeaderWrittenToDatabase()
        {
            // ARRANGE
            var executionHelper = new ExecutionsHelper();
            var myHeader        = new MyHeader()
            {
                Name = "Jack",
                Id   = 367
            };

            // ACT
            bool startedOk;

            using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
            {
                startedOk = executionContext.TryStart <MyHeader>(myHeader);

                var myHeaderBack = executionContext.GetHeader <MyHeader>();
            }

            var dbHelper        = new ExecutionsHelper();
            var executionHeader = dbHelper.GetLastExecutionHeader(_taskDefinitionId);
            var expectedHeader  = "{\"Name\":\"Jack\",\"Id\":367}";

            // ASSERT
            Assert.AreEqual(expectedHeader, executionHeader);
        }
Exemple #2
0
        public async Task If_InUsingBlockAndNoExecutionTokenExists_ThenExecutionTokenCreatedAutomatically()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            // ACT
            var  executionsHelper = new ExecutionsHelper();
            bool startedOk;
            ExecutionTokenStatus tokenStatusAfterStart;
            ExecutionTokenStatus tokenStatusAfterUsingBlock;

            using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
            {
                startedOk = await executionContext.TryStartAsync();

                tokenStatusAfterStart = executionsHelper.GetExecutionTokenStatus(TestConstants.ApplicationName, TestConstants.TaskName);
            }

            await Task.Delay(1000);

            tokenStatusAfterUsingBlock = executionsHelper.GetExecutionTokenStatus(TestConstants.ApplicationName, TestConstants.TaskName);

            // ASSERT
            Assert.True(startedOk);
            Assert.Equal(ExecutionTokenStatus.Unavailable, tokenStatusAfterStart);
            Assert.Equal(ExecutionTokenStatus.Available, tokenStatusAfterUsingBlock);
        }
        public void If_TimeOverrideMode_OneTaskAndOneTokenAndIsUnavailableAndGrantedDateHasPassedElapsedTime_ThenIsGranted()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest = CreateOverrideStartRequest();

            startRequest.OverrideThreshold = new TimeSpan(0, 0, 5);
            var secondRequest = CreateOverrideStartRequest();

            secondRequest.OverrideThreshold = new TimeSpan(0, 0, 5);

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

            Thread.Sleep(6000);

            var secondResponse = sut.Start(secondRequest);

            // ASSERT
            Assert.AreEqual(GrantStatus.Granted, firstResponse.GrantStatus);
            Assert.AreEqual(GrantStatus.Granted, secondResponse.GrantStatus);
            Assert.AreNotEqual("0", secondResponse.ExecutionTokenId);
        }
Exemple #4
0
        public async Task If_TryStart_ThenLogCorrectTasklingVersion()
        {
            // ARRANGE
            var executionHelper = new ExecutionsHelper();

            // ACT
            bool startedOk;

            using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
            {
                startedOk = await executionContext.TryStartAsync();

                var sqlServerImplAssembly =
                    AppDomain.CurrentDomain.GetAssemblies()
                    .First(x => x.FullName.Contains("Taskling") &&
                           !x.FullName.Contains("Taskling.Sql") &&
                           !x.FullName.Contains("Tests"));
                FileVersionInfo fileVersionInfo   = FileVersionInfo.GetVersionInfo(sqlServerImplAssembly.Location);
                string          versionOfTaskling = fileVersionInfo.ProductVersion;
                var             executionVersion  = executionHelper.GetLastExecutionVersion(_taskDefinitionId);
                Assert.Equal(versionOfTaskling.Trim(), executionVersion.Trim());
            }

            // ASSERT
        }
Exemple #5
0
        public void If_KeepAliveMode_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.InsertKeepAliveTaskExecution(taskDefinitionId);

            executionHelper.InsertUnavailableCriticalSectionToken(taskDefinitionId, taskExecutionId1);

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

            executionHelper.InsertIntoCriticalSectionQueue(taskDefinitionId, 1, taskExecutionId2);

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

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

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

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

            Assert.AreEqual(1, numberOfQueueRecords);
            Assert.AreEqual(GrantStatus.Denied, response.GrantStatus);
        }
Exemple #6
0
        public async Task If_KeepAliveMode_OneTaskAndOneTokenAndIsUnavailableAndKeepAliveHasPassedElapsedTime_ThenIsGranted()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest = CreateKeepAliveStartRequest();

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

            var secondRequest = CreateKeepAliveStartRequest();

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

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

            executionHelper.SetKeepAlive(firstResponse.TaskExecutionId);

            Thread.Sleep(6000);

            var secondResponse = await sut.StartAsync(secondRequest);

            // ASSERT
            Assert.Equal(GrantStatus.Granted, secondResponse.GrantStatus);
            Assert.NotEqual("0", secondResponse.ExecutionTokenId);
        }
        public async Task If_TimeOverrideMode_OneTaskAndOneTokenAndIsUnavailableAndKeepAliveHasNotPassedElapsedTime_ThenIsDenied()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest  = CreateOverrideStartRequest();
            var secondRequest = CreateOverrideStartRequest();

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

            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);
        }
        public void If_KeepAliveMode_OneToken_MultipleTaskThreads_ThenNoDeadLocksOccur()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            // ACT
            var sut   = CreateSut();
            var tuple = new Tuple <int, TaskExecutionRepository>(taskDefinitionId, sut);

            var tasks = new List <Task>();

            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));
            tasks.Add(Task.Factory.StartNew(RequestAndReturnTokenWithKeepAliveMode, tuple, TaskCreationOptions.LongRunning));

            Task.WaitAll(tasks.ToArray());

            // ASSERT
        }
Exemple #9
0
        public async Task If_TryStartOverTheConcurrencyLimit_ThenMarkExecutionAsBlocked()
        {
            // ARRANGE
            var executionHelper = new ExecutionsHelper();

            // ACT
            bool startedOk;
            bool startedOkBlockedExec;
            bool isBlocked;

            using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
            {
                startedOk = await executionContext.TryStartAsync();

                using (var executionContextBlocked = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
                {
                    startedOkBlockedExec = await executionContextBlocked.TryStartAsync();
                }
                isBlocked = executionHelper.GetBlockedStatusOfLastExecution(_taskDefinitionId);
            }

            // ASSERT
            Assert.True(isBlocked);
            Assert.True(startedOk);
            Assert.False(startedOkBlockedExec);
        }
        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);
        }
Exemple #11
0
        private void CreateTasksAndExecutionTokens()
        {
            var executionHelper = new ExecutionsHelper();

            executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);
            foreach (var process in _processes)
            {
                int drSecondaryId   = executionHelper.InsertTask(TestConstants.ApplicationName, "DR_" + process);
                int nrSecondaryId   = executionHelper.InsertTask(TestConstants.ApplicationName, "NR_" + process);
                int lsucSecondaryId = executionHelper.InsertTask(TestConstants.ApplicationName, "LSUC_" + process);
                int lpcSecondaryId  = executionHelper.InsertTask(TestConstants.ApplicationName, "LPC_" + process);
                int lbcSecondaryId  = executionHelper.InsertTask(TestConstants.ApplicationName, "LBC_" + process);

                int ovdrSecondaryId   = executionHelper.InsertTask(TestConstants.ApplicationName, "OV_DR_" + process);
                int ovnrSecondaryId   = executionHelper.InsertTask(TestConstants.ApplicationName, "OV_NR_" + process);
                int ovlsucSecondaryId = executionHelper.InsertTask(TestConstants.ApplicationName, "OV_LSUC_" + process);
                int ovlpcSecondaryId  = executionHelper.InsertTask(TestConstants.ApplicationName, "OV_LPC_" + process);
                int ovlbcSecondaryId  = executionHelper.InsertTask(TestConstants.ApplicationName, "OV_LBC_" + process);

                executionHelper.InsertAvailableExecutionToken(drSecondaryId);
                executionHelper.InsertAvailableExecutionToken(nrSecondaryId);
                executionHelper.InsertAvailableExecutionToken(lsucSecondaryId);
                executionHelper.InsertAvailableExecutionToken(lpcSecondaryId);
                executionHelper.InsertAvailableExecutionToken(lbcSecondaryId);

                executionHelper.InsertAvailableExecutionToken(ovdrSecondaryId);
                executionHelper.InsertAvailableExecutionToken(ovnrSecondaryId);
                executionHelper.InsertAvailableExecutionToken(ovlsucSecondaryId);
                executionHelper.InsertAvailableExecutionToken(ovlpcSecondaryId);
                executionHelper.InsertAvailableExecutionToken(ovlbcSecondaryId);
            }
        }
        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);
        }
Exemple #13
0
        public void If_InUsingBlock_ThenExecutionCompletedOnEndOfBlock()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            // ACT
            var  executionsHelper = new ExecutionsHelper();
            bool startedOk;
            ExecutionTokenStatus tokenStatusAfterStart;
            ExecutionTokenStatus tokenStatusAfterUsingBlock;

            using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
            {
                startedOk             = executionContext.TryStart();
                tokenStatusAfterStart = executionsHelper.GetExecutionTokenStatus(TestConstants.ApplicationName, TestConstants.TaskName);
            }
            tokenStatusAfterUsingBlock = executionsHelper.GetExecutionTokenStatus(TestConstants.ApplicationName, TestConstants.TaskName);

            // ASSERT
            Assert.AreEqual(true, startedOk);
            Assert.AreEqual(ExecutionTokenStatus.Unavailable, tokenStatusAfterStart);
            Assert.AreEqual(ExecutionTokenStatus.Available, tokenStatusAfterUsingBlock);
        }
        public void If_TimeOverrideMode_OneToken_MultipleTaskThreads_ThenNoDeadLocksOccur()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            // ACT
            var sut   = CreateSut();
            var tasks = new List <Task>();

            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));
            tasks.Add(Task.Run(async() => await RequestAndReturnTokenWithTimeOverrideModeAsync(sut)));

            Task.WaitAll(tasks.ToArray());

            // ASSERT
        }
        public async Task If_TimeOverrideMode_FiveConcurrentTasksAndFourTokensAndAllAreAvailable_ThenIsGrantFirstFourTasksAndDenyTheOther()
        {
            // ARRANGE
            int concurrencyLimit = 4;
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId, concurrencyLimit);

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

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

            var secondResponse = await sut.StartAsync(secondStartRequest);

            var thirdResponse = await sut.StartAsync(thirdStartRequest);

            var fourthResponse = await sut.StartAsync(fourthStartRequest);

            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);
        }
Exemple #16
0
        public When_TryStart_AsKeepAliveMode()
        {
            var executionHelper = new ExecutionsHelper();

            executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            TaskRepository.ClearCache();
        }
        public void Initialize()
        {
            var executionHelper = new ExecutionsHelper();

            executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            TaskRepository.ClearCache();
        }
Exemple #18
0
        public When_GetLastExecutionMeta()
        {
            var executionHelper = new ExecutionsHelper();

            executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            _taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
        }
Exemple #19
0
        public void Initialize()
        {
            var executionHelper = new ExecutionsHelper();

            executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            _taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
        }
        public When_GetRangeBlocksFromExecutionContext()
        {
            _blocksHelper = new BlocksHelper();
            _blocksHelper.DeleteBlocks(TestConstants.ApplicationName);
            _executionHelper = new ExecutionsHelper();
            _executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            _taskDefinitionId = _executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
            _executionHelper.InsertAvailableExecutionToken(_taskDefinitionId);
        }
        public void Initialize()
        {
            _executionHelper = new ExecutionsHelper();
            _executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);
            _blocksHelper = new BlocksHelper();
            _blocksHelper.DeleteBlocks(TestConstants.ApplicationName);

            _taskDefinitionId = _executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
            _executionHelper.InsertAvailableExecutionToken(_taskDefinitionId);
        }
Exemple #22
0
        public When_ConcurrentIsThreadSafe()
        {
            _blocksHelper = new BlocksHelper();
            _blocksHelper.DeleteBlocks(TestConstants.ApplicationName);
            _executionHelper = new ExecutionsHelper();
            _executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            var taskDefinitionId = _executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            _executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId);
        }
        public void Initialize()
        {
            _blocksHelper = new BlocksHelper();
            _blocksHelper.DeleteBlocks(TestConstants.ApplicationName);
            _executionHelper = new ExecutionsHelper();
            _executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            _taskDefinitionId = _executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
            _executionHelper.InsertUnlimitedExecutionToken(_taskDefinitionId);

            TaskRepository.ClearCache();
        }
Exemple #24
0
        public When_FindDeadBlocks()
        {
            _blocksHelper = new BlocksHelper();
            _blocksHelper.DeleteBlocks(TestConstants.ApplicationName);
            _executionHelper = new ExecutionsHelper();
            _executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            _taskDefinitionId = _executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
            _executionHelper.InsertAvailableExecutionToken(_taskDefinitionId);

            TaskRepository.ClearCache();
        }
Exemple #25
0
        public When_GetLastNumericRangeBlock(ITestOutputHelper output)
        {
            this.output   = output;
            _blocksHelper = new BlocksHelper();
            _blocksHelper.DeleteBlocks(TestConstants.ApplicationName);
            _executionHelper = new ExecutionsHelper();
            _executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName);

            _taskDefinitionId = _executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);
            _executionHelper.InsertUnlimitedExecutionToken(_taskDefinitionId);

            TaskRepository.ClearCache();
        }
Exemple #26
0
        public void If_LastExecutionDead_ThenReturnStatusIsDead()
        {
            // ARRANGE, ACT, ASSERT
            using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
            {
                executionContext.TryStart();
                Thread.Sleep(200);
                var helper = new ExecutionsHelper();
                helper.SetLastExecutionAsDead(_taskDefinitionId);

                using (var executionContext2 = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing()))
                {
                    var executionMeta = executionContext2.GetLastExecutionMeta();
                    Assert.AreEqual(Taskling.Tasks.TaskExecutionStatus.Dead, executionMeta.Status);
                }
            }
        }
Exemple #27
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);
        }
        public async Task If_TimeOverrideMode_OneTaskAndOneTokenAndIsAvailable_ThenIsGranted()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest = CreateOverrideStartRequest();

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

            // ASSERT
            Assert.Equal(GrantStatus.Granted, response.GrantStatus);
            Assert.NotEqual("0", response.ExecutionTokenId);
        }
        public async Task If_TimeOverrideMode_ThenReturnsValidDataValues()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest = CreateOverrideStartRequest();

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

            // ASSERT
            Assert.True(response.TaskExecutionId != "0");
            Assert.True(response.StartedAt > DateTime.MinValue);
        }
        public void If_KeepAliveMode_OneTaskAndOneTokenAndIsAvailable_ThenIsGranted()
        {
            // ARRANGE
            var executionHelper  = new ExecutionsHelper();
            var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName);

            executionHelper.InsertAvailableExecutionToken(taskDefinitionId);

            var startRequest = CreateKeepAliveStartRequest();

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

            // ASSERT
            Assert.AreEqual(GrantStatus.Granted, response.GrantStatus);
            Assert.AreNotEqual("0", response.ExecutionTokenId);
        }