Beispiel #1
0
        public async Task GetFinishedJobRuns_OutsideTimeWindow_ReturnsNoFinishedJobs()
        {
            // Arrange
            DateTimeOffset startWindow = BogusGenerator.Date.RecentOffset();
            DateTimeOffset endWindow   = BogusGenerator.Date.SoonOffset();

            IEnumerable <Run> includedRuns = CreateRandomRuns(startWindow, endWindow);
            IEnumerable <Run> tooLateRuns  = CreateRandomRuns(endWindow, BogusGenerator.Date.FutureOffset());
            IEnumerable <Run> allRuns      = includedRuns.Concat(tooLateRuns);
            IEnumerable <Job> jobs         = includedRuns.Select(r => new Job
            {
                JobId    = r.JobId,
                Settings = new JobSettings {
                    Name = Guid.NewGuid().ToString()
                }
            }).ToArray();

            DatabricksClient client = DatabricksClientFactory.Create(allRuns, jobs);
            var provider            = new DatabricksInfoProvider(client, NullLogger.Instance);

            // Act
            IEnumerable <JobRun> finishedJobs = await provider.GetFinishedJobRunsAsync(BogusGenerator.Date.PastOffset(), startWindow);

            // Assert
            Assert.Empty(finishedJobs);
        }
Beispiel #2
0
        public async Task GetFinishedJobRuns_WithEndTimeLessThanStartTime_Throws()
        {
            // Arrange
            DateTimeOffset   startWindow = BogusGenerator.Date.SoonOffset();
            DateTimeOffset   endWindow   = BogusGenerator.Date.RecentOffset();
            DatabricksClient client      = DatabricksClientFactory.Create(Enumerable.Empty <Run>(), Enumerable.Empty <Job>());
            var provider = new DatabricksInfoProvider(client, NullLogger.Instance);

            // Act / Assert
            await Assert.ThrowsAnyAsync <ArgumentException>(() => provider.GetFinishedJobRunsAsync(startWindow, endWindow));
        }
Beispiel #3
0
        public async Task GetFinishedJobRuns_WithNoAvailableFinishedJobs_ReturnsNoFinishedJobs()
        {
            // Arrange
            DateTimeOffset startWindow = BogusGenerator.Date.RecentOffset();
            DateTimeOffset endWindow   = BogusGenerator.Date.SoonOffset();

            DatabricksClient client = DatabricksClientFactory.Create(Enumerable.Empty <Run>(), Enumerable.Empty <Job>());
            var provider            = new DatabricksInfoProvider(client, NullLogger.Instance);

            // Act
            IEnumerable <JobRun> finishedJobs = await provider.GetFinishedJobRunsAsync(startWindow, endWindow);

            // Assert
            Assert.Empty(finishedJobs);
        }
Beispiel #4
0
        public async Task MeasureJobOutcomes_WithNoAvailableFinishedJobs_ReturnsNoFinishedJobs()
        {
            // Arrange
            DateTimeOffset startWindow = BogusGenerator.Date.RecentOffset();
            DateTimeOffset endWindow   = BogusGenerator.Date.SoonOffset();
            string         metricName  = BogusGenerator.Random.Word();

            DatabricksClient client = DatabricksClientFactory.Create(Enumerable.Empty <Run>(), Enumerable.Empty <Job>());
            var spyLogger           = new InMemoryLogger <DatabricksJobMetricsJob>();
            var provider            = new DatabricksInfoProvider(client, spyLogger);

            // Act
            await provider.MeasureJobOutcomesAsync(metricName, startWindow, endWindow);

            // Assert
            Assert.DoesNotContain(spyLogger.Messages, msg => msg.StartsWith("Metric " + metricName));
        }
