Esempio n. 1
0
 private JobDescription CreateJobWithReturnData(TestJobWithReturnData.TestData data)
 {
     return(new JobDescription
     {
         Type = typeof(TestJobWithReturnData).AssemblyQualifiedName,
         Input = new JobInputDescription
         {
             Type = data.GetType().AssemblyQualifiedName,
             InputData = data
         }
     });
 }
Esempio n. 2
0
        public async Task Successful_Job_Should_Release_With_Given_Result()
        {
            //Arrange
            var settings = new BatchSettings
            {
                NumberOfParallelJobs = 1,
                PollingFrequency     = 50,
                HeartBeatFrequency   = 5000,
            };

            var data = new TestJobWithReturnData.TestData
            {
                State      = ExecutionState.Halted,
                StatusInfo = "info",
                DueTime    = new DateTime(2018, 1, 2, 3, 4, 5)
            };

            var job = CreateJobWithReturnData(data);

            job.Id = Guid.NewGuid();

            _store.AcquireJobAsync().Returns(Task.FromResult(job), Task.FromResult((JobDescription)null));

            JobResult result = null;

            await _store.ReleaseJobAsync(job.Id, Arg.Do <JobResult>(x => result = x));

            //Act
            using (var engine = new BatchEngine(_store, _dependencyResolver, _logger, settings))
            {
                engine.Start();

                await Task.Delay(10);
            }

            //Assert
            Assert.Equal(data.State, result.State);
            Assert.Equal(data.StatusInfo, result.StatusInfo);
            Assert.Equal(data.DueTime, result.DueTime);

            await _store.Received(1).ReleaseJobAsync(job.Id, result);

            AssertNoErrorsLogged();
        }
Esempio n. 3
0
        public async Task Polling_Frequency_Zero_Should_Release_Semaphore()
        {    //Arrange
            var settings = new BatchSettings
            {
                NumberOfParallelJobs = 1,
                PollingFrequency     = 0,
                HeartBeatFrequency   = 5000,
            };

            var data = new TestJobWithReturnData.TestData
            {
                State      = ExecutionState.Waiting,
                StatusInfo = "info",
                DueTime    = new DateTime(2018, 1, 2, 3, 4, 5)
            };

            var job = CreateJobWithReturnData(data);

            job.Id = Guid.NewGuid();

            _store.AcquireJobAsync().Returns(Task.FromResult(job), Task.FromResult((JobDescription)null), Task.FromResult(job), Task.FromResult((JobDescription)null));

            //Act
            using (var engine = new BatchEngine(_store, _dependencyResolver, _logger, settings))
            {
                engine.Start();

                await Task.Delay(200);
            }

            //Assert

            await _store.Received(2).ReleaseJobAsync(job.Id, Arg.Any <JobResult>());

            AssertNoErrorsLogged();
        }