public void Initialize() { var executionHelper = new ExecutionsHelper(); executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName); TaskRepository.ClearCache(); }
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 Initialize() { var executionHelper = new ExecutionsHelper(); executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName); _taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); }
public void If_KeepAliveMode_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.InsertKeepAliveTaskExecution(taskDefinitionId); executionHelper.InsertUnavailableCriticalSectionToken(taskDefinitionId, taskExecutionId1); // Create second execution var taskExecutionId2 = executionHelper.InsertKeepAliveTaskExecution(taskDefinitionId); var request = new StartCriticalSectionRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName), taskExecutionId2, TaskDeathMode.KeepAlive, CriticalSectionType.User); request.KeepAliveDeathThreshold = 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 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); }
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 Initialize() { _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() { _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(); }
public void If_KeepAlive_ThenKeepAliveContinuesUntilExecutionContextDies() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); executionHelper.InsertAvailableExecutionToken(taskDefinitionId); // ACT StartContextWithoutUsingOrComplete(); GC.Collect(0, GCCollectionMode.Forced); // referenceless context is collected Thread.Sleep(6000); // ASSERT var expectedLastKeepAliveMax = DateTime.UtcNow.AddSeconds(-5); var lastKeepAlive = executionHelper.GetLastKeepAlive(taskDefinitionId); Assert.IsTrue(lastKeepAlive < expectedLastKeepAliveMax); }
public void 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 = sut.Start(startRequest); // ASSERT Assert.AreEqual(GrantStatus.Granted, response.GrantStatus); Assert.AreNotEqual("0", response.ExecutionTokenId); }
public void If_KeepAliveMode_ThenReturnsValidDataValues() { // 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.IsTrue(response.TaskExecutionId != "0"); Assert.IsTrue(response.StartedAt > DateTime.MinValue); }
public void If_Checkpoint_ThenCheckpointEventCreated() { // ARRANGE var executionHelper = new ExecutionsHelper(); // ACT bool startedOk; Tuple<EventType, string> lastEvent = null; using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing())) { startedOk = executionContext.TryStart(); executionContext.Checkpoint("Test checkpoint"); lastEvent = executionHelper.GetLastEvent(_taskDefinitionId); } // ASSERT Assert.AreEqual(EventType.CheckPoint, lastEvent.Item1); Assert.AreEqual("Test checkpoint", lastEvent.Item2); }
public void If_KeepAliveMode_TokenAvailableAndNothingInQueue_ThenGrant() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); var taskExecutionId = executionHelper.InsertKeepAliveTaskExecution(taskDefinitionId); executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId); var request = new StartCriticalSectionRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName), taskExecutionId, TaskDeathMode.KeepAlive, CriticalSectionType.User); request.KeepAliveDeathThreshold = new TimeSpan(0, 1, 0); // ACT var sut = CreateSut(); var response = sut.Start(request); // ASSERT Assert.AreEqual(GrantStatus.Granted, response.GrantStatus); }
public void If_TryStart_ThenLogCorrectTasklingVersion() { // ARRANGE var executionHelper = new ExecutionsHelper(); // ACT bool startedOk; using (var executionContext = ClientHelper.GetExecutionContext(TestConstants.TaskName, ClientHelper.GetDefaultTaskConfigurationWithKeepAliveAndReprocessing())) { startedOk = executionContext.TryStart(); var sqlServerImplAssembly = AppDomain.CurrentDomain.GetAssemblies() .First(x => x.FullName.Contains("Taskling.SqlServer")); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(sqlServerImplAssembly.Location); string versionOfTaskling = fileVersionInfo.ProductVersion; var executionVersion = executionHelper.GetLastExecutionVersion(_taskDefinitionId); Assert.AreEqual(versionOfTaskling.Trim(), executionVersion.Trim()); } // ASSERT }
public void If_TryStartWithHeader_ThenGetHeaderReturnsTheHeader() { // 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>(); Assert.AreEqual(myHeader.Name, myHeaderBack.Name); Assert.AreEqual(myHeader.Id, myHeaderBack.Id); } // ASSERT }
public void 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 = sut.Start(firstStartRequest); executionHelper.SetKeepAlive(firstResponse.TaskExecutionId); var secondResponse = sut.Start(secondStartRequest); executionHelper.SetKeepAlive(secondResponse.TaskExecutionId); var thirdResponse = sut.Start(thirdStartRequest); executionHelper.SetKeepAlive(thirdResponse.TaskExecutionId); var fourthResponse = sut.Start(fourthStartRequest); executionHelper.SetKeepAlive(fourthResponse.TaskExecutionId); var fifthResponse = sut.Start(fifthStartRequest); // ASSERT Assert.AreEqual(GrantStatus.Granted, firstResponse.GrantStatus); Assert.AreEqual(GrantStatus.Granted, secondResponse.GrantStatus); Assert.AreEqual(GrantStatus.Granted, thirdResponse.GrantStatus); Assert.AreEqual(GrantStatus.Granted, fourthResponse.GrantStatus); Assert.AreEqual(GrantStatus.Denied, fifthResponse.GrantStatus); }
private void CreateDeadTask() { using (var executionContext = CreateTaskExecutionContextWithNoReprocessing()) { var startedOk = executionContext.TryStart(); if (startedOk) { var values = GetPersonList(6); short maxBlockSize = 3; var listBlocks = executionContext.GetListBlocks<PersonDto>(x => x.WithPeriodicCommit(values, maxBlockSize, BatchSize.Ten)); foreach (var listBlock in listBlocks) { listBlock.Start(); } } } var executionHelper = new ExecutionsHelper(); executionHelper.SetLastExecutionAsDead(_taskDefinitionId); }
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 }
private void CreateDeadNumericTask() { using (var executionContext = CreateTaskExecutionContextWithNoReprocessing()) { var startedOk = executionContext.TryStart(); if (startedOk) { long from = 31; long to = 60; short maxBlockSize = 10; var numericBlocks = executionContext.GetNumericRangeBlocks(x => x.WithRange(from, to, maxBlockSize)); foreach (var block in numericBlocks) { block.Start(); } } } var executionHelper = new ExecutionsHelper(); executionHelper.SetLastExecutionAsDead(_taskDefinitionId); }
public void If_KeepAliveMode_TwoSequentialTasksAndOneTokenAndIsAvailable_ThenIsGrantFirstTaskAndThenGrantTheOther() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); executionHelper.InsertAvailableExecutionToken(taskDefinitionId); var firstStartRequest = CreateKeepAliveStartRequest(); var secondStartRequest = CreateKeepAliveStartRequest(); // ACT var sut = CreateSut(); var firstStartResponse = sut.Start(firstStartRequest); var firstCompleteRequest = new TaskExecutionCompleteRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName), firstStartResponse.TaskExecutionId, firstStartResponse.ExecutionTokenId); var firstCompleteResponse = sut.Complete(firstCompleteRequest); var secondStartResponse = sut.Start(secondStartRequest); // ASSERT Assert.AreEqual(GrantStatus.Granted, firstStartResponse.GrantStatus); Assert.AreEqual(GrantStatus.Granted, secondStartResponse.GrantStatus); }
private void RequestAndReturnTokenWithKeepAliveMode(object state) { var tuple = (Tuple<int, TaskExecutionRepository>)state; var sut = tuple.Item2; for (int i = 0; i < 100; i++) { var firstStartRequest = CreateKeepAliveStartRequest(); var firstStartResponse = sut.Start(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 = sut.Complete(firstCompleteRequest); } } }
public void If_KeepAliveMode_TokenAvailableAndIsNotFirstInQueueButFirstHasCompleted_ThenRemoveBothFromQueueAndGrant() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); executionHelper.InsertUnlimitedExecutionToken(taskDefinitionId); // Create execution 1 and add it to the queue var taskExecutionId1 = executionHelper.InsertKeepAliveTaskExecution(taskDefinitionId); executionHelper.SetKeepAlive(taskExecutionId1); executionHelper.InsertIntoCriticalSectionQueue(taskDefinitionId, 1, taskExecutionId1); executionHelper.SetTaskExecutionAsCompleted(taskExecutionId1); // 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 = new TimeSpan(0, 30, 0); // 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 void 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 = sut.Start(startRequest); executionHelper.SetKeepAlive(firstResponse.TaskExecutionId); Thread.Sleep(5000); var secondResponse = sut.Start(secondRequest); // ASSERT Assert.AreEqual(GrantStatus.Granted, firstResponse.GrantStatus); Assert.AreNotEqual("0", firstResponse.ExecutionTokenId); Assert.AreEqual(GrantStatus.Denied, secondResponse.GrantStatus); Assert.AreEqual("0", secondResponse.ExecutionTokenId); }
public void 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 = sut.Start(request); // ASSERT var numberOfQueueRecords = executionHelper.GetQueueCount(taskExecutionId2); Assert.AreEqual(1, numberOfQueueRecords); Assert.AreEqual(GrantStatus.Denied, response.GrantStatus); }
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_KeepAliveMode_OneTokenExistsAndConcurrencyLimitIsUnlimited_ThenRemoveAvailableTokenAndCreateOneNewUnlimitedToken() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); executionHelper.InsertAvailableExecutionToken(taskDefinitionId); var startRequest = CreateKeepAliveStartRequest(-1); // ACT var sut = CreateSut(); sut.Start(startRequest); // ASSERT var tokensList = executionHelper.GetExecutionTokens(TestConstants.ApplicationName, TestConstants.TaskName); Assert.AreEqual(1, tokensList.Tokens.Count(x => x.Status == ExecutionTokenStatus.Unlimited)); }
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); } } }
private void CreateDeadDateTask() { using (var executionContext = CreateTaskExecutionContextWithNoReprocessing()) { var startedOk = executionContext.TryStart(); if (startedOk) { var from = new DateTime(2016, 1, 4); var to = new DateTime(2016, 1, 7); var maxBlockSize = new TimeSpan(1, 0, 0, 0); var dateBlocks = executionContext.GetDateRangeBlocks(x => x.WithRange(from, to, maxBlockSize)); foreach (var block in dateBlocks) { block.Start(); } } } var executionHelper = new ExecutionsHelper(); executionHelper.SetLastExecutionAsDead(_taskDefinitionId); }
public void Initialize() { var executionHelper = new ExecutionsHelper(); executionHelper.DeleteRecordsOfApplication(TestConstants.ApplicationName); }
public void If_KeepAliveMode_TwoUnavailableTokensExistsAndConcurrencyLimitIsOne_ThenRemoveOneUnavailableToken() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); executionHelper.InsertExecutionToken(taskDefinitionId, new List<Tuple<ExecutionTokenStatus, string>>() { new Tuple<ExecutionTokenStatus, string>(ExecutionTokenStatus.Unavailable, "0"), new Tuple<ExecutionTokenStatus, string>(ExecutionTokenStatus.Unavailable, "1") }); var startRequest = CreateKeepAliveStartRequest(1); // ACT var sut = CreateSut(); sut.Start(startRequest); // ASSERT var tokensList = executionHelper.GetExecutionTokens(TestConstants.ApplicationName, TestConstants.TaskName); Assert.AreEqual(1, tokensList.Tokens.Count(x => x.Status == ExecutionTokenStatus.Unavailable)); }