Пример #1
0
        public void T120_Rejuvenate()
        {
            using (var cache = PileCacheTestCore.MakeCache())
            {
                var tA = cache.GetOrCreateTable <string>("A");

                Assert.AreEqual(PutResult.Inserted, tA.Put("key1", "value1", 12));
                Assert.AreEqual(PutResult.Inserted, tA.Put("key2", "value2", 12));
                Assert.AreEqual(PutResult.Inserted, tA.Put("key3", "value3", 12));



                Assert.AreEqual("value1", tA.Get("key1"));
                Assert.AreEqual("value2", tA.Get("key2"));
                Assert.AreEqual("value3", tA.Get("key3"));

                for (var i = 0; i < 30; i++)
                {
                    Thread.Sleep(1000);
                    Console.WriteLine("Second {0}   Load Factor {1}", i, tA.LoadFactor);
                    Assert.IsTrue(tA.Rejuvenate("key2"));
                }

                Assert.AreEqual(null, tA.Get("key1"));
                Assert.AreEqual("value2", tA.Get("key2"));//this is still here because it got rejuvenated
                Assert.AreEqual(null, tA.Get("key3"));

                Thread.Sleep(30000);
                Assert.AreEqual(null, tA.Get("key2"));//has died too
                Assert.AreEqual(0, tA.Count);
            }
        }
Пример #2
0
        public void T070_DoesNotSeeAgedOrExpired()
        {
            using (var cache = PileCacheTestCore.MakeCache())
            {
                var tA = cache.GetOrCreateTable <string>("A");
                var tB = cache.GetOrCreateTable <string>("B");
                var tC = cache.GetOrCreateTable <string>("C");
                tC.Options.DefaultMaxAgeSec = 4;
                var tD = cache.GetOrCreateTable <string>("D");

                Aver.IsTrue(PutResult.Inserted == tA.Put("key1", "value1"));                                                       //does not expire by itself
                Aver.IsTrue(PutResult.Inserted == tB.Put("key1", "value1", 7));                                                    //will expire in 7 seconds
                Aver.IsTrue(PutResult.Inserted == tC.Put("key1", "value1"));                                                       //will expire in Options.DefaultMaxAgeSec
                Aver.IsTrue(PutResult.Inserted == tD.Put("key1", "value1", absoluteExpirationUTC: DateTime.UtcNow.AddSeconds(4))); //will expire at specific time

                Aver.AreObjectsEqual("value1", tA.Get("key1"));
                Aver.AreObjectsEqual("value1", tA.Get("key1", 3));

                Aver.AreObjectsEqual("value1", tB.Get("key1"));

                Aver.AreObjectsEqual("value1", tC.Get("key1"));

                Aver.AreObjectsEqual("value1", tD.Get("key1"));

                Thread.Sleep(20000);// wait long enough to cover a few swep cycles (that may be 5+sec long)

                Aver.AreObjectsEqual("value1", tA.Get("key1"));
                Aver.AreObjectsEqual(null, tA.Get("key1", 3)); //did not expire, but aged over get limit
                Aver.AreObjectsEqual(null, tB.Get("key1"));    //expired because of put with time limit
                Aver.AreObjectsEqual(null, tC.Get("key1"));    //expired because of Options
                Aver.AreObjectsEqual(null, tD.Get("key1"));    //expired because of absolute expiration on put
            }
        }