Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
        public void JobStepSourceBuilder_GetInlineJobQueue_TypeShouldBeCorrect()
        {
            Nebula.RegisterJobProcessor(typeof(FirstJobProcessor), typeof(FirstJobStep));
            var queue = Nebula.JobStepSourceBuilder.BuildInlineJobQueue <FirstJobStep>(_jobId);

            Assert.IsNotNull(queue);
            Assert.AreEqual(typeof(InlineJobQueue <FirstJobStep>), queue.GetType());
        }
Exemplo n.º 6
0
        public void JobProcessor_Instance_Registration_ShouldReturnSameInstances()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            Nebula.RegisterJobProcessor(typeof(TransientProcessor1), typeof(FirstJobStep));

            var jobProcessor1 = Nebula.ComponentContext.GetComponent <IJobProcessor <FirstJobStep> >();
            var jobProcessor2 = Nebula.ComponentContext.GetComponent <IJobProcessor <FirstJobStep> >();

            Assert.AreEqual(jobProcessor2, jobProcessor1);
        }
Exemplo n.º 7
0
        public void JobProcessor_InstanceProvider_ReturnsInterface_ShouldReturnDifferentInstances()
        {
            Nebula.RegisterJobQueue(typeof(InMemoryJobQueue <FirstJobStep>), QueueType.InMemory);

            Nebula.RegisterJobProcessor(() => _sp.GetService <IJobProcessor <FirstJobStep> >(),
                                        typeof(FirstJobStep));

            var jobProcessor1 = Nebula.ComponentContext.GetComponent <IJobProcessor <FirstJobStep> >();
            var jobProcessor2 = Nebula.ComponentContext.GetComponent <IJobProcessor <FirstJobStep> >();

            Assert.AreNotEqual(jobProcessor2, jobProcessor1);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }