Example #1
0
        public void Test_MoveToAchiveAndDeleteByDate()
        {
            ArchiveProcessorConfig config = TestInternals.LoadConfiguration("TestConfiguration0.json");

            TestInternals.CreateClearTestInputOutput(config);
            config.AutoTimerIntervalEnabled = false;
            FilesArchiveProcessor farp = new FilesArchiveProcessor(config);

            var markerTime = DateTime.UtcNow;
            var time       = markerTime;

            TestInternals.FillTestFiles(config, "archive-able_0{0}.xml", 2, time);
            TestInternals.FillTestFiles(config, "ignored-able_0{0}.xml", 2, time);
            time = time - TimeSpan.FromHours(12);
            TestInternals.FillTestFiles(config, "archive-able_1{0}.xml", 2, time);
            TestInternals.FillTestFiles(config, "ignored-able_1{0}.xml", 2, time);

            time = markerTime - TimeSpan.FromDays(config.ArchiveRules[0].MoveToArchiveOlderThanDays);
            TestInternals.FillTestFiles(config, "archive-able_2{0}.xml", 2, time);
            TestInternals.FillTestFiles(config, "ignored-able_2{0}.xml", 2, time);
            time = time - TimeSpan.FromDays(1);
            TestInternals.FillTestFiles(config, "archive-able_3{0}.xml", 2, time);
            TestInternals.FillTestFiles(config, "ignored-able_3{0}.xml", 2, time);


            time = markerTime - TimeSpan.FromDays(config.ArchiveRules[0].DeleteFromArchiveOlderThanDays);
            TestInternals.FillTestFiles(config, "archive-able_4{0}.xml", 2, time);
            TestInternals.FillTestFiles(config, "ignored-able_4{0}.xml", 2, time);
            time = time - TimeSpan.FromDays(1);
            TestInternals.FillTestFiles(config, "archive-able_5{0}.xml", 2, time);
            TestInternals.FillTestFiles(config, "ignored-able_5{0}.xml", 2, time);

            var task = farp.LaunchArchiveFilesAsync();
            var res  = task.Wait(TimeSpan.FromSeconds(10));

            Assert.IsTrue(res);
            TestInternals.VerifySourceOlderByDate(config, markerTime);
            TestInternals.VerifyArchiveOlderByDate(config, markerTime);

            task = farp.LaunchDeleteFromArchiveFilesAsync();
            res  = task.Wait(TimeSpan.FromSeconds(10));
            Assert.IsTrue(res);

            TestInternals.VerifySourceDeletedOlderByDate(config, markerTime);
        }
