Ejemplo n.º 1
0
        public async Task GivenATaskCanceledButNotComplete_WhenCreateTaskBySameType_ConflictShouldBeReturned()
        {
            string queueId    = Guid.NewGuid().ToString();
            string inputData  = "inputData";
            short  uniqueType = 4321;

            TaskInfo taskInfo = new TaskInfo()
            {
                TaskId     = Guid.NewGuid().ToString(),
                QueueId    = queueId,
                TaskTypeId = uniqueType,
                InputData  = inputData,
            };

            SqlServerTaskManager sqlServerTaskManager = new SqlServerTaskManager(_fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskManager> .Instance);

            _ = await sqlServerTaskManager.CreateTaskAsync(taskInfo, true, CancellationToken.None);

            _ = await sqlServerTaskManager.CancelTaskAsync(taskInfo.TaskId, CancellationToken.None);

            taskInfo = new TaskInfo()
            {
                TaskId     = Guid.NewGuid().ToString(),
                QueueId    = queueId,
                TaskTypeId = uniqueType,
                InputData  = inputData,
            };

            await Assert.ThrowsAnyAsync <TaskConflictException>(async() => await sqlServerTaskManager.CreateTaskAsync(taskInfo, true, CancellationToken.None));
        }
Ejemplo n.º 2
0
        public async Task GivenASqlTaskManager_WhenCancelTask_ThenTaskStatusShouldBeChanged()
        {
            string queueId   = Guid.NewGuid().ToString();
            string taskId    = Guid.NewGuid().ToString();
            string inputData = "inputData";

            TaskInfo taskInfo = new TaskInfo()
            {
                TaskId     = taskId,
                QueueId    = queueId,
                TaskTypeId = SqlServerTaskManagerTestsTypeId,
                InputData  = inputData,
            };

            SqlServerTaskManager sqlServerTaskManager = new SqlServerTaskManager(_fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskManager> .Instance);

            _ = await sqlServerTaskManager.CreateTaskAsync(taskInfo, false, CancellationToken.None);

            TaskInfo canceledTask = await sqlServerTaskManager.CancelTaskAsync(taskId, CancellationToken.None);

            Assert.True(canceledTask.IsCanceled);
        }
        public async Task GivenATaskCreated_WhenTaskCanceled_ThenCanBePickedUp()
        {
            string queueId = Guid.NewGuid().ToString();
            TaskHostingConfiguration config = new TaskHostingConfiguration()
            {
                Enabled = true,
                QueueId = queueId,
                TaskHeartbeatTimeoutThresholdInSeconds = 60,
            };

            IOptions <TaskHostingConfiguration> taskHostingConfig = Substitute.For <IOptions <TaskHostingConfiguration> >();

            taskHostingConfig.Value.Returns(config);
            SqlServerTaskManager  sqlServerTaskManager  = new SqlServerTaskManager(_fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskManager> .Instance);
            SqlServerTaskConsumer sqlServerTaskConsumer = new SqlServerTaskConsumer(taskHostingConfig, _fixture.SqlConnectionWrapperFactory, NullLogger <SqlServerTaskConsumer> .Instance);

            string taskId    = Guid.NewGuid().ToString();
            string inputData = "inputData";

            TaskInfo taskInfo = new TaskInfo()
            {
                TaskId        = taskId,
                QueueId       = queueId,
                TaskTypeId    = SqlServerTaskConsumerTestsTypeId,
                InputData     = inputData,
                MaxRetryCount = 1,
            };

            _ = await sqlServerTaskManager.CreateTaskAsync(taskInfo, false, CancellationToken.None);

            _ = await sqlServerTaskManager.CancelTaskAsync(taskInfo.TaskId, CancellationToken.None);

            var taskInfoResult = (await sqlServerTaskConsumer.GetNextMessagesAsync(1, 60, CancellationToken.None)).First();

            Assert.Equal(taskInfo.TaskId, taskInfoResult.TaskId);
        }