Example #1
0
        public void ContainsKey_CanDetectValid()
        {
            var cache = new TimedCache<string>("test3", 10, 10);
            cache.Add("newkey", "something");

            Assert.IsTrue(cache.ContainsKey("newkey"));
        }
 public void ResetTest3()
 {
     TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 0, 5));
     cache.Set(1, 2);
     System.Threading.Thread.Sleep(5100);
     Assert.Throws<KeyNotFoundException>(delegate() { cache.Reset(1); });
 }
Example #3
0
 public CrcCacheManager()
 {
     AllReportsCacheByUsername = new TimedCache<rws.CatalogItem[]>("allrep", 30, 45);
     AllReportsHierarchicalCacheByUsername = new TimedCache<CrissCrossLib.Hierarchical.CrcReportFolder>("allrephier", 30, 45);
     PopularReportsCacheByUsername = new TimedCache<rws.CatalogItem[]>("poprep", 30, 45);
     GlobalPopularReportsCacheByUsername = new TimedCache<rws.CatalogItem[]>("globpoprep", 30, 45);
 }
Example #4
0
        public void Add_CanAdd()
        {
            var cache = new TimedCache<string>("test1", 10, 10);
            cache.Add("newkey", "something");

            var retreive = cache["newkey"];
            Assert.AreEqual("something", retreive);
        }
Example #5
0
        public void ContainsKey_CanDetectInValid()
        {
            var cache = new TimedCache <string>("test4", 10, 10);

            cache.Add("newkey", "something");

            Assert.IsFalse(cache.ContainsKey("wrongkey"));
        }
Example #6
0
        public void Add_CanAdd()
        {
            var cache = new TimedCache <string>("test1", 10, 10);

            cache.Add("newkey", "something");

            var retreive = cache["newkey"];

            Assert.AreEqual("something", retreive);
        }
Example #7
0
        public void Item_CanReturnNullIfNotFound()
        {
            var cache = new TimedCache <string>("test2", 10, 10);

            cache.Add("newkey", "something");

            var retreive         = cache["newkey"];
            var retreiveUnlikely = cache["unusedkey"];

            Assert.AreEqual("something", retreive);
            Assert.IsNull(retreiveUnlikely);
        }
Example #8
0
        public void GetValidUntilDateTimeTest()
        {
            TimedCache <string, string> timedCache = new TimedCache <string, string>(TimeSpan.FromHours(5.0));
            DateTime validUntil = timedCache.GetValidUntilDateTime();

            TimeSpan timeSpan        = validUntil - DateTime.UtcNow;
            TimeSpan greaterTimeSpan = new TimeSpan(5, 1, 0);
            TimeSpan lesserTimeSpan  = new TimeSpan(4, 59, 0);

            Assert.LessOrEqual(timeSpan.Milliseconds, greaterTimeSpan.Milliseconds);
            Assert.GreaterOrEqual(timeSpan.Milliseconds, lesserTimeSpan.Milliseconds);
        }
Example #9
0
        // this test takes a couple of minutes so commented out TestMethod attribute
        // comment it back in if you're looking at cache behaviour
        //[TestMethod]
        public void ItemsCanExpire()
        {
            var cache = new TimedCache <string>("test4", 1, 1);

            cache.Add("newkey", "something");
            var retreiveEarly = cache["newkey"];

            System.Threading.Thread.Sleep(TimeSpan.FromMinutes(1.5));
            var retreiveLate = cache["newkey"];

            Assert.AreEqual("something", retreiveEarly);
            Assert.IsNull(retreiveLate);
        }
Example #10
0
        /// <summary>
        /// creates a new <see cref="StatusWindow"/>
        /// </summary>
        /// <param name="context">module context</param>
        public StatusWindow(Context context)
            : base(context)
        {
            InitializeComponent();
            this.context = context;
            emotecache   = new TimedCache <long, BitmapImage>(CreateImage);
            Closing     += (sender, args) => {
                Visibility  = Visibility.Hidden;
                args.Cancel = true;
            };

            IsVisibleChanged += OnVisibilityChanged;
        }
Example #11
0
        //Todo: Write IT

        //Todo:Refactor name
        private TimedCache <int> AddItemAndSimulateTimerCall(TimeSpan timeoutPeriod, TimeSpan timeUntilTimerCall)
        {
            var timeProviderMock = new Mock <ITimeProvider>();

            timeProviderMock.Setup(timeProvider => timeProvider.Now).Returns(_defaultTime);
            TimerMock timerMock = new TimerMock();

            var timedCache = new TimedCache <int>(timeoutPeriod, timerMock, timeProviderMock.Object);

            timedCache.Add(_defaultElement);
            timeProviderMock.Setup(timeProvider => timeProvider.Now).Returns(_defaultTime + timeUntilTimerCall);
            timerMock.RaiseElapsed();
            return(timedCache);
        }
