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); }
public virtual void TestNamedCacheLock() { 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))); cache.Lock(key); Assert.AreEqual(cache[GetKeyObject(key)], value); cache.Unlock(key); cache.Lock(key); Assert.AreEqual(cache[GetKeyObject(key)], value); cache.Unlock(key); CacheFactory.ReleaseCache(cache); CacheFactory.Shutdown(); }
public void PofCircularReference() { CacheFactory.DefaultPofConfigPath = "//Coherence.Tests/Tangosol.Resources/s4hc-test-reference-config.xml"; CacheFactory.DefaultPofConfig = XmlHelper.LoadResource(ResourceLoader.GetResource( "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-reference-config.xml"), "POF configuration"); IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; ccf.Config = XmlHelper.LoadXml( "assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config-reference.xml"); ICacheService service = (ICacheService)ccf.EnsureService("ExtendTcpCacheService"); INamedCache cache = service.EnsureCache("dist-extend-reference"); var joe = new PortablePerson("Joe Smith", new DateTime(78, 4, 25)); var jane = new PortablePerson("Jane Smith", new DateTime(80, 5, 22)); joe.Spouse = jane; jane.Spouse = joe; cache.Add("Key1", joe); cache.Invoke("Key1", new ConditionalPut(new AlwaysFilter(), joe, false)); CacheFactory.DefaultPofConfigPath = "//Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"; CacheFactory.DefaultPofConfig = XmlHelper.LoadResource(ResourceLoader.GetResource( "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"), "POF configuration"); CacheFactory.Shutdown(); }
public void TestEvents() { // start the ProxyService on just one cluster node IInvocationService invocationService = RestartProxy(null); // put data items into inner cache to generate events INamedCache testCache = GetCache("proxy-stop-test"); testCache.Clear(); for (int i = 0; i < SOME_DATA; i++) { testCache.Add("TestKey" + i, i); } // create listener for CQC TestCQCListener listener = new TestCQCListener(SOME_DATA); // instantiate the CQC, will start the test running. theCQC = new ContinuousQueryCache(testCache, AlwaysFilter.Instance, listener); // instantiate a service listener to receive memberLeft event fMemberLeft = false; testCache.CacheService.MemberLeft += new MemberEventHandler(OnMemberLeft); // allow test time to complete. DateTime endTime = DateTime.Now.AddSeconds(30); while (listener.GetActualTotal() < SOME_DATA && (DateTime.Now < endTime)) { Thread.Sleep(250); } // check listener received the correct number of events. Assert.AreEqual(SOME_DATA, listener.GetActualTotal()); listener.ResetActualTotal(); // restart proxy RestartProxy(invocationService); endTime = DateTime.Now.AddSeconds(30); while (!fMemberLeft && (DateTime.Now < endTime)) { Thread.Sleep(250); } // ping the CQC to make it realize the cache needs restart. theCQC.Contains("junkstuff"); // allow test time to complete. endTime = DateTime.Now.AddSeconds(30); while (listener.GetActualTotal() < SOME_DATA && (DateTime.Now < endTime)) { Thread.Sleep(250); } Assert.AreEqual(SOME_DATA, listener.GetActualTotal()); }
public void TestCompositeKey() { ConfigurablePofContext.DefaultPofConfig = XmlHelper.LoadResource( ResourceLoader.GetResource( "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-reference-config.xml"), "POF configuration"); INamedCache cache = CacheFactory.GetCache("dist-pof-test"); cache.Clear(); CompositeKey key0 = new CompositeKey(new PortablePerson("Joe Smith", new DateTime(78, 4, 25)), new PortablePerson("Joe Smith", new DateTime(78, 4, 25))); PortablePerson person1 = new PortablePerson("Joe Smith", new DateTime(78, 4, 25)); CompositeKey key1 = new CompositeKey(person1, person1); cache.Add(key0, "value0"); cache.Add(key1, "value1"); Assert.AreEqual(1, cache.Count); CacheFactory.Shutdown(); ConfigurablePofContext.DefaultPofConfig = null; }
public void TestDeferKeyAssociationCheck() { INamedCache cache = CacheFactory.GetCache("defer-key-association-check"); cache.Add("key", "value"); Exception e = null; try { cache.Add(new CustomKeyClass("key"), "value"); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); cache.Clear(); CacheFactory.Shutdown(); }
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 TestCustomEventTransformer() { INamedCache cache = CacheFactory.GetCache("dist-cache"); cache.Clear(); // add data var obj1 = new EventTransformerTestObject(); obj1.ID = 1; obj1.Name = "A"; cache.Add(1, obj1); // add two listeners ICacheListener listener1 = AddListener(cache); ICacheListener listener2 = AddListener(cache); Thread.Sleep(100); // add more data var obj2 = new EventTransformerTestObject(); var obj3 = new EventTransformerTestObject(); obj2.ID = 2; obj2.Name = "B"; obj3.ID = 3; obj3.Name = "C"; cache.Add(2, obj2); cache.Add(3, obj3); // remove an entry cache.Remove(1); Thread.Sleep(1000); Assert.AreEqual(4, cInsertCalled); Assert.AreEqual(2, cDeleteCalled); }
/// <summary> /// Execute a cycle of basic operations. /// </summary> /// <param name="cache"> /// The target cache. /// </param> public virtual void Execute(INamedCache cache) { Contact contact = createContact(); ContactId contactId = new ContactId(contact.FirstName, contact.LastName); Console.WriteLine("------BasicExample begins------"); // associate a ContactId with a Contact in the cache cache.Add(contactId, contact); // retrieve the Contact associated with a ContactId from the cache contact = (Contact)cache[contactId]; // remove mapping of ContactId to Contact from the cache. cache.Remove(contactId); Console.WriteLine("------BasicExample completed------"); }
public void TestComparer() { INamedCache cache = CacheFactory.GetCache("dist-comparator-cache"); Random r = new Random(); for (int i = 0; i < 10000; i++) { AirDealComparer.AirDeal deal = new AirDealComparer.AirDeal(i, "SFO", "JFK", r.NextDouble()); cache.Add(deal.Oid, deal); } IValueExtractor ve = new ReflectionExtractor("getOrigAirport"); cache.AddIndex(ve, true, null); IFilter primaryFilter = new EqualsFilter(ve, "SFO"); IFilter filterLimit = new LimitFilter(primaryFilter, 40); ICollection setReturn = cache.GetEntries(filterLimit, new AirDealComparer()); Assert.AreEqual(setReturn.Count, 40); }
public void TestCacheOperations() { ConfigurablePofContext.DefaultPofConfig = XmlHelper.LoadResource( ResourceLoader.GetResource( "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-reference-config.xml"), "POF configuration"); INamedCache cache = CacheFactory.GetCache("dist-pof-test"); PortablePerson ellen = new PortablePerson("Ellen", new DateTime(105, 3, 15)); PortablePerson tom = new PortablePerson("Tom", new DateTime(103, 7, 5)) { Children = new PortablePerson[] { ellen } }; cache.Add(tom.Name, tom); PortablePerson netObj = (PortablePerson)cache[tom.Name]; Assert.IsTrue(tom.Equals(netObj)); CacheFactory.Shutdown(); ConfigurablePofContext.DefaultPofConfig = null; }
public void Save(K key, M item) { _coherenceCache.Add(key, item); }
public void Put <T>(string key, T value, TimeSpan lifeSpan) { cache.Add(key, value); }