Beispiel #5
0
        public async Task MeasureJobOutcomes_WithinTimeWindow_OnlyReturnsFinishedJobsWithinTheTimeWindow()
        {
            // Arrange
            DateTimeOffset startWindow = BogusGenerator.Date.RecentOffset();
            DateTimeOffset endWindow   = BogusGenerator.Date.SoonOffset();
            string         metricName  = BogusGenerator.Random.Word();

            IEnumerable <Run> includedRuns = CreateRandomRuns(startWindow, endWindow);
            IEnumerable <Run> tooLateRuns  = CreateRandomRuns(endWindow, BogusGenerator.Date.FutureOffset());
            IEnumerable <Run> allRuns      = includedRuns.Concat(tooLateRuns);
            IEnumerable <Job> jobs         = allRuns.Select(r => new Job
            {
                JobId    = r.JobId,
                Settings = new JobSettings {
                    Name = Guid.NewGuid().ToString()
                }
            }).ToArray();

            DatabricksClient client = DatabricksClientFactory.Create(allRuns, jobs);
            var spyLogger           = new InMemoryLogger <DatabricksJobMetricsJob>();
            var provider            = new DatabricksInfoProvider(client, spyLogger);

            // Act
            await provider.MeasureJobOutcomesAsync(metricName, startWindow, endWindow);

            // Assert
            Assert.All(includedRuns, run =>
            {
                Assert.Contains(spyLogger.Messages, msg => msg.Contains(run.RunId.ToString()));
                Assert.Contains(spyLogger.Messages, msg => msg.Contains(run.JobId.ToString()));
                Job job = Assert.Single(jobs, j => j.JobId == run.JobId);
                Assert.NotNull(job);
                Assert.Contains(spyLogger.Messages, msg => msg.Contains(job.Settings.Name));
            });
            Assert.All(tooLateRuns, run =>
            {
                Assert.DoesNotContain(spyLogger.Messages, msg => msg.Contains(run.RunId.ToString()));
                Assert.DoesNotContain(spyLogger.Messages, msg => msg.Contains(run.JobId.ToString()));
                Job job = Assert.Single(jobs, j => j.JobId == run.JobId);
                Assert.NotNull(job);
                Assert.DoesNotContain(spyLogger.Messages, msg => msg.Contains(job.Settings.Name));
            });
        }
Beispiel #6
0
        public async Task GetFinishedJobRuns_WithinTimeWindow_OnlyReturnsFinishedJobsWithinTheTimeWindow()
        {
            // Arrange
            DateTimeOffset startWindow = BogusGenerator.Date.RecentOffset();
            DateTimeOffset endWindow   = BogusGenerator.Date.SoonOffset();

            IEnumerable <Run> includedRuns = CreateRandomRuns(startWindow, endWindow);
            IEnumerable <Run> tooLateRuns  = CreateRandomRuns(endWindow, BogusGenerator.Date.FutureOffset());
            IEnumerable <Run> allRuns      = includedRuns.Concat(tooLateRuns);
            IEnumerable <Job> jobs         = includedRuns.Select(r => new Job
            {
                JobId    = r.JobId,
                Settings = new JobSettings {
                    Name = Guid.NewGuid().ToString()
                }
            }).ToArray();

            DatabricksClient client = DatabricksClientFactory.Create(allRuns, jobs);
            var provider            = new DatabricksInfoProvider(client, NullLogger.Instance);

            // Act
            IEnumerable <JobRun> finishedJobs = await provider.GetFinishedJobRunsAsync(startWindow, endWindow);

            // Assert
            Assert.NotNull(finishedJobs);
            Assert.NotEmpty(finishedJobs);
            Assert.Equal(finishedJobs.Count(), includedRuns.Count());
            Assert.All(finishedJobs, job =>
            {
                Assert.Contains(includedRuns, run => run.RunId == job.Run.RunId);
                Assert.DoesNotContain(tooLateRuns, run => run.RunId == job.Run.RunId);
                Job expectedJob = Assert.Single(jobs, j => j.Settings.Name == job.JobName);
                Assert.NotNull(expectedJob);
                Assert.Equal(expectedJob.JobId, job.Run.JobId);
            });
        }
        /// <summary>
        /// Creates an <see cref="DatabricksClient"/> instance using the predefined values.
        /// </summary>
        /// <param name="secretProvider">The provider to retrieve the token during the creation of the instance.</param>
        public override Task <DatabricksClient> CreateDatabricksClientAsync(ISecretProvider secretProvider)
        {
            DatabricksClient client = DatabricksClientFactory.Create(_runs, _jobs);

            return(Task.FromResult(client));
        }