Пример #1
0
        public async Task QueueType_CreateCustome_Success()
        {
            //create sample job with custom queue
            Nebula.RegisterJobQueue(typeof(FirstJobQueue <>), QueueTypes.FirstJobQueue);

            var jobManager = Nebula.GetJobManager();
            var jobStore   = Nebula.ComponentContext.GetComponent <IJobStore>();

            var jobId = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(
                string.Empty, "sample-job", nameof(FirstJobStep), new JobConfigurationData
            {
                MaxBatchSize = 100,
                MaxConcurrentBatchesPerWorker = 5,
                IsIndefinite = true,
                MaxBlockedSecondsPerCycle = 300,
                QueueTypeName             = QueueTypes.FirstJobQueue
            });

            var jobData = await jobStore.LoadFromAnyTenant(jobId);

            var jobQueue =
                Nebula.JobStepSourceBuilder.BuildJobStepSource <FirstJobStep>(jobData.Configuration.QueueTypeName);

            Assert.AreEqual(typeof(FirstJobQueue <FirstJobStep>), jobQueue.GetType());
        }
Пример #2
0
        public async Task StopJob_StopStartedJob_ShouldPurgeQueue()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                QueueTypeName = QueueType.InMemory
            });

            var queue = Nebula.JobStepSourceBuilder.BuildInMemoryJobQueue <FirstJobStep>(jobId);

            await jobManager.StartJob(Tenant.Id, jobId);

            await queue.Enqueue(new FirstJobStep { Number = 1 });

            var initialQueueLength = await queue.GetQueueLength();

            await jobManager.StopJob(Tenant.Id, jobId);

            var afterStopQueueLength = await queue.GetQueueLength();

            Assert.AreEqual(1, initialQueueLength);
            Assert.AreEqual(0, afterStopQueueLength);
        }
Пример #3
0
        public async Task StopJob_StopStartedJob_CheckJobState()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                QueueTypeName = QueueType.InMemory
            });

            var queue = Nebula.JobStepSourceBuilder.BuildInMemoryJobQueue <FirstJobStep>(jobId);
            await queue.Enqueue(new FirstJobStep { Number = 1 });

            await jobManager.StartJob(Tenant.Id, jobId);

            await jobManager.StopJob(Tenant.Id, jobId);

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var job      = await jobStore.Load(Tenant.Id, jobId);

            Assert.IsNotNull(job);
            Assert.AreEqual(JobState.Stopped, job.Status.State);
        }
Пример #4
0
        public async Task StopJob_NotDefinedJob_InvalidJobIdErrorKey()
        {
            var result = await Nebula.GetJobManager().StopJob(Tenant.Id, "jobId");

            Assert.IsFalse(result.Success);
            Assert.AreEqual(ErrorKeys.InvalidJobId, result.Errors.FirstOrDefault()?.ErrorKey);
        }
Пример #5
0
        public async Task StopJob_InCompletePreprocessor_JobActionHasPreprocessorDependencyErrorKey()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager        = Nebula.GetJobManager();
            var preprocessorJobId = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                                   configuration : new JobConfigurationData
            {
                QueueTypeName = QueueType.InMemory
            });

            var jobId = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                       configuration : new JobConfigurationData
            {
                QueueTypeName = QueueType.InMemory
            });

            await jobManager.AddPredecessor(Tenant.Id, jobId, preprocessorJobId);

            var result = await jobManager.StopJob(Tenant.Id, jobId);

            Assert.IsFalse(result.Success);
            Assert.AreEqual(ErrorKeys.JobActionHasPreprocessorDependency, result.Errors.FirstOrDefault()?.ErrorKey);
        }
