Takes periodic snapshots of a PrevalenceEngine instance and applies a clean up policy to the prevalence base folder.
Inheritance: System.IDisposable
コード例 #1
0
		private void CreateSnapshotTaker(PrevalenceEngine engine, float snapshotPeriod)
		{
			TimeSpan period = TimeSpan.FromHours(snapshotPeriod);
			ICleanUpPolicy policy = (ICleanUpPolicy) Kernel[PrevalenceFacility.CleanupPolicyComponentPropertyKey];

			SnapshotTaker taker = new SnapshotTaker(engine, period, policy);

			Kernel.AddComponentInstance(PrevalenceFacility.SnapShotTakerComponentPropertyKey, taker);
		}
コード例 #2
0
		public void TestSnapshotTaker()
		{
			// create some logs...			
			Add(30); 
			_engine.HandsOffOutputLog();
			Add(20);

			TimeSpan period = TimeSpan.FromSeconds(3);
			SnapshotTaker taker = new SnapshotTaker(_engine, period);		

			// Let's wait for a snapshot to be taken
			Thread.Sleep(TimeSpan.FromSeconds(5));
            Assert.AreEqual(1, _engine.PrevalenceBase.GetFiles("*.snapshot").Length);

			// more log files...
			Add(20);

			// a second snapshot...
			Thread.Sleep(TimeSpan.FromSeconds(2));

			// ok, we're done.
			taker.Dispose();

			// Let's make sure no more snapshots will be
			// taken...
			Thread.Sleep(period + TimeSpan.FromSeconds(1));

            Assert.AreEqual(2, _engine.PrevalenceBase.GetFiles("*.snapshot").Length);

			// sanity check
			CrashRecover();
			AssertTotal(70);			
		}
コード例 #3
0
		public void TestCleanUpOldFilesPolicy()
		{		
			// some log files...
			Add(20); // 1st log file - 0001.commandlog
			CrashRecover();
			Add(30); // 2nd log file - 0002.commandlog			
			_engine.TakeSnapshot(); // 1st snapshot - 0002.snapshot
			Thread.Sleep(TimeSpan.FromMilliseconds(2500));
			Add(10); // 3rd log file - 0003.commandlog
			
			// remove files older than 2 seconds...
			ICleanUpPolicy policy = new OldFilesCleanUpPolicy(TimeSpan.FromSeconds(2));
			SnapshotTaker taker = new SnapshotTaker(_engine, TimeSpan.FromMilliseconds(250), policy);
			Thread.Sleep(TimeSpan.FromMilliseconds(400));
			// 2nd snasphot taken - 0003.snapshot
			taker.Dispose();

			FileInfo[] files = _engine.PrevalenceBase.GetFiles("*.*");
			Array.Sort(files, FileNameComparer.Default);

            Assert.AreEqual(2, files.Length);
            Assert.AreEqual(FormatCommandLogName(3), files[0].Name, "3rd command log");
            Assert.AreEqual(FormatSnapshotName(3), files[1].Name, "2nd snapshot");

			// sanity check
			CrashRecover();
			AssertTotal(60);
		}
コード例 #4
0
		public void TestCleanUpAllFilesPolicy()
		{
			// some log files...
			Add(20); // 1st log file
			CrashRecover();
			Add(30); // 2nd log file			
			_engine.TakeSnapshot(); // 1st snapshot
			Add(10); // 3rd log file
			_engine.TakeSnapshot(); // 2nd snapshot
			Add(20); // 4rd log file
			
			FileInfo[] files = CleanUpAllFilesPolicy.Default.SelectFiles(_engine);

            Assert.AreEqual(4, files.Length);
            Assert.AreEqual(FormatCommandLogName(1), files[0].Name);
            Assert.AreEqual(FormatCommandLogName(2), files[1].Name);
            Assert.AreEqual(FormatSnapshotName(2), files[2].Name);
            Assert.AreEqual(FormatCommandLogName(3), files[3].Name);

			SnapshotTaker taker = new SnapshotTaker(_engine, TimeSpan.FromMilliseconds(200), CleanUpAllFilesPolicy.Default);
			Thread.Sleep(300);
			taker.Dispose();

			// sanity check
			CrashRecover();
			AssertTotal(80);
		}
コード例 #5
0
 private void SetupEngine()
 {
     engine = PrevalenceActivator.CreateTransparentEngine(typeof (CacheSystem), dataDir);
     system = engine.PrevalentSystem as CacheSystem;
     taker = new SnapshotTaker(engine, TimeSpan.FromMinutes(5), CleanUpAllFilesPolicy.Default);
 }