Exemplo n.º 1
0
        public async Task GivenNoContextUpdates_WhenUpdateJobProgress_NoProgressShouldBeUpdated()
        {
            var typeFilters = new List <TypeFilter> {
                new ("Patient", null), new ("Observation", null)
            };
            var filterInfo = new FilterInfo(FilterScope.System, null, DateTimeOffset.MinValue, typeFilters, null);

            var activeJob = Job.Create(
                ContainerName,
                JobStatus.Running,
                new DataPeriod(DateTimeOffset.MinValue, DateTimeOffset.MaxValue),
                filterInfo);

            var containerClient    = new InMemoryBlobContainerClient();
            var jobProgressUpdater = GetInMemoryJobProgressUpdater(activeJob, containerClient);
            var updateTask         = Task.Run(() => jobProgressUpdater.Consume());

            jobProgressUpdater.Complete();
            await updateTask;

            var persistedJob = await containerClient.GetValue <Job>($"jobs/activeJobs/{activeJob.Id}.json");

            Assert.Equal(activeJob.ToString(), persistedJob.ToString());
        }
Exemplo n.º 2
0
        public async Task GivenTaskUpdateContextTwice_WhenUpdateJobProgress_ProgressShouldBeUpdatedCorrectly()
        {
            var typeFilters = new List <TypeFilter> {
                new("Patient", null), new("Observation", null)
            };
            var filterInfo = new FilterInfo(FilterScope.System, null, DateTimeOffset.MinValue, typeFilters, null);

            var activeJob = Job.Create(
                ContainerName,
                JobStatus.Running,
                new DataPeriod(DateTimeOffset.MinValue, DateTimeOffset.MaxValue),
                filterInfo);

            var context = TaskContext.CreateFromJob(
                activeJob,
                typeFilters);

            var containerClient    = new InMemoryBlobContainerClient();
            var jobProgressUpdater = GetInMemoryJobProgressUpdater(activeJob, containerClient);
            var updateTask         = Task.Run(() => jobProgressUpdater.Consume());

            activeJob.RunningTasks[context.Id] = context;
            activeJob.NextTaskIndex++;

            // context is updated
            context.SearchCount = new Dictionary <string, int>()
            {
                { "Patient", 15 }
            };
            context.SkippedCount = new Dictionary <string, int>()
            {
                { "Patient", 0 }, { "Patient_customized", 2 }
            };
            context.ProcessedCount = new Dictionary <string, int>()
            {
                { "Patient", 10 }, { "Patient_customized", 13 }
            };
            context.OutputFileIndexMap = new Dictionary <string, int>()
            {
                { "Patient", 1 }, { "Patient_customized", 1 }
            };
            context.SearchProgress.ContinuationToken = "exampleContinuationToken";

            // sync up the updated context to job
            await jobProgressUpdater.Produce(context);

            Assert.True(activeJob.RunningTasks.ContainsKey(context.Id));
            Assert.Equal("exampleContinuationToken", activeJob.RunningTasks[context.Id].SearchProgress.ContinuationToken);
            Assert.Empty(activeJob.TotalResourceCounts);
            Assert.Empty(activeJob.ProcessedResourceCounts);
            Assert.Empty(activeJob.SkippedResourceCounts);

            context.IsCompleted = true;
            await jobProgressUpdater.Produce(context);

            jobProgressUpdater.Complete();
            await updateTask;

            Assert.Empty(activeJob.RunningTasks);
            Assert.Equal(15, activeJob.TotalResourceCounts["Patient"]);
            Assert.Equal(10, activeJob.ProcessedResourceCounts["Patient"]);
            Assert.Equal(0, activeJob.SkippedResourceCounts["Patient"]);
            Assert.Equal(13, activeJob.ProcessedResourceCounts["Patient_customized"]);
            Assert.Equal(2, activeJob.SkippedResourceCounts["Patient_customized"]);

            var persistedJob = await containerClient.GetValue <Job>($"jobs/activeJobs/{activeJob.Id}.json");

            Assert.Equal(activeJob.ToString(), persistedJob.ToString());
            Assert.Empty(persistedJob.RunningTasks);
            Assert.Equal(15, persistedJob.TotalResourceCounts["Patient"]);
            Assert.Equal(10, persistedJob.ProcessedResourceCounts["Patient"]);
            Assert.Equal(0, persistedJob.SkippedResourceCounts["Patient"]);
        }