public InsertTask ( string applicationName, string taskName ) : int | ||
applicationName | string | |
taskName | string | |
리턴 | int |
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_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 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_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_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_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_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_TimeOverrideMode_TwoConcurrentTasksAndOneTokenAndIsAvailable_ThenIsGrantFirstTaskAndDenyTheOther() { // ARRANGE var executionHelper = new ExecutionsHelper(); var taskDefinitionId = executionHelper.InsertTask(TestConstants.ApplicationName, TestConstants.TaskName); executionHelper.InsertAvailableExecutionToken(taskDefinitionId); var firstStartRequest = CreateOverrideStartRequest(); var secondStartRequest = CreateOverrideStartRequest(); // ACT var sut = CreateSut(); var firstResponse = sut.Start(firstStartRequest); var secondResponse = sut.Start(secondStartRequest); // ASSERT Assert.AreEqual(GrantStatus.Granted, firstResponse.GrantStatus); Assert.AreEqual(GrantStatus.Denied, secondResponse.GrantStatus); }
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_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_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); }
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_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 }
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); }
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)); }
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); }