Пример #1
0
        public void IncrementTest()
        {
            var testId  = "PulseUnitTest";
            var message = "Hello World";

            HealthCounterRepository.Increment(testId, message);
            var res = HealthCounterRepository.ProbeAndPrune().ToList();

            Assert.That(res.Count, Is.EqualTo(1));
            var entry = res[0];

            Assert.That(entry.Count, Is.EqualTo(1));
            Assert.That(entry.Id, Is.EqualTo(testId));
            Assert.That(entry.Message, Is.EqualTo(message));
            Assert.That(entry.TimeStamp, Is.EqualTo(TimeProvider.GetUtcNow()));
            TimeProvider.Step(TimeSpan.FromSeconds(5));
            HealthCounterRepository.Increment(testId, message + "2");
            res = HealthCounterRepository.ProbeAndPrune().ToList();
            Assert.That(res.Count, Is.EqualTo(1));
            entry = res[0];
            Assert.That(entry.Count, Is.EqualTo(2));
            Assert.That(entry.Id, Is.EqualTo(testId));
            Assert.That(entry.Message, Is.EqualTo(message + "2"));
            Assert.That(entry.TimeStamp, Is.EqualTo(TimeProvider.GetUtcNow()));
            TimeProvider.Step(MaxAge + TimeSpan.FromSeconds(5));
            HealthCounterRepository.Increment(testId, message + "3");
            res   = HealthCounterRepository.ProbeAndPrune().ToList();
            entry = res[0];
            Assert.That(entry.Count, Is.EqualTo(1));
        }
Пример #2
0
        public void RetryPluginTest()
        {
            var oldJob = CreateRetryJob(2);
            var job    = oldJob;

            JobRepository.Add(job);
            Assert.That(JobRepository.WaitingJobs().Count(), Is.EqualTo(1));
            var maxiumJobFinishTime = TimeProvider.GetUtcNow().AddMinutes(5);

            while ((JobRepository.WaitingJobs().Any() || JobRepository.ActiveJobs().Any()) && TimeProvider.GetUtcNow() < maxiumJobFinishTime)
            {
                MockCallbackService.Verify(m => m.MakeCallback(It.IsAny <Job>()), Times.Never, "MakeCallback should not be called yet.");
                Executor.Pulse();
                TimeProvider.Step(TimeSpan.FromSeconds(5));
            }

            Assert.That(TimeProvider.GetUtcNow() < maxiumJobFinishTime, "Must finish the jobs before the time limit.");
            retryPlugin.Verify(m => m.Assign(It.IsAny <ExecutionTask>()), Times.Once);
            retryPlugin.Verify(m => m.Retry(It.IsAny <ExecutionTask>()), Times.Exactly(2));
            Assert.That(JobRepository.WaitingJobs().Count(), Is.EqualTo(0));
            Assert.That(JobRepository.ActiveJobs().Count(), Is.EqualTo(0));
            Assert.That(JobRepository.FailedJobs().Count(), Is.EqualTo(0));
            Assert.That(JobRepository.DoneJobs().Count(), Is.EqualTo(1));
            job = JobRepository.Get(job.Urn);

            Assert.That(job.Plan.Tasks.FirstOrDefault(t => t.PluginUrn == RetryPluginUrn).NumberOfRetries, Is.GreaterThan(0));
        }
 public void StepTest()
 {
     timeProvider.Step(TimeSpan.FromMinutes(1));
     Assert.That(timeProvider.GetUtcNow(), Is.EqualTo(startTime.AddMinutes(1)));
     timeProvider.Step(TimeSpan.FromMinutes(1));
     Assert.That(timeProvider.GetUtcNow(), Is.EqualTo(startTime.AddMinutes(2)));
 }
