public void ConfirmLogs_With2CacheProgress_Throws()
        {
            var lmd1 = new LoadMetadata(CatalogueRepository, "MyLmd");
            var cata = new Catalogue(CatalogueRepository, "myCata");

            cata.LoadMetadata_ID = lmd1.ID;
            cata.LoggingDataTask = "B";
            cata.SaveToDatabase();

            var lmd2  = new LoadMetadata(CatalogueRepository, "MyLmd");
            var cata2 = new Catalogue(CatalogueRepository, "myCata");

            cata2.LoadMetadata_ID = lmd2.ID;
            cata2.LoggingDataTask = "A";
            cata2.SaveToDatabase();

            var lp1 = new LoadProgress(CatalogueRepository, lmd1);
            var lp2 = new LoadProgress(CatalogueRepository, lmd2);

            var cp1 = new CacheProgress(CatalogueRepository, lp1);
            var cp2 = new CacheProgress(CatalogueRepository, lp2);

            cp2.Name = "MyCoolCache";
            cp2.SaveToDatabase();

            var lm = new LogManager(cp1.GetDistinctLoggingDatabase());

            lm.CreateNewLoggingTaskIfNotExists(cp1.GetDistinctLoggingTask());

            // create a log entry for cp1 only
            var logEntry = lm.CreateDataLoadInfo(cp1.GetDistinctLoggingTask(), "pack o' cards", cp1.GetLoggingRunName(), null, true);

            // we mark it as completed successfully - this is a good, happy log entry
            logEntry.CloseAndMarkComplete();

            // The first cache has logged success so should be happy
            var cmd1 = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), cp1, null);

            Assert.DoesNotThrow(() => cmd1.Execute());

            // The second cache has not logged any successes so should be unhappy
            var cmd2 = new ExecuteCommandConfirmLogs(new ThrowImmediatelyActivator(RepositoryLocator), cp2, null);
            var ex   = Assert.Throws <LogsNotConfirmedException>(() => cmd2.Execute());

            Assert.AreEqual("There are no log entries for MyCoolCache", ex.Message);
        }
Пример #2
0
        public int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener, ICheckNotifier checkNotifier, GracefulCancellationToken token)
        {
            CacheProgress cp           = repositoryLocator.CatalogueRepository.GetObjectByID <CacheProgress>(_options.CacheProgress);
            string        dataLoadTask = cp.GetDistinctLoggingTask();

            var defaults      = repositoryLocator.CatalogueRepository.GetServerDefaults();
            var loggingServer = defaults.GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID);

            if (loggingServer == null)
            {
                throw new NotSupportedException("No default logging server specified, you must specify one in ");
            }

            var logManager = new LogManager(loggingServer);

            logManager.CreateNewLoggingTaskIfNotExists(dataLoadTask);

            switch (_options.Command)
            {
            case CommandLineActivity.run:

                //Setup dual listeners for the Cache process, one ticks the lifeline one very message and one logs to the logging db
                var toLog        = new ToLoggingDatabaseDataLoadEventListener(this, logManager, dataLoadTask, cp.GetLoggingRunName());
                var forkListener = new ForkDataLoadEventListener(toLog, listener);
                try
                {
                    var cachingHost = new CachingHost(repositoryLocator.CatalogueRepository);
                    cachingHost.RetryMode     = _options.RetryMode;
                    cachingHost.CacheProgress = cp;      //run the cp

                    //By default caching host will block
                    cachingHost.TerminateIfOutsidePermissionWindow = true;

                    cachingHost.Start(forkListener, token);
                }
                finally
                {
                    //finish everything
                    toLog.FinalizeTableLoadInfos();
                }

                break;

            case CommandLineActivity.check:
                var checkable = new CachingPreExecutionChecker(cp);
                checkable.Check(checkNotifier);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(0);
        }