Example #2
0
        public void Test_MoveToAchiveAndDeleteByDateAndNumberAutoOneMinManual()
        {
            ArchiveProcessorConfig config = TestInternals.LoadConfiguration("TestConfiguration0.json");

            TestInternals.CreateClearTestInputOutput(config);
            config.AutoTimerIntervalEnabled       = true;
            config.DelayArchiveInSecondsOnstartUp = 1;
            config.AutoTimerArchiveIntervalMin    = 1000;

            var markerTime = DateTime.UtcNow;
            var time       = markerTime;

            TestInternals.FillTestFiles(config, "archive-able_0{0}.xml", 2, time);
            time = time - TimeSpan.FromHours(12);
            TestInternals.FillTestFiles(config, "archive-able_1{0}.xml", config.ArchiveRules[0].MoveToArchiveAfterReachingFiles, time);

            time = markerTime - TimeSpan.FromDays(config.ArchiveRules[0].MoveToArchiveOlderThanDays);
            TestInternals.FillTestFiles(config, "archive-able_2{0}.xml", config.ArchiveRules[0].DeleteFromArchiveAfterReachingFiles, time);

            time = time - TimeSpan.FromDays(1);
            TestInternals.FillTestFiles(config, "archive-able_3{0}.xml", 2, time);


            time = markerTime - TimeSpan.FromDays(config.ArchiveRules[0].DeleteFromArchiveOlderThanDays);
            TestInternals.FillTestFiles(config, "archive-able_4{0}.xml", 2, time);
            time = time - TimeSpan.FromDays(1);
            TestInternals.FillTestFiles(config, "archive-able_5{0}.xml", 2, time);

            FilesArchiveProcessor farp = new FilesArchiveProcessor(config, false);
            var task = farp.StartAsync();
            var res  = task.Wait(TimeSpan.FromSeconds(10));

            Assert.IsTrue(res);

            Thread.Sleep(TimeSpan.FromSeconds(66));
            TestInternals.VerifySourceOlderByDate(config, markerTime);
            TestInternals.VerifySourceByNumber(config);
            TestInternals.VerifyArchiveByNumber(config);
            TestInternals.VerifySourceDeletedOlderByDate(config, markerTime);

            task = farp.StopAsync();
            res  = task.Wait(TimeSpan.FromSeconds(10));
            Assert.IsTrue(res);
        }
        public void Test_HostingOfLogFilesMonitorArchiver()
        {
            string            name              = "TestConfiguration0.json";
            IConfiguration    configuration     = GetConfiguration(name);
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IConfiguration>(configuration);

            serviceCollection.AddLogFilesMonitorArchiver();

            IServiceProvider Services = serviceCollection.BuildServiceProvider();

            var _hostedServices = Services.GetService <IEnumerable <IHostedService> >();

            // Setup proper test configuration
            ArchiveProcessorConfig config = ((FilesArchiveProcessor)_hostedServices.First()).Configuration;

            config.AutoTimerIntervalEnabled       = true;
            config.DelayArchiveInSecondsOnstartUp = 1;
            config.AutoTimerArchiveIntervalMin    = 1000;

            var path = TestInternals.GetBasePath();

            foreach (var rule in config.ArchiveRules)
            {
                rule.SourcePath  = Path.Combine(path, rule.SourcePath);
                rule.ArchivePath = Path.Combine(path, rule.ArchivePath);
            }

            config.AutoTimerIntervalEnabled       = true;
            config.DelayArchiveInSecondsOnstartUp = 1;
            config.AutoTimerArchiveIntervalMin    = 1000;

            var markerTime = DateTime.UtcNow;
            var time       = markerTime;

            TestInternals.FillTestFiles(config, "archive-able_0{0}.xml", 2, time);
            time = time - TimeSpan.FromHours(12);
            TestInternals.FillTestFiles(config, "archive-able_1{0}.xml", config.ArchiveRules[0].MoveToArchiveAfterReachingFiles, time);

            time = markerTime - TimeSpan.FromDays(config.ArchiveRules[0].MoveToArchiveOlderThanDays);
            TestInternals.FillTestFiles(config, "archive-able_2{0}.xml", config.ArchiveRules[0].DeleteFromArchiveAfterReachingFiles, time);

            time = time - TimeSpan.FromDays(1);
            TestInternals.FillTestFiles(config, "archive-able_3{0}.xml", 2, time);


            time = markerTime - TimeSpan.FromDays(config.ArchiveRules[0].DeleteFromArchiveOlderThanDays);
            TestInternals.FillTestFiles(config, "archive-able_4{0}.xml", 2, time);
            time = time - TimeSpan.FromDays(1);
            TestInternals.FillTestFiles(config, "archive-able_5{0}.xml", 2, time);

            // Start service via host services interface

            foreach (var hostedService in _hostedServices)
            {
                // Fire IHostedService.Start
                hostedService.StartAsync(CancellationToken.None).ConfigureAwait(false);
            }

            Thread.Sleep(TimeSpan.FromSeconds(66));
            TestInternals.VerifySourceOlderByDate(config, markerTime);
            TestInternals.VerifySourceByNumber(config);
            TestInternals.VerifyArchiveByNumber(config);
            TestInternals.VerifySourceDeletedOlderByDate(config, markerTime);
        }