예제 #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);
        }
예제 #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);
        }
예제 #3
0
        public void Test_NegativeExceptions()
        {
            ArchiveProcessorConfig config = TestInternals.LoadConfiguration("TestConfiguration0.json");

            TestInternals.CreateClearTestInputOutput(config);
            config.AutoTimerIntervalEnabled = false;

            FilesArchiveProcessor farp = new FilesArchiveProcessor(config, false);

            // Should throw exception until it has been started
            Assert.ThrowsException <InvalidOperationException>(() => farp.LaunchArchiveFilesAsync());
            Assert.ThrowsException <InvalidOperationException>(() => farp.LaunchDeleteFromArchiveFilesAsync());

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

            Assert.IsTrue(res);

            Assert.ThrowsException <InvalidOperationException>(() => farp.StartAsync());

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

            // Should throw exception until it has been started
            Assert.ThrowsException <InvalidOperationException>(() => farp.LaunchArchiveFilesAsync());
            Assert.ThrowsException <InvalidOperationException>(() => farp.LaunchDeleteFromArchiveFilesAsync());

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

            farp.Dispose();
            // Should throw exception until it has been started
            Assert.ThrowsException <InvalidOperationException>(() => farp.LaunchArchiveFilesAsync());
            Assert.ThrowsException <InvalidOperationException>(() => farp.LaunchDeleteFromArchiveFilesAsync());
        }