예제 #1
0
        public async Task Acquire_Job_Where_Due_Time_Is_Greater_Than_Now_Should_Return_Null()
        {
            var date = new DateTime(2017, 1, 2, 3, 4, 5);

            DateService.GetNow().Returns(date);

            var job1 = new JobDescription
            {
                Id      = Guid.NewGuid(),
                State   = ExecutionState.Waiting,
                DueTime = new DateTime(2017, 1, 2, 3, 4, 6),
                Type    = "type"
            };

            var jobs = new List <JobDescription>
            {
                job1
            };

            await Store.AddJobsAsync(jobs);

            var r1 = await Store.AcquireJobAsync();

            Assert.Null(r1);


            date = date.AddSeconds(1);

            DateService.GetNow().Returns(date);

            var r2 = await Store.AcquireJobAsync();

            Assert.Equal(job1.Id, r2.Id);
        }
예제 #2
0
        public async Task Acquire_Job_Should_Update_State()
        {
            //Arrange
            var job1 = new JobDescription
            {
                Id        = Guid.NewGuid(),
                WaitCount = 0,
                State     = ExecutionState.Waiting,
                Type      = "type"
            };

            var jobs = new List <JobDescription>
            {
                job1
            };

            var date = new DateTime(2017, 1, 2, 3, 4, 5);

            DateService.GetNow().Returns(date);

            //Act
            await Store.AddJobsAsync(jobs);

            var result = await Store.AcquireJobAsync();

            //Assert
            Assert.Equal(ExecutionState.Running, result.State);
            Assert.Equal(date, result.UpdatedTime);
        }
예제 #3
0
        public async Task Acquire_Job_With_Input()
        {
            //Arrange
            var data = new TestData
            {
                Text   = "text",
                Number = 123
            };

            var date = new DateTime(2018, 1, 2, 3, 4, 5);

            DateService.GetNow().Returns(date);

            var job1 = new JobDescription
            {
                Id    = Guid.NewGuid(),
                Input = new JobInputDescription
                {
                    InputData = data,
                    Type      = typeof(TestData).AssemblyQualifiedName
                },
                State       = ExecutionState.Waiting,
                DueTime     = new DateTime(2017, 1, 2, 3, 4, 5),
                Type        = "type",
                Priority    = 100,
                PrevId      = Guid.NewGuid(),
                NextId      = Guid.NewGuid(),
                BatchId     = Guid.NewGuid(),
                CreatedTime = new DateTime(2016, 1, 2, 3, 4, 5),
                WaitCount   = 0,
                StatusInfo  = "status"
            };

            var jobs = new List <JobDescription>
            {
                job1
            };

            //Act
            await Store.AddJobsAsync(jobs);

            var result = await Store.AcquireJobAsync();

            //Assert
            var inputResult = (TestData)result.Input.InputData;

            Assert.Equal(data.Text, inputResult.Text);
            Assert.Equal(data.Number, inputResult.Number);

            Assert.Equal(job1.Id, result.Id);
            Assert.Equal(ExecutionState.Running, result.State);
            Assert.Equal(job1.DueTime, result.DueTime);
            Assert.Equal(job1.Type, result.Type);
            Assert.Equal(job1.Priority, result.Priority);
            Assert.Equal(job1.PrevId, result.PrevId);
            Assert.Equal(job1.NextId, result.NextId);
            Assert.Equal(job1.BatchId, result.BatchId);
            Assert.Equal(job1.CreatedTime, result.CreatedTime);
            Assert.Equal(job1.WaitCount, result.WaitCount);
            Assert.Equal(job1.StatusInfo, result.StatusInfo);
            Assert.Equal(date, result.UpdatedTime);
        }