Пример #4
0
        public void OneJob()
        {
            var oldJob = CreateNewJob();
            var job    = oldJob;

            JobRepository.Add(job);
            Assert.That(JobRepository.WaitingJobs().Count(), Is.EqualTo(1));
            var maxiumJobFinishTime = TimeProvider.GetUtcNow().AddMinutes(5);

            while ((JobRepository.WaitingJobs().Any() || JobRepository.ActiveJobs().Any()) && TimeProvider.GetUtcNow() < maxiumJobFinishTime)
            {
                MockCallbackService.Verify(m => m.MakeCallback(It.IsAny <Job>()), Times.Never, "MakeCallback should not be called yet.");
                Executor.Pulse();
                TimeProvider.Step(TimeSpan.FromSeconds(5));
            }
            MockCallbackService.Verify(m => m.MakeCallback(It.IsAny <Job>()), Times.Once, "MakeCallback have not been called once.");
            Assert.That(TimeProvider.GetUtcNow() < maxiumJobFinishTime, "Most finish the jobs before the time limit.");
            Assert.That(JobRepository.WaitingJobs().Count(), Is.EqualTo(0));
            Assert.That(JobRepository.ActiveJobs().Count(), Is.EqualTo(0));
            Assert.That(JobRepository.DoneJobs().Count(), Is.EqualTo(1));
            job = JobRepository.Get(job.Urn);
            var flags = job.Plan.GetCurrentEssence().Flags;

            Assert.That((bool)(flags.HasFlag(StateFlags.HardSubtitles) && flags.HasFlag(StateFlags.Logo)));
            Assert.That(job.Destination.Files.Count, Is.EqualTo(3));
        }
Пример #5
0
        public void SemaphoreTest()
        {
            Assert.That(SemaphoreRepository.MaxAge > TimeSpan.FromSeconds(2),
                        "Can not complete the test with a SemaphoreMaxAge less than 2 sec.");
            var    callerId1 = "CommonRepoTest1";
            string currentOwner;

            Assert.That(SemaphoreRepository.Get(_semaphoreId, callerId1, out currentOwner), Is.True,
                        "Should get lock from empty repo");
            Assert.That(callerId1, Is.EqualTo(currentOwner),
                        "Current owner should be set correctly");

            // Make a time step less than SemaphoreMaxAge
            TimeProvider.Step(SemaphoreRepository.MaxAge.Add(TimeSpan.FromSeconds(-1)));

            var callerId2 = "CommonRepoTest2";

            Assert.That(SemaphoreRepository.Get(_semaphoreId, callerId2, out currentOwner), Is.False,
                        "Another caller should not get the lock before max age has expired.");
            Assert.That(callerId1, Is.EqualTo(currentOwner),
                        "Current owner should not have changed.");
            Assert.That(SemaphoreRepository.Get(_semaphoreId, callerId1, out currentOwner), Is.True,
                        "First caller should still get the lock");
            Assert.That(callerId1, Is.EqualTo(currentOwner),
                        "Current owner should not have changed.");

            // Make a time step more than SemaphoreMaxAge
            TimeProvider.Step(SemaphoreRepository.MaxAge.Add(TimeSpan.FromSeconds(1)));
            Assert.That(SemaphoreRepository.Get(_semaphoreId, callerId2, out currentOwner), Is.True,
                        "The semaphore max age has been exceded ownership change should be allowed.");
            Assert.That(callerId2, Is.EqualTo(currentOwner),
                        "The current owner is changed correctly to 2nd caller id.");
            Assert.That(SemaphoreRepository.Get(_semaphoreId, callerId1, out currentOwner), Is.False,
                        "The previous caller is denied, since the semaphore has moved to 2nd caller");
            Assert.That(callerId2, Is.EqualTo(currentOwner),
                        "Current owner should not have changed.");

            var probe = SemaphoreRepository.Probe(_semaphoreId);

            Assert.That(probe.SemaphoreId, Is.EqualTo(_semaphoreId));
            Assert.That(probe.CurrentOwnerId, Is.EqualTo(callerId2));
            Assert.That(probe.HeartBeat, Is.EqualTo(TimeProvider.GetUtcNow()));
        }
Пример #6
0
        public void UpdateModifiesLastModifiedDateTest()
        {
            var job = ActiveJob();

            JobRepository.Add(job); //Sets the initial lastmodified timestamp
            job = JobRepository.Get(job.Urn);
            var createdTime = job.LastModified;

            TimeProvider.Step(TimeSpan.FromMinutes(1));
            JobRepository.Update(job);
            var updatedJob = JobRepository.Get(job.Urn);

            Assert.That(updatedJob.LastModified, Is.EqualTo(createdTime.AddMinutes(1)));
        }