Пример #6
0
        public async Task PurgeQueue_CustomeJobQueueDefinedInJob_shouldBeEmpty()
        {
            //create sample job with custom queue
            var jobManager = Nebula.GetJobManager();
            var jobStore   = Nebula.ComponentContext.GetComponent <IJobStore>();

            Nebula.RegisterJobQueue(typeof(FirstJobQueue <FirstJobStep>), QueueTypes.FirstJobQueue);

            var jobId = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(
                string.Empty, "sample-job", nameof(FirstJobStep), new JobConfigurationData
            {
                MaxBatchSize = 100,
                MaxConcurrentBatchesPerWorker = 5,
                IsIndefinite = true,
                MaxBlockedSecondsPerCycle = 300,
                QueueTypeName             = QueueTypes.FirstJobQueue
            });

            var jobData = await jobStore.LoadFromAnyTenant(jobId);

            var jobQueue =
                Nebula.JobStepSourceBuilder.BuildJobStepSource <FirstJobStep>(jobData.Configuration.QueueTypeName,
                                                                              jobData.JobId) as IJobQueue <FirstJobStep>;

            await jobQueue.Enqueue(new FirstJobStep());

            await jobQueue.Purge();

            var queueLeghnt = await jobQueue.GetQueueLength();

            Assert.AreEqual(0, queueLeghnt);
        }
Пример #7
0
        public async Task StartJob_EnqueueOneItem_QueueShouldBeEmpty()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData {
                QueueTypeName = QueueType.InMemory
            });

            var queue = Nebula.JobStepSourceBuilder.BuildInMemoryJobQueue <FirstJobStep>(jobId);
            await queue.Enqueue(new FirstJobStep { Number = 1 });

            var initialLength = await queue.GetQueueLength();

            await jobManager.StartJob(Tenant.Id, jobId);


            var processedLength = await queue.GetQueueLength();

            var jobRunnerManager = Nebula.ComponentContext.GetComponent <IJobRunnerManager>();

            Assert.IsTrue(jobRunnerManager.IsJobRunnerStarted(jobId));
            Assert.AreEqual(1, initialLength);
            Assert.AreEqual(0, processedLength);
        }
Пример #8
0
        public async Task StopJob_StoppedJob_Success()
        {
            await AddJobToDb(JobState.Stopped);

            var result = await Nebula.GetJobManager().StopJob(Tenant.Id, _jobId);

            Assert.IsTrue(result.Success);
        }
Пример #9
0
        public async Task StopJob_ExpiredJob_InvalidJobStateErrorKey()
        {
            await AddJobToDb(JobState.Expired);

            var result = await Nebula.GetJobManager().StopJob(Tenant.Id, _jobId);

            Assert.IsFalse(result.Success);
            Assert.AreEqual(ErrorKeys.InvalidJobState, result.Errors.FirstOrDefault()?.ErrorKey);
        }
        public async Task CreateJob_ZeroThrottledMaxBurstSize_ExceptionThrown()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                           configuration : new JobConfigurationData
            {
                ThrottledMaxBurstSize = JobConfigurationDefaultValues.MinThrottledMaxBurstSize,
                QueueTypeName         = QueueType.InMemory
            });
        }
        public async Task CreateJob_jobWithoutJobId_ShouldHaveValue()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData {
                QueueTypeName = QueueType.InMemory
            });

            Assert.IsTrue(!jobId.IsNullOrWhitespace());
        }
        public async Task CreateJob_ExpiredJob_ExceptionThrown()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                           configuration : new JobConfigurationData
            {
                ExpiresAt     = DateTime.Now.AddDays(-1),
                QueueTypeName = QueueType.InMemory
            });
        }
