Ejemplo n.º 1
0
        public void NearCacheListenNoneTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            nearcache.Add(1, "Ivan");
            Assert.AreEqual(1, nearcache.Count);
            Assert.AreEqual(1, nearcache.FrontCache.Count);
            Assert.AreEqual(1, nearcache.BackCache.Count);
            nearcache.Insert(2, "Goran");
            Assert.AreEqual(2, nearcache.Count);
            Assert.AreEqual(2, nearcache.FrontCache.Count);
            Assert.AreEqual(2, nearcache.BackCache.Count);
            Assert.IsTrue(nearcache.FrontCache.Contains(1));
            Assert.IsTrue(nearcache.FrontCache.Contains(2));
            Assert.IsTrue(nearcache.BackCache.Contains(1));
            Assert.IsTrue(nearcache.BackCache.Contains(2));

            object obj = nearcache[1];

            Assert.AreEqual("Ivan", obj);
            obj = nearcache[2];
            Assert.AreEqual("Goran", obj);

            nearcache.Clear();
            Assert.AreEqual(0, nearcache.Count);
            Assert.IsTrue(nearcache.IsActive);
            localcache.LocalCache = new LocalCache(Int32.MaxValue, 500);
            nearcache.Insert(1, "Ana");
            nearcache.Add(2, "Goran");
            Assert.IsTrue(nearcache.FrontCache.Contains(1));
            Assert.IsTrue(nearcache.FrontCache.Contains(2));
            Assert.IsTrue(nearcache.BackCache.Contains(1));
            Assert.IsTrue(nearcache.BackCache.Contains(2));
            Thread.Sleep(1000);
            Assert.IsNull(nearcache.FrontCache[1]);
            Assert.IsNull(nearcache.FrontCache[2]);

            nearcache.Insert(3, "Ivan");
            IDictionary dict = nearcache.GetAll(new object[] { 1, 2, 3, 4 });

            Assert.AreEqual("Ana", dict[1]);
            Assert.AreEqual("Goran", dict[2]);
            Assert.AreEqual("Ivan", dict[3]);
            Assert.AreEqual(null, dict[4]);

            localcache.LocalCache = new LocalCache();
            obj = nearcache[1];
            Assert.AreEqual(obj, "Ana");
            Assert.IsTrue(nearcache.FrontCache.Contains(1));
            Assert.IsNull(nearcache.FrontCache[2]);

            Hashtable ht = new Hashtable();

            ht.Add(2, "Goran");
            ht.Add(3, "Ivan");
            ht.Add(4, "Aleks");
            nearcache.InsertAll(ht);
            nearcache.Remove(1);
            Assert.IsNull(nearcache.FrontCache[1]);
            Assert.IsNull(nearcache[1]);

            nearcache.Clear();
            nearcache.Release();
            Assert.IsFalse(nearcache.IsActive);

            CacheFactory.Shutdown();
        }