Exemplo n.º 1
0
        public void TestNamedDefaultPofSerializer()
        {
            IXmlElement xmlConfig = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-extend-named-pof-default-serializer-cache-config.xml");

            CacheFactory.Configure(xmlConfig, null);
            INamedCache cache = CacheFactory.GetCache("dist-default");

            cache.Clear();

            // create a key, and value
            String sKey   = "hello";
            String sValue = "grid";

            // insert the pair into the cache
            cache.Add(sKey, sValue);

            // get the key and value back
            IDictionary entries = cache.GetAll(cache.Keys);

            Assert.AreEqual(1, entries.Count);
            Assert.IsInstanceOf(typeof(IDictionary), entries);
            Assert.AreEqual(sValue, ((String)((IDictionary)entries)[sKey]));

            CacheFactory.ReleaseCache(cache);
        }
        /// <summary>
        /// Test CacheData.
        /// Put and get a set of data from cache.
        /// </summary>
        public void TestCacheData()
        {
            var map  = new Hashtable();
            var keys = new ArrayList();

            for (int i = 0; i < 100; i++)
            {
                string key = "key" + i;
                keys.Add(key);
                map.Add(key, i);
            }

            namedCache.Clear();
            namedCache.InsertAll(map);
            ICollection entrySet = namedCache.GetAll(keys);

            Assert.AreEqual(100, entrySet.Count);
            namedCache.Release();
        }
        public void TestNamedCacheMethods()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);
            string      key   = "testNamedCacheInterfaceMethodsKey";
            string      value = "testNamedCacheInterfaceMethodsValue";

            object[] keys   = { GetKeyObject("key1"), GetKeyObject("key2"), GetKeyObject("key3") };
            string[] values = { "value1", "value2", "value3" };

            cache.Clear();
            Assert.IsTrue(cache.Count == 0);

            cache.Add(GetKeyObject(key), value);
            Assert.AreEqual(cache.Count, 1);
            Assert.AreEqual(cache[GetKeyObject(key)], value);
            Assert.IsTrue(cache.Contains(GetKeyObject(key)));

            object old = cache.Insert(keys[0], values[0]);

            Assert.IsNull(old);
            Assert.AreEqual(cache[keys[0]], values[0]);

            IDictionary h = new Hashtable();

            h.Add(keys[0], values[0]);
            h.Add(keys[1], values[1]);
            h.Add(keys[2], values[2]);

            cache.InsertAll(h);

            IList       list = new ArrayList(keys);
            IDictionary map  = cache.GetAll(list);

            Assert.AreEqual(map.Count, list.Count);
            Assert.AreEqual(cache[keys[1]], map[keys[1]]);

            cache.Remove(GetKeyObject(key));
            Assert.IsNull(cache[GetKeyObject(key)]);

            Binary bin = new Binary(new byte[] { 1, 2, 3 });

            cache.Insert(GetKeyObject("key4"), bin);
            object o = cache[GetKeyObject("key4")];

            Assert.IsNotNull(o);
            Assert.IsInstanceOf(typeof(Binary), o);
            Assert.AreEqual(bin.Length, ((Binary)o).Length);

            CacheFactory.ReleaseCache(cache);
            CacheFactory.Shutdown();
        }
        public void TestRemoteNamedCacheGetAllWithSameKeys()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();
            IDictionary dict = new Hashtable();

            for (int i = 0; i < 10; i++)
            {
                dict.Add(GetKeyObject("key" + i), "value" + i);
            }
            cache.InsertAll(dict);
            object[]    keys   = { GetKeyObject("key1"), GetKeyObject("key2"), GetKeyObject("key1"), GetKeyObject("key1") };
            IDictionary result = cache.GetAll(keys);

            Assert.AreEqual(2, result.Count);
            CacheFactory.Shutdown();
        }