public void SubscribersTest() { //Scenario: //reserve package name //try to get package by first subscriber //try to get package by second subscriber //register downloaded package //the first subscriber should get notification //the second subscriber should get notification //the third subscriber appears and get package local address var reservationKey = "ReservationKey"; var cacher = new PackageCacherImpl(clearInterval, lifeTime, tempDir); var address = cacher.ReserveAddress(reservationKey); var firstSubscriberGotPackage = false; cacher.Get(reservationKey, (response) => { firstSubscriberGotPackage = true; }); var secondSubscriberGotPackage = false; cacher.Get(reservationKey, (response) => { secondSubscriberGotPackage = true; }); cacher.RegisterDownloaded(reservationKey, 0); var thirdSubscriberGotPackage = false; cacher.Get(reservationKey, (response) => { thirdSubscriberGotPackage = true; }); Assert.IsTrue(firstSubscriberGotPackage); Assert.IsTrue(secondSubscriberGotPackage); Assert.IsTrue(thirdSubscriberGotPackage); }
public void CommonTest() { //Scenario: //create cacher //create two files, they will be out-of-time //create third file, it will be out-of-time too, but cacher mustn't delete it as it will be locked by reading //create forth file, it will be out-of-time too, but cacher mustn't delete it as it will touched. //make a delay according to time-of-life //create fifth, it won't be expired //open third file on read //touch forth to overcome out-of-time //take a small delay //conclude what exists now //run cleaning by cacher //see what are lasted //there must be third, forth and fifth if (Directory.Exists(tempDir)) { Directory.Delete(tempDir); } Console.WriteLine(Directory.CreateDirectory(tempDir).FullName); var FIRST_KEY = "first.txt"; var SECOND_KEY = "second.txt"; var THIRD_KEY = "third.txt"; var FORTH_KEY = "forth.txt"; var FIFTH_KEY = "fifth.txt"; var cacher = new PackageCacherImpl(clearInterval, lifeTime, tempDir); var FIRST = cacher.ReserveAddress(FIRST_KEY); var SECOND = cacher.ReserveAddress(SECOND_KEY); var THIRD = cacher.ReserveAddress(THIRD_KEY); var FORTH = cacher.ReserveAddress(FORTH_KEY); var FIFTH = cacher.ReserveAddress(FIFTH_KEY); CreateFiles(FIRST, SECOND, THIRD, FORTH); RegisterFiles(cacher, FIRST_KEY, SECOND_KEY, THIRD_KEY, FORTH_KEY); Thread.Sleep(5 * 1000); CreateFile(FIFTH); RegisterFiles(cacher, FIFTH_KEY); var readingFile = ReadFile(THIRD); //It's synchronius cacher.Get(FORTH_KEY, (x) => {}); Thread.Sleep(2 * 1000); Assert.IsTrue(CheckExisting(FIRST, SECOND, THIRD, FORTH, FIFTH)); cacher.Clean(); Assert.IsTrue(CheckExisting(THIRD, FORTH, FIFTH)); }