コード例 #1
0
        public async Task Take_ShallReturnAJob(InferenceJobState initalState, InferenceJobState endingState)
        {
            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.SetStoragePath("/path/to/job");
            job.State = initalState;

            var cancellationSource = new CancellationTokenSource();

            _inferenceJobRepository.SetupSequence(p => p.AsQueryable())
            .Returns((new List <InferenceJob>()
            {
                job
            }).AsQueryable());

            var jobStore = new ClaraJobRepository(
                _logger.Object,
                _configuration,
                _fileSystem,
                _inferenceJobRepository.Object);

            var result = await jobStore.Take(cancellationSource.Token);

            Assert.Equal(job, result);
            Assert.Equal(endingState, job.State);
            _logger.VerifyLoggingMessageBeginsWith($"Updating inference job {job.JobId} from {initalState } to {endingState}.", LogLevel.Information, Times.Once());
        }
コード例 #2
0
        public async Task Take_ShallThrowWhenCancelled()
        {
            var cancellationSource = new CancellationTokenSource();

            _inferenceJobRepository.Setup(p => p.AsQueryable())
            .Returns((new List <InferenceJob>()).AsQueryable());

            var jobStore = new ClaraJobRepository(
                _logger.Object,
                _configuration,
                _fileSystem,
                _inferenceJobRepository.Object);

            cancellationSource.CancelAfter(100);
            await Assert.ThrowsAsync <OperationCanceledException>(async() => await jobStore.Take(cancellationSource.Token));
        }