Example #12
0
        public World(MinecraftServer server, string name, IWorldGenerator generator)
        {
            Server = server;
            Name   = name;

            Chunks         = new TimedCache <Chunk>("Chunk cache", TimeSpan.FromMinutes(5));
            PlayerEntities = new List <PlayerEntity>();
            Entities       = new List <BaseEntity>();

            Generator = generator;

            if (!Directory.Exists(GetDirectory()))
            {
                Directory.CreateDirectory(GetDirectory());

                Format = new WaterWorldFormat(this);

                // world does not exist - generate
                int a = (int)Math.Floor(initializationChunks / 2d);
                int i = 0;

                Stopwatch totalStopwatch = new();
                totalStopwatch.Start();

                for (int x = -a; x <= a; x++)
                {
                    for (int z = -a; z <= a; z++)
                    {
                        LoadChunk(x, z);
                        i++;
                    }
                }

                totalStopwatch.Stop();
                Logger.Info(
                    $"Finished generating world! ({i} chunks) Took {Math.Round(totalStopwatch.Elapsed.TotalMilliseconds, 2)}ms");

                Format.Save();
            }
            else
            {
                Format = new WaterWorldFormat(this);
                Format.Load();
            }

            WorldThread      = new Thread(Update);
            WorldThread.Name = "World update thread";
            WorldThread.Start();
        }
        public void TryGetTest1()
        {
            TimedCache<int, object> cache = new TimedCache<int, object>(new TimeSpan(0, 1, 0));

            object o = null;
            Assert.IsFalse(cache.TryGet(1, ref o));
            Assert.IsNull(o);

            cache.Set(1, o);
            Assert.IsTrue(cache.TryGet(1, ref o));
            Assert.IsNull(o);

            o = new object();
            cache.Set(1, o);
            Assert.IsTrue(cache.TryGet(1, ref o));
            Assert.IsNotNull(o);
        }
Example #14
0
        public void GetValidUntilDateTimeConfigTest()
        {
            /// Tester the TimeCache with the constructor, that is used i Rasp
            /// https://bugs.softwareborsen.dk/show_bug.cgi?id=1210
            Dictionary <string, string> config = new Dictionary <string, string>();

            config.Add("validityTimeInHours", "24");
            config.Add("frequencyInMinutes", "10");

            TimedCache <string, string> timedCache = new TimedCache <string, string>(config);
            DateTime validUntil = timedCache.GetValidUntilDateTime();

            TimeSpan timeSpan        = validUntil - DateTime.UtcNow;
            TimeSpan greaterTimeSpan = new TimeSpan(24, 1, 0);
            TimeSpan lesserTimeSpan  = new TimeSpan(23, 59, 0);

            Assert.LessOrEqual(timeSpan.Milliseconds, greaterTimeSpan.Milliseconds);
            Assert.GreaterOrEqual(timeSpan.Milliseconds, lesserTimeSpan.Milliseconds);
        }
Example #15
0
 /// <summary>
 /// creates a new <see cref="TextModule"/>
 /// </summary>
 /// <param name="context">access to module context</param>
 public TextModule(Context context)
 {
     this.context = context;
     imagecache   = new TimedCache <TextSpecs, byte[]>(CreateText);
 }
        public void TryGetTest2()
        {
            TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 1, 0));

            int output = 5;
            Assert.IsFalse(cache.TryGet(1, ref output));
            Assert.AreEqual(5, output);

            cache.Set(10, output);
            int output2 = Int32.MinValue;
            Assert.IsTrue(cache.TryGet(10, ref output2));
            Assert.AreEqual(5, output2);

            output = 15;
            cache.Set(10, output);
            int output3 = Int32.MinValue;
            Assert.IsTrue(cache.TryGet(10, ref output3));
            Assert.AreEqual(15, output3);
        }
Example #17
0
        public void Item_CanReturnNullIfNotFound()
        {
            var cache = new TimedCache<string>("test2", 10, 10);
            cache.Add("newkey", "something");

            var retreive = cache["newkey"];
            var retreiveUnlikely = cache["unusedkey"];
            Assert.AreEqual("something", retreive);
            Assert.IsNull(retreiveUnlikely);
        }
 public void ResetTest2()
 {
     TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 1, 0));
     Assert.Throws<KeyNotFoundException>(delegate() { cache.Reset(1); });
 }
 public void ResetTest()
 {
     TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 1, 0));
     cache.Set(1, 2);
     cache.Reset(1);
 }
 public void TryResetTest3()
 {
     TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 0, 5));
     cache.Set(1, 2);
     System.Threading.Thread.Sleep(5100);
     Assert.IsFalse(cache.TryReset(1));
 }
        public void TryResetTest2()
        {
            TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 1, 0));

            Assert.IsFalse(cache.TryReset(1));
        }
 public void TryResetTest()
 {
     TimedCache<int, int> cache = new TimedCache<int, int>(new TimeSpan(0, 1, 0));
     cache.Set(1, 2);
     Assert.IsTrue(cache.TryReset(1));
 }
Example #23
0
        // this test takes a couple of minutes so commented out TestMethod attribute
        // comment it back in if you're looking at cache behaviour
        //[TestMethod]
        public void ItemsCanExpire()
        {
            var cache = new TimedCache<string>("test4", 1, 1);
            cache.Add("newkey", "something");
            var retreiveEarly = cache["newkey"];
            System.Threading.Thread.Sleep(TimeSpan.FromMinutes(1.5));
            var retreiveLate = cache["newkey"];

            Assert.AreEqual("something", retreiveEarly);
            Assert.IsNull(retreiveLate);
        }