Exemple #1
0
        public void PublishPeriodic_should_run_jobs_periodically_until_end()
        {
            var endAtUtc = DateTime.UtcNow.AddSeconds(4.5);

            DummyJob.PublishPeriodic("test_periodic", 1, null, endAtUtc);
            DummyJob.PublishPeriodic("test_periodic", 1, null, endAtUtc);
            DummyJob.PublishPeriodic("test_periodic", 1, null, endAtUtc);

            Thread.Sleep(6000);

            Assert.AreEqual(4, _performCount);
        }
        public void New_FunqJobActivator_Given_Container_Should_Resolve_Job()
        {
            var dummyJob = new DummyJob();

            var container = new Container();
            container.Register<DummyJob>(dummyJob);

            var activator = new FunqJobActivator(container);

            var returnedJob = activator.ActivateJob(typeof(DummyJob));

            Assert.AreEqual(dummyJob, returnedJob);
        }
        public void QuandoForRecebidaUmaNotificacaoInformandoQueUmaSolicitacaoDeTrabalhoDoTipoComIdentificadorFoiExecutadaComFalhaEDeveSerRepetida(string p0, string p1)
        {
            using (var publishingBus = PublishingBusBuilder.Build())
            {
                var job = new DummyJob
                {
                    MessageId = MessageId.New(),
                    ExpectedExecutionStatus = JobStatus.Failed,
                    FailureAction = JobFailureAction.Repeat
                };
                publishingBus.Publish(JobStatus.Pending.TopicId(), job);
            }

            Thread.Sleep(5000);
        }
        public void QuandoForRecebidaUmaNotificacaoInformandoQueUmaSolicitacaoDeTrabalhoDoTipoComIdentificadorFoiExecutadaComSucesso(string p0, string p1)
        {
            using (var publishingBus = PublishingBusBuilder.Build())
            {
                var job = new DummyJob
                {
                    MessageId = MessageId.New(),
                    WorkDurationInMilliseconds = 0,
                    ExpectedExecutionStatus = JobStatus.Succeeded
                };
                publishingBus.Publish(JobStatus.Pending.TopicId(), job);
            }

            Thread.Sleep(5000);
        }
Exemple #5
0
        public void CronJob_should_run_jobs_periodically_until_end()
        {
            while (DateTime.UtcNow.Second % 2 != 0)
            {
                Thread.Sleep(100);
            }

            var endAtUtc = DateTime.UtcNow.AddSeconds(4.1);

            DummyJob.PublishPeriodic("test_periodic", "0/2 * * ? * *", null, null, endAtUtc);

            // these should be ignored
            DummyJob.PublishPeriodic("test_periodic", 1, null, endAtUtc);
            DummyJob.PublishPeriodic("test_periodic", 1, null, endAtUtc);

            Thread.Sleep(6000);

            Assert.AreEqual(2, _performCount);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldExecuteAllTheJobsWhenSeparateJobFails() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldExecuteAllTheJobsWhenSeparateJobFails()
        {
            IList <DummyJob> allRuns = new List <DummyJob>();

            DummyJob         firstJob     = new DummyJob(this, "first", allRuns);
            DummyJob         thirdJob     = new DummyJob(this, "third", allRuns);
            DummyJob         fourthJob    = new DummyJob(this, "fourth", allRuns);
            IList <DummyJob> expectedJobs = Arrays.asList(firstJob, thirdJob, fourthJob);

            _collector.init();

            _collector.add(firstJob);
            _collector.add(new EvilJob(this));
            _collector.add(thirdJob);
            _collector.add(fourthJob);

            _collector.start();
            _collector.shutdown();

            AssertSame(expectedJobs, allRuns);
        }
        /// <summary>
        /// Main task thread for working with a single APSIMRunner.exe process using
        /// an anonymous pipe.
        /// </summary>
        private void PipeServerTaskThread()
        {
            // Create 2 anonymous pipes (read and write) for duplex communications
            // (each pipe is one-way)
            using (var pipeRead = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
                using (var pipeWrite = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
                {
                    var pipeHandles = pipeRead.GetClientHandleAsString() + " " + pipeWrite.GetClientHandleAsString();

                    // Run a APSIMRunner process passing the pipe read and write handles as arguments.
                    var runnerProcess = new ProcessUtilities.ProcessWithRedirectedOutput();
                    runnerProcess.Exited += OnExited;
                    var runnerExecutable = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "APSIMRunner.exe");
                    runnerProcess.Start(executable: runnerExecutable,
                                        arguments: pipeHandles,
                                        workingDirectory: Directory.GetCurrentDirectory(),
                                        redirectOutput: true,
                                        cancelToken: cancelToken.Token,
                                        writeToConsole: false);

                    // Release the local handles that were created with the above GetClientHandleAsString calls
                    pipeRead.DisposeLocalCopyOfClientHandle();
                    pipeWrite.DisposeLocalCopyOfClientHandle();

                    try
                    {
                        // Get the next job to run.
                        var job = GetJobToRun();

                        while (job != null)
                        {
                            var startTime = DateTime.Now;

                            DummyJob dummy = new DummyJob(job.RunnableJob);
                            if (!(job.RunnableJob is JobRunnerSleepJob))
                            {
                                lock (runningLock)
                                    SimsRunning.Add(dummy);
                            }

                            // Send the job to APSIMRunner.exe - this will run the simulation.
                            PipeUtilities.SendObjectToPipe(pipeWrite, job.JobSentToClient);

                            pipeWrite.WaitForPipeDrain();

                            // Get the output data back from APSIMRunner.exe
                            object response = PipeUtilities.GetObjectFromPipe(pipeRead);
                            while (!(response is JobOutput))
                            {
                                if (response == null)
                                {
                                    throw new Exception("Invalid response from APSIMRunner pipe: response was null");
                                }

                                if (response is ProgressReport progressResponse)
                                {
                                    dummy.Progress = progressResponse.Progress;
                                }

                                response = PipeUtilities.GetObjectFromPipe(pipeRead);
                            }

                            var endJob = response as JobOutput;

                            // Send the output data to storage.
                            endJob?.WriteOutput(job.DataStore);

                            if (!(job.RunnableJob is JobRunnerSleepJob))
                            {
                                lock (runningLock)
                                {
                                    NumJobsCompleted++;
                                    SimsRunning.Remove(dummy);
                                }
                            }

                            // Signal end of job.
                            InvokeJobCompleted(job.RunnableJob,
                                               job.JobManager,
                                               startTime,
                                               endJob?.ErrorMessage);

                            // Get the next job to run.
                            job = GetJobToRun();
                        }
                    }
                    catch (Exception err)
                    {
                        AddException(err);
                    }
                }
        }