예제 #1
0
        public void LoadProgress_JobFactory_NoDates()
        {
            var lp = WhenIHaveA <LoadProgress>();



            lp.OriginDate = new DateTime(2001, 1, 1);

            // We are fully up-to-date
            lp.DataLoadProgress = DateTime.Now;

            lp.Check(new ThrowImmediatelyCheckNotifier());

            var stratFactory = new JobDateGenerationStrategyFactory(new AnyAvailableLoadProgressSelectionStrategy(lp.LoadMetadata));
            var strat        = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener());

            var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.WorkDirectory), "LoadProgress_JobFactory_NoDates", true);

            var lmd = lp.LoadMetadata;

            lmd.LocationOfFlatFiles = dir.RootPath.FullName;

            foreach (var cata in lmd.GetAllCatalogues())
            {
                cata.LoggingDataTask = "ff";
                cata.SaveToDatabase();
            }


            lmd.SaveToDatabase();


            var jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null);
            var ex         = Assert.Throws <Exception>(() => jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null));

            Assert.AreEqual("DatesToRetrieve was empty for load 'MyLoad'.  Possibly the load is already up to date?", ex.Message);

            // We have 1 day to load (date is the last fully loaded date)
            lp.DataLoadProgress = DateTime.Now.AddDays(-2);
            lp.SaveToDatabase();

            strat      = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener());
            jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null);

            var job = jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null);

            Assert.AreEqual(1, ((ScheduledDataLoadJob)job).DatesToRetrieve.Count);
        }
        public override ExitCodeType Run(GracefulCancellationToken loadCancellationToken, object payload = null)
        {
            // single job, so grab the first available LoadProgress and lock it
            var loadProgresses = LoadProgressSelectionStrategy.GetAllLoadProgresses();

            if (!loadProgresses.Any())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            var loadProgress = loadProgresses.First();

            // we don't need any other schedules the strategy may have given us
            loadProgresses.Remove(loadProgress);

            // Create the job factory
            if (_scheduledJobFactory != null)
            {
                throw new Exception("Job factory should only be created once");
            }

            _scheduledJobFactory = new SingleScheduledJobFactory(loadProgress, JobDateGenerationStrategyFactory.Create(loadProgress, DataLoadEventListener), OverrideNumberOfDaysToLoad ?? loadProgress.DefaultNumberOfDaysToLoadEachTime, LoadMetadata, LogManager);

            // If the job factory won't produce any jobs we can bail out here
            if (!_scheduledJobFactory.HasJobs())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            // Run the data load
            JobProvider = _scheduledJobFactory;

            return(base.Run(loadCancellationToken, payload));
        }
        public void DateKnown_NoCache_SuggestSingleScheduleConsecutiveDateStrategy()
        {
            var lp = Mock.Of <ILoadProgress>(p => p.DataLoadProgress == new DateTime(2001, 01, 01));

            var factory = new JobDateGenerationStrategyFactory(new SingleLoadProgressSelectionStrategy(lp));

            Assert.AreEqual(typeof(SingleScheduleConsecutiveDateStrategy), factory.Create(lp, new ThrowImmediatelyDataLoadEventListener()).GetType());
        }
        public void NoDates()
        {
            var lp = Mock.Of <ILoadProgress>();

            var factory = new JobDateGenerationStrategyFactory(new SingleLoadProgressSelectionStrategy(lp));

            var ex = Assert.Throws <LoadOrCacheProgressUnclearException>(() => factory.Create(lp, new ThrowImmediatelyDataLoadEventListener()));

            Assert.AreEqual("Don't know when to start the data load, both DataLoadProgress and OriginDate are null", ex.Message);
        }
예제 #5
0
        public override ExitCodeType Run(GracefulCancellationToken loadCancellationToken, object payload = null)
        {
            // grab all the load schedules we can and lock them
            var loadProgresses = LoadProgressSelectionStrategy.GetAllLoadProgresses();

            if (!loadProgresses.Any())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            // create job factory
            var progresses  = loadProgresses.ToDictionary(loadProgress => loadProgress, loadProgress => JobDateGenerationStrategyFactory.Create(loadProgress, DataLoadEventListener));
            var jobProvider = new MultipleScheduleJobFactory(progresses, OverrideNumberOfDaysToLoad, LoadMetadata, LogManager);

            // check if the factory will produce any jobs, if not we can stop here
            if (!jobProvider.HasJobs())
            {
                return(ExitCodeType.OperationNotRequired);
            }

            // Run the data load process
            JobProvider = jobProvider;

            //Do a data load
            ExitCodeType result;

            while ((result = base.Run(loadCancellationToken, payload)) == ExitCodeType.Success) //stop if it said not required
            {
                //or if between executions the token is set
                if (loadCancellationToken.IsAbortRequested)
                {
                    return(ExitCodeType.Abort);
                }

                if (loadCancellationToken.IsCancellationRequested)
                {
                    return(ExitCodeType.Success);
                }
            }

            //should be Operation Not Required or Error since the token inside handles stopping
            return(result);
        }
        public void CacheProvider_None()
        {
            var ex = Assert.Throws <CacheDataProviderFindingException>(() => _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener()));

            Assert.IsTrue(ex.Message.StartsWith("LoadMetadata JobDateGenerationStrategyFactoryTestsIntegration does not have ANY process tasks of type ProcessTaskType.DataProvider"));
        }