Exemple #1
0
        public async Task Add_ShallAddItem()
        {
            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.Instances.Add(InstanceGenerator.GenerateInstance("./aet", "aet", fileSystem: _fileSystem));

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

            await jobStore.Add(job);

            _inferenceJobRepository.Verify(p => p.AddAsync(It.IsAny <InferenceJob>(), It.IsAny <CancellationToken>()), Times.Once());
            _inferenceJobRepository.Verify(p => p.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
Exemple #2
0
        public async Task Add_ShallRetryOnFailure()
        {
            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.Instances.Add(InstanceGenerator.GenerateInstance("./aet", "aet", fileSystem: _fileSystem));

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

            _inferenceJobRepository.Setup(p => p.AddAsync(It.IsAny <InferenceJob>(), It.IsAny <CancellationToken>())).Throws(new Exception("error"));

            await Assert.ThrowsAsync <Exception>(async() => await jobStore.Add(job));

            _logger.VerifyLoggingMessageBeginsWith($"Error saving inference job.", LogLevel.Error, Times.Exactly(3));
        }
Exemple #3
0
        public async Task Add_ShallRetryCopyThenThrow()
        {
            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(p => p.Directory).Returns(_fileSystem.Directory);
            fileSystem.Setup(p => p.Path).Returns(_fileSystem.Path);
            fileSystem.Setup(p => p.File.Create(It.IsAny <string>()))
            .Returns((string path) => _fileSystem.File.Create(path));
            fileSystem.Setup(p => p.File.Copy(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .Throws(new IOException("error", ClaraJobRepository.ERROR_DISK_FULL));

            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.SetStoragePath("/path/to/job");
            job.Instances.Add(InstanceGenerator.GenerateInstance("./aet", "aet", fileSystem: fileSystem.Object));
            _configuration.Value.Storage.Temporary = "./aet";

            var cancellationSource = new CancellationTokenSource();

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

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

            await Assert.ThrowsAsync <IOException>(async() => await jobStore.Add(job));

            _logger.VerifyLoggingMessageBeginsWith($"Error copying file to {job.JobPayloadsStoragePath}; destination may be out of disk space, will retry in {1000}ms.", LogLevel.Error, Times.Exactly(3));
            _logger.VerifyLoggingMessageBeginsWith($"Error copying file to {job.JobPayloadsStoragePath}; destination may be out of disk space.  Exceeded maximum retries.", LogLevel.Error, Times.Once());
        }
Exemple #4
0
        public async Task Add_ThrowsWhenFailToCopy()
        {
            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(p => p.Directory).Returns(_fileSystem.Directory);
            fileSystem.Setup(p => p.Path).Returns(_fileSystem.Path);
            fileSystem.Setup(p => p.File.Create(It.IsAny <string>()))
            .Returns((string path) => _fileSystem.File.Create(path));
            fileSystem.Setup(p => p.File.Copy(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())).Throws(new Exception("error"));

            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.SetStoragePath("/path/to/job");
            job.Instances.Add(InstanceGenerator.GenerateInstance("./aet", "aet", fileSystem: fileSystem.Object));
            _configuration.Value.Storage.Temporary = "./aet";

            var cancellationSource = new CancellationTokenSource();

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

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

            await Assert.ThrowsAsync <Exception>(async() => await jobStore.Add(job));

            _logger.VerifyLoggingMessageBeginsWith($"Failed to copy file {job.JobPayloadsStoragePath}.", LogLevel.Error, Times.Once());
        }