Пример #13
0
        public async Task QueueType_notDefined_ExceptionThrown()
        {
            var jobManager = Nebula.GetJobManager();

            await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(
                string.Empty, "sample-job", nameof(FirstJobStep), new JobConfigurationData
            {
                MaxBatchSize = 100,
                MaxConcurrentBatchesPerWorker = 5,
                IsIndefinite = true,
                MaxBlockedSecondsPerCycle = 300
            });
        }
        public async Task CreateJob_NewJob_QueueExistenceCheck()
        {
            Nebula.RegisterJobQueue(typeof(FirstJobQueue <FirstJobStep>), QueueTypes.FirstJobQueue);

            var jobManager = Nebula.GetJobManager();
            await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                           configuration : new JobConfigurationData {
                QueueTypeName = QueueTypes.FirstJobQueue
            });

            var queue = Nebula.JobStepSourceBuilder.BuildJobStepSource <FirstJobStep>(QueueTypes.FirstJobQueue) as FirstJobQueue <FirstJobStep>;

            Assert.IsNotNull(queue);
            Assert.IsTrue(queue.QueueExistenceChecked);
        }
Пример #15
0
        public async Task StartJob_InvalidJobState_ExceptionThrown()
        {
            var jobId    = "jobId";
            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            await jobStore.AddOrUpdateDefinition(new JobData
            {
                TenantId = Tenant.Id,
                JobId    = jobId,
                Status   = new JobStatusData {
                    State = JobState.Failed
                }
            });

            await Nebula.GetJobManager().StartJob(Tenant.Id, jobId);
        }
        public async Task CreateJob_MaxBatchSizeRange_LessTahnMax()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                MaxBatchSize  = JobConfigurationDefaultValues.MaxBatchSize + 1,
                QueueTypeName = QueueType.InMemory
            });

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var job      = await jobStore?.Load(Tenant.Id, jobId);

            Assert.IsTrue(job.Configuration.MaxBatchSize <= JobConfigurationDefaultValues.MaxBatchSize);
        }
Пример #17
0
        public async Task StartJob_StartNewJob_ShouldCreateRunner()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData {
                QueueTypeName = QueueType.InMemory
            });

            await jobManager.StartJob(Tenant.Id, jobId);

            var jobRunnerManager = Nebula.ComponentContext.GetComponent <IJobRunnerManager>();

            Assert.IsTrue(jobRunnerManager.IsJobRunnerStarted(jobId));
        }
Пример #18
0
        public async Task StopJob_IndefiniteJob_InvalidJobActionErrorKey()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                IsIndefinite  = true,
                QueueTypeName = QueueType.InMemory
            });

            var result = await jobManager.StopJob(Tenant.Id, jobId);

            Assert.IsFalse(result.Success);
            Assert.AreEqual(ErrorKeys.InvalidJobAction, result.Errors.FirstOrDefault()?.ErrorKey);
        }
        public async Task CreateJob_IdleSecondsToCompletion_MoreThanMin()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                IdleSecondsToCompletion = JobConfigurationDefaultValues.MinIdleSecondsToCompletion - 1,
                QueueTypeName           = QueueType.InMemory
            });

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var job      = await jobStore?.Load(Tenant.Id, jobId);

            Assert.IsTrue(job.Configuration.IdleSecondsToCompletion >=
                          JobConfigurationDefaultValues.MinIdleSecondsToCompletion);
        }
        public async Task CreateJob_MinConcurrentBatchesPerWorker_MoreThanMin()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                MaxConcurrentBatchesPerWorker = JobConfigurationDefaultValues.MinConcurrentBatchesPerWorker - 1,
                QueueTypeName = QueueType.InMemory
            });

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var job      = await jobStore?.Load(Tenant.Id, jobId);

            Assert.IsTrue(job.Configuration.MaxConcurrentBatchesPerWorker >=
                          JobConfigurationDefaultValues.MinConcurrentBatchesPerWorker);
        }
        public async Task CreateJob_DefaultThrottledItemsPerSecond_MoreThanMin()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData
            {
                ThrottledItemsPerSecond = JobConfigurationDefaultValues.MinThrottledItemsPerSecond - 0.0001,
                QueueTypeName           = QueueType.InMemory
            });

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var job      = await jobStore?.Load(Tenant.Id, jobId);

            Assert.IsTrue(job.Configuration.ThrottledItemsPerSecond >=
                          JobConfigurationDefaultValues.MinThrottledItemsPerSecond);
        }
Пример #22
0
        public async Task StartJobIfNotStarted_StartJob_StateShouldBeInProgress()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));

            var jobManager = Nebula.GetJobManager();
            var jobId      = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id,
                                                                                            configuration : new JobConfigurationData {
                QueueTypeName = QueueType.InMemory
            });

            await jobManager.StartJobIfNotStarted(Tenant.Id, jobId);

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var JobData  = await jobStore.Load(Tenant.Id, jobId);

            Assert.IsNotNull(JobData);
            Assert.AreEqual(JobState.InProgress, JobData.Status.State);
        }
Пример #23
0
        public async Task QueueType_DifferentJobs_DifferentQueues()
        {
            //create sample job with custom queue
            var jobManager = Nebula.GetJobManager();
            var jobStore   = Nebula.ComponentContext.GetComponent <IJobStore>();

            Nebula.RegisterJobQueue(typeof(FirstJobQueue <>), QueueTypes.FirstJobQueue);
            Nebula.RegisterJobQueue(typeof(SecondJobQueue <>), QueueTypes.SecondJobQueue);

            var firstJob = await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(
                string.Empty, "first-job", nameof(FirstJobStep), new JobConfigurationData
            {
                MaxBatchSize = 100,
                MaxConcurrentBatchesPerWorker = 5,
                IsIndefinite = true,
                MaxBlockedSecondsPerCycle = 300,
                QueueTypeName             = QueueTypes.FirstJobQueue
            });

            var secondJob = await jobManager.CreateNewJobOrUpdateDefinition <SecondJobStep>(
                string.Empty, "second-job", nameof(SecondJobStep), new JobConfigurationData
            {
                MaxBatchSize = 100,
                MaxConcurrentBatchesPerWorker = 5,
                IsIndefinite = true,
                MaxBlockedSecondsPerCycle = 300,
                QueueTypeName             = QueueTypes.SecondJobQueue
            });

            var firstJobData = await jobStore.LoadFromAnyTenant(firstJob);

            var firstJobQueue =
                Nebula.GetJobQueue <FirstJobStep>(firstJobData.Configuration.QueueTypeName);

            var secondJobData = await jobStore.LoadFromAnyTenant(secondJob);

            var secondJobQueue =
                Nebula.GetJobQueue <SecondJobStep>(secondJobData.Configuration.QueueTypeName);

            Assert.AreEqual(typeof(FirstJobQueue <FirstJobStep>), firstJobQueue.GetType());
            Assert.AreEqual(typeof(SecondJobQueue <SecondJobStep>), secondJobQueue.GetType());
        }
        public async Task CreateJob_NewJob_ShouldExistInStore()
        {
            var jobId   = "testJobId";
            var jobName = "testJob";

            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            var jobManager = Nebula.GetJobManager();
            await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id, jobName, jobId,
                                                                           new JobConfigurationData { QueueTypeName = QueueType.InMemory });

            await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id, "secondJob", "secondJob",
                                                                           new JobConfigurationData { QueueTypeName = QueueType.InMemory });

            var jobStore = Nebula.ComponentContext.GetComponent(typeof(IJobStore)) as IJobStore;
            var job      = await jobStore?.Load(Tenant.Id, jobId);

            Assert.IsNotNull(job);
            Assert.AreEqual(jobId, job.JobId);
        }
Пример #25
0
 public async Task StartJobIfNotStarted_NotDefinedJob_ExceptionThrown()
 {
     await Nebula.GetJobManager().StartJobIfNotStarted(Tenant.Id, "jobId");
 }
 public async Task CreateJob_NullConfiguration_ExceptionThrown()
 {
     var jobManager = Nebula.GetJobManager();
     await jobManager.CreateNewJobOrUpdateDefinition <FirstJobStep>(Tenant.Id);
 }