コード例 #1
0
        public void TestRemoteInvocation()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml");

            ccf.Config = config;

            IService service = CacheFactory.GetService("RemoteInvocationService");

            Assert.IsNotNull(service);
            Assert.IsInstanceOf(typeof(SafeInvocationService), service);
            SafeInvocationService sis = service as SafeInvocationService;

            Assert.IsNotNull(sis);
            Assert.IsTrue(sis.IsRunning);
            Assert.AreEqual(sis.ServiceName, "RemoteInvocationService");
            Assert.AreEqual(sis.ServiceType, ServiceType.RemoteInvocation);
            Assert.IsNotNull(sis.Service);
            Assert.IsInstanceOf(typeof(RemoteInvocationService), sis.Service);
            Assert.IsNotNull(sis.Serializer);
            Assert.IsInstanceOf(typeof(ConfigurablePofContext), sis.Serializer);
            RemoteInvocationService ris = sis.Service as RemoteInvocationService;

            Assert.IsNotNull(ris);
            Assert.IsTrue(ris.IsRunning);
            Assert.AreEqual(ris.ServiceName, "RemoteInvocationService");
            Assert.AreEqual(ris.ServiceType, ServiceType.RemoteInvocation);
            Assert.AreEqual(ris.OperationalContext.Edition, 1);
            Assert.IsNotNull(ris.OperationalContext.LocalMember);
            Assert.IsNotNull(ris.Serializer);
            Assert.IsInstanceOf(typeof(ConfigurablePofContext), ris.Serializer);

            IInvocable  invocable = new EmptyInvocable();
            IDictionary result    = sis.Query(invocable, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[ris.OperationalContext.LocalMember], 42);

            sis.Shutdown();
            Assert.IsFalse(sis.IsRunning);
        }
コード例 #2
0
        public void TestJmxConnectionInformation()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;
            IXmlDocument config           = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml");

            ccf.Config = config;
            IInvocationService service = (IInvocationService)CacheFactory.GetService("RemoteInvocationService");
            IMember            member  = ((DefaultConfigurableCacheFactory)ccf).OperationalContext.LocalMember;

            MBeanInvocable invocable = new MBeanInvocable();

            IDictionary result = service.Query(invocable, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 1);

            Assert.IsNotNull(result[member]);

            service.Shutdown();
        }
コード例 #3
0
        public void TestLocking()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            Assert.IsTrue(cache is LocalNamedCache);

            LocalNamedCache localNamedCache = cache as LocalNamedCache;

            Assert.IsNotNull(localNamedCache);
            Hashtable ht = new Hashtable();

            ht.Add("key1", 435);
            ht.Add("key2", 253);
            ht.Add("key3", 3);
            ht.Add("key4", 200);
            localNamedCache.InsertAll(ht);

            localNamedCache.Lock("key2");
            localNamedCache.Lock("key2", 1000);

            localNamedCache.Unlock("key2");

            GreaterFilter filter = new GreaterFilter(IdentityExtractor.Instance, 280);

            object[] results = localNamedCache.GetValues(filter, null);

            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(435, results[0]);

            results = localNamedCache.GetEntries(filter, null);
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(435, ((ICacheEntry)results[0]).Value);

            CacheFactory.Shutdown();
        }
コード例 #4
0
        public void TestEntries()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            Assert.IsTrue(cache is LocalNamedCache);

            LocalNamedCache localNamedCache = cache as LocalNamedCache;

            Assert.IsNotNull(localNamedCache);
            Hashtable ht = new Hashtable();

            ht.Add("key1", 435);
            ht.Add("key2", 253);
            ht.Add("key3", 3);
            ht.Add("key4", 200);
            localNamedCache.InsertAll(ht);

            ICollection result = localNamedCache.Entries;

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count);

            result = localNamedCache.Values;
            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Count);

            int[] results = new int[localNamedCache.Count];
            localNamedCache.CopyTo(results, 0);
            Assert.AreEqual(localNamedCache.Count, result.Count);


            CacheFactory.Shutdown();
        }
コード例 #5
0
        public void TestConditional()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("conditionalKey1", 200);
            ht.Add("conditionalKey2", 250);
            ht.Add("conditionalKey3", 300);
            ht.Add("conditionalKey4", 400);
            cache.InsertAll(ht);


            IFilter lessThen300            = new LessFilter(IdentityExtractor.Instance, 300);
            ConditionalProcessor processor = new ConditionalProcessor(
                new GreaterFilter(IdentityExtractor.Instance, 200),
                new ConditionalRemove(lessThen300, false));

            Assert.IsTrue(cache.Count == 4);
            cache.Invoke("conditionalKey4", processor);
            Assert.IsTrue(cache.Count == 4);

            cache.Invoke("conditionalKey3", processor);
            Assert.IsTrue(cache.Count == 4);

            cache.Invoke("conditionalKey2", processor);
            Assert.IsTrue(cache.Count == 3);

            CacheFactory.Shutdown();
        }
コード例 #6
0
        public void TestMemberRemoteInvocation()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;
            IXmlDocument config           = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml");

            ccf.Config = config;
            IInvocationService service = (IInvocationService)CacheFactory.GetService("RemoteInvocationService");

            IMember member = new LocalMember();

            member.MachineName = "machine1";
            member.MemberName  = "member1";
            member.ProcessName = "process1";
            member.RackName    = "rack1";
            member.RoleName    = "role1";
            member.SiteName    = "site1";

            POFObjectInvocable invocable = new POFObjectInvocable();

            invocable.PofObject = member;

            IDictionary result = service.Query(invocable, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 1);
            IMember copy = (IMember)result[((DefaultConfigurableCacheFactory)CacheFactory
                                            .ConfigurableCacheFactory).OperationalContext.LocalMember];

            Assert.AreEqual(member.MachineName, copy.MachineName);
            Assert.AreEqual(member.MemberName, copy.MemberName);
            Assert.AreEqual(member.ProcessName, copy.ProcessName);
            Assert.AreEqual(member.RackName, copy.RackName);
            Assert.AreEqual(member.RoleName, copy.RoleName);
            Assert.AreEqual(member.SiteName, copy.SiteName);

            service.Shutdown();
        }
コード例 #7
0
        public void TestPropertiesAndMethods()
        {
            LocalNamedCache lnc = new LocalNamedCache(10, 10, null);

            Assert.IsNotNull(lnc);
            lnc = new LocalNamedCache(10, 10, 15.5);
            Assert.IsNotNull(lnc);

            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            Assert.IsTrue(cache is LocalNamedCache);

            LocalNamedCache localNamedCache = cache as LocalNamedCache;

            Assert.IsNotNull(localNamedCache);
            Assert.AreEqual("local-default", localNamedCache.CacheName);
            Assert.IsNull(localNamedCache.CacheService);

            Assert.IsTrue(localNamedCache.IsActive);
            Assert.IsFalse(localNamedCache.IsReleased);

            Assert.IsFalse(localNamedCache.IsReadOnly);
            Assert.IsFalse(localNamedCache.IsFixedSize);

            Assert.IsNotNull(localNamedCache.SyncRoot);

            Assert.IsTrue(localNamedCache.IsSynchronized);

            localNamedCache.Release();
            localNamedCache.Destroy();
        }
コード例 #8
0
        public void TestCompositeKeyRemoteInvocation()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;
            IXmlDocument config           = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml");

            ccf.Config = config;
            IInvocationService service = (IInvocationService)CacheFactory.GetService("RemoteInvocationService");

            CompositeKey       key       = new CompositeKey("abc", "xyz");
            POFObjectInvocable invocable = new POFObjectInvocable();

            invocable.PofObject = key;

            IDictionary result = service.Query(invocable, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 1);
            CompositeKey copy = (CompositeKey)result[((DefaultConfigurableCacheFactory)
                                                      CacheFactory.ConfigurableCacheFactory).OperationalContext.LocalMember];

            Assert.AreEqual(key, copy);

            service.Shutdown();
        }
コード例 #9
0
        public void TestListenerConfiguration()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config =
                XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-near-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("dist-extend-direct-listener");

            cache.Clear();
            SyncListenerStatic.Reset();

            Assert.IsNull(SyncListenerStatic.CacheEvent);
            cache.Insert("test", "yes");
            Assert.AreEqual(SyncListenerStatic.CacheEvent.EventType, CacheEventType.Inserted);
            cache["test"] = "d";
            Assert.AreEqual(SyncListenerStatic.CacheEvent.EventType, CacheEventType.Updated);
            cache.Remove("test");
            Assert.AreEqual(SyncListenerStatic.CacheEvent.EventType, CacheEventType.Deleted);

            CacheFactory.Shutdown();
        }
コード例 #10
0
        public void TestExtractor()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();
            ExtractorProcessor processor = new ExtractorProcessor(new ReflectionExtractor("Street"));
            Address            addr1     = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000");
            Address            addr2     = new Address("Pere Velimirovica", "Uzice", "Serbia", "11000");
            Address            addr3     = new Address("Rige od Fere", "Novi Sad", "Serbia", "11000");

            cache.Insert("addr1", addr1);
            cache.Insert("addr2", addr2);
            cache.Insert("addr3", addr3);

            Assert.IsTrue(cache.Count == 3);

            Object result = cache.Invoke("addr1", processor);

            Assert.IsNotNull(result);
            Assert.AreEqual(addr1.Street, result as String);

            processor = new ExtractorProcessor(new ReflectionExtractor("City"));
            IDictionary dictResult = cache.InvokeAll(cache.Keys, processor);

            Assert.AreEqual(addr1.City, dictResult["addr1"]);
            Assert.AreEqual(addr2.City, dictResult["addr2"]);
            Assert.AreEqual(addr3.City, dictResult["addr3"]);

            CacheFactory.Shutdown();
        }
コード例 #11
0
        public void TestEmbeddedCacheConfig()
        {
            var coherence   = (CoherenceConfig)ConfigurationUtils.GetCoherenceConfiguration();
            var oldResource = coherence.CacheConfig;
            IConfigurableCacheFactory ccf = null;

            try
            {
                coherence.CacheConfig = null; // null out configured cache config to force loading the default
                ccf = new DefaultConfigurableCacheFactory();

                INamedCache cache = ccf.EnsureCache("foo");
                Assert.AreEqual("RemoteCache", ((SafeCacheService)cache.CacheService).ServiceName);
                ccf.DestroyCache(cache);
            }
            finally
            {
                coherence.CacheConfig = oldResource; // restore
                if (ccf != null)
                {
                    ccf.Shutdown();
                }
            }
        }
コード例 #12
0
        public void TestFilterEnumerator()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Key1", 435);
            ht.Add("Key2", 253);
            ht.Add("Key3", 3);
            ht.Add("Key4", 200);
            ht.Add("Key5", 333);
            cache.InsertAll(ht);

            GreaterFilter    filter           = new GreaterFilter(IdentityExtractor.Instance, 200);
            FilterEnumerator filterEnumerator = new FilterEnumerator(cache.GetEnumerator(), filter);

            ArrayList results = new ArrayList();

            while (filterEnumerator.MoveNext())
            {
                object o = filterEnumerator.Current;
                Assert.IsNotNull(o);
                results.Add(o);
            }

            Assert.AreEqual(3, results.Count);

            foreach (ICacheEntry value in results)
            {
                Assert.IsTrue((int)value.Value > 200);
            }

            filterEnumerator.Reset();
            results.Clear();
            while (filterEnumerator.MoveNext())
            {
                object o = filterEnumerator.Current;
                Assert.IsNotNull(o);
                results.Add(o);
            }

            Assert.AreEqual(3, results.Count);

            foreach (ICacheEntry value in results)
            {
                Assert.IsTrue((int)value.Value > 200);
            }


            filterEnumerator.Reset();
            results.Clear();
            filter           = new GreaterFilter(IdentityExtractor.Instance, 400);
            filterEnumerator = new FilterEnumerator(cache.GetEnumerator(), filter);
            results          = new ArrayList();
            while (filterEnumerator.MoveNext())
            {
                object o = filterEnumerator.Current;
                Assert.IsNotNull(o);
                results.Add(o);
            }
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(ht["Key1"], ((ICacheEntry)results[0]).Value);

            filterEnumerator.Reset();
            results.Clear();
            filter           = new GreaterFilter(IdentityExtractor.Instance, 600);
            filterEnumerator = new FilterEnumerator(cache.GetEnumerator(), filter);
            results          = new ArrayList();
            while (filterEnumerator.MoveNext())
            {
                object o = filterEnumerator.Current;
                Assert.IsNotNull(o);
                results.Add(o);
            }
            Assert.AreEqual(0, results.Count);

            CacheFactory.Shutdown();
        }
コード例 #13
0
        public void TestExpiry()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-with-init");

            cache.Clear();
            Hashtable ht = new Hashtable();

            ht.Add("key1", 100.0);
            ht.Add("key2", 80.5);
            ht.Add("key3", 19.5);
            ht.Add("key4", 2.0);

            cache.InsertAll(ht);
            lock (this)
            {
                Monitor.Wait(this, 50);
            }

            foreach (ICacheEntry entry in cache)
            {
                Assert.IsTrue(entry is LocalCache.Entry);
                Assert.IsTrue(((LocalCache.Entry)entry).IsExpired);
            }


            cache = CacheFactory.GetCache("local-custom-impl-with-init");

            cache.Clear();
            ht = new Hashtable();
            ht.Add("key1", 100.0);
            ht.Add("key2", 80.5);
            ht.Add("key3", 19.5);
            ht.Add("key4", 2.0);

            cache.InsertAll(ht);
            lock (this)
            {
                Monitor.Wait(this, 50);
            }

            foreach (ICacheEntry entry in cache)
            {
                Assert.IsTrue(entry is LocalCache.Entry);
                Assert.IsFalse(((LocalCache.Entry)entry).IsExpired);
            }

            LocalNamedCache localCache = new LocalNamedCache();

            localCache.LocalCache.ExpiryDelay = 50;

            localCache.Clear();

            localCache.Insert("key1", 100.0, 2100);
            localCache.Insert("key2", 801.5, 2100);
            localCache.Insert("key3", 40.1, 2100);

            lock (this)
            {
                Monitor.Wait(this, 2300);
            }

            foreach (ICacheEntry entry in localCache)
            {
                Assert.IsTrue(entry is LocalCache.Entry);
                Assert.IsTrue(((LocalCache.Entry)entry).IsExpired);
            }

            CacheFactory.Shutdown();
        }
コード例 #14
0
        public void TestPrunization()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-custom-highunits");

            cache.Clear();
            Hashtable ht = new Hashtable();

            ht.Add("key1", 100.0);
            ht.Add("key2", 80.5);
            ht.Add("key3", 19.5);
            ht.Add("key4", 2.0);
            ht.Add("key5", 2.0);
            ht.Add("key6", 2.0);
            ht.Add("key7", 2.0);
            ht.Add("key8", 2.0);
            ht.Add("key9", 2.0);

            cache.InsertAll(ht);

            Assert.AreEqual(9, cache.Count);

            object result = cache["key8"];

            result = cache["key7"];
            result = cache["key8"];
            result = cache["key8"];

            ht.Clear();
            ht.Add("key10", 2.0);
            ht.Add("key11", 2.0);
            cache.InsertAll(ht);

            Assert.AreEqual(3, cache.Count);

            cache.Clear();
            ht.Clear();
            Assert.AreEqual(0, cache.Count);

            LocalCache localCache = new LocalCache(10);

            localCache.EvictionType = LocalCache.EvictionPolicyType.Hybrid;
            localCache.LowUnits     = 4;

            ht.Add("key1", 100.0);
            ht.Add("key2", 80.5);
            ht.Add("key3", 19.5);
            ht.Add("key4", 2.0);
            ht.Add("key5", 2.0);
            ht.Add("key6", 2.0);
            ht.Add("key7", 2.0);
            ht.Add("key8", 2.0);
            ht.Add("key9", 2.0);

            localCache.InsertAll(ht);

            Assert.AreEqual(ht.Count, localCache.Count);

            result = cache["key8"];
            result = cache["key7"];
            result = cache["key8"];
            result = cache["key8"];

            ht.Clear();
            ht.Add("key10", 2.0);
            ht.Add("key11", 2.0);
            localCache.InsertAll(ht);

            Assert.AreEqual(localCache.LowUnits, localCache.Count);

            CacheFactory.Shutdown();
        }
コード例 #15
0
        public void TestInvoke()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("conditionalPutKey1", 435);
            ht.Add("conditionalPutKey2", 253);
            ht.Add("conditionalPutKey3", 3);
            ht.Add("conditionalPutKey4", 200);
            ht.Add("conditionalPutKey5", 333);
            cache.InsertAll(ht);

            IFilter greaterThen600 = new GreaterFilter(IdentityExtractor.Instance, 600);
            IFilter greaterThen200 = new GreaterFilter(IdentityExtractor.Instance, 200);

            // no entries with value>600
            ICollection keys = cache.GetKeys(greaterThen600);

            Assert.IsTrue(keys.Count == 0);

            // invoke processor for one entry with filter that will evaluate to false
            // again, no entries with value>600
            IEntryProcessor processor = new ConditionalPut(greaterThen600, 666);

            cache.Invoke("conditionalPutKey1", processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.IsTrue(keys.Count == 0);

            // invoke processor for one entry with filter that will evaluate to true
            // this will change one entry
            processor = new ConditionalPut(AlwaysFilter.Instance, 666);
            cache.Invoke("conditionalPutKey1", processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 1);
            Assert.AreEqual(cache["conditionalPutKey1"], 666);

            // 3 entries with value>200
            keys = cache.GetKeys(greaterThen200);
            Assert.AreEqual(keys.Count, 3);

            // invoke processor for these three entries
            processor = new ConditionalPut(greaterThen200, 666);
            cache.InvokeAll(cache.Keys, processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 3);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("conditionalPutAllKey1", 435);
            ht.Add("conditionalPutAllKey2", 253);
            ht.Add("conditionalPutAllKey3", 200);
            ht.Add("conditionalPutAllKey4", 333);
            cache.InsertAll(ht);

            Hashtable htPut = new Hashtable();

            htPut.Add("conditionalPutAllKey1", 100);
            htPut.Add("conditionalPutAllKey6", 80);
            htPut.Add("conditionalPutAllKey3", 10);

            // put key1 and compare cache value with the put one
            processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut);
            cache.Invoke("conditionalPutAllKey1", processor);
            Assert.IsNotNull(cache["conditionalPutAllKey1"]);
            Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]);

            // TODO: Decide wheter putall should insert new entries or not
            // put all keys from htPut and compare cache values with put ones
            //cache.InvokeAll(htPut.Keys, processor);
            //Assert.IsTrue(cache.Count == 5);
            //Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]);
            //Assert.AreEqual(cache["conditionalPutAllKey6"], htPut["conditionalPutAllKey6"]);
            //Assert.AreEqual(cache["conditionalPutAllKey3"], htPut["conditionalPutAllKey3"]);

            //htPut.Clear();
            //htPut.Add("conditionalPutAllKey4", 355);
            //processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut);

            //cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 300), processor);
            //Assert.AreEqual(cache["conditionalPutAllKey4"], htPut["conditionalPutAllKey4"]);

            CacheFactory.Shutdown();
        }
コード例 #16
0
        public void TestAggregate()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();


            Hashtable ht = new Hashtable();

            ht.Add("comparableMaxKey1", 100);
            ht.Add("comparableMaxKey2", 80.5);
            ht.Add("comparableMaxKey3", 19.5);
            ht.Add("comparableMaxKey4", 2);
            cache.InsertAll(ht);

            IEntryAggregator aggregator = new DoubleAverage(IdentityExtractor.Instance);
            object           result     = cache.Aggregate(cache.Keys, aggregator);

            Assert.AreEqual(50.5, result);

            cache.Insert("comparableKey5", null);
            result = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(50.5, result);

            IFilter alwaysFilter = new AlwaysFilter();

            result = cache.Aggregate(alwaysFilter, aggregator);
            Assert.AreEqual(50.5, result);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("comparableMaxKey1", 435);
            ht.Add("comparableMaxKey2", 253);
            ht.Add("comparableMaxKey3", 3);
            ht.Add("comparableMaxKey4", null);
            ht.Add("comparableMaxKey5", -3);
            cache.InsertAll(ht);

            aggregator = new ComparableMax(IdentityExtractor.Instance);
            object max = cache.Aggregate(cache.Keys, aggregator);

            Assert.AreEqual(max, 435);

            max = cache.Aggregate(alwaysFilter, aggregator);
            Assert.AreEqual(max, 435);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("comparableMaxKey1", 435);
            ht.Add("comparableMaxKey2", 253);
            ht.Add("comparableMaxKey3", 3);
            ht.Add("comparableMaxKey4", 3);
            ht.Add("comparableMaxKey5", 3);
            ht.Add("comparableMaxKey6", null);
            ht.Add("comparableMaxKey7", null);
            cache.InsertAll(ht);

            aggregator = new DistinctValues(IdentityExtractor.Instance);
            result     = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(3, ((ICollection)result).Count);
            foreach (object o in ht.Values)
            {
                Assert.IsTrue(((IList)result).Contains(o) || o == null);
            }

            IFilter lessFilter = new LessFilter(IdentityExtractor.Instance, 100);

            result = cache.Aggregate(lessFilter, aggregator);
            Assert.AreEqual(1, ((ICollection)result).Count);

            cache.Clear();

            ht = new Hashtable();
            ht.Add("key1", 100);
            ht.Add("key2", 80.5);
            ht.Add("key3", 19.5);
            ht.Add("key4", 2);

            cache.InsertAll(ht);

            aggregator = new DoubleSum(IdentityExtractor.Instance);
            result     = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(202, result);

            IFilter filter = new AlwaysFilter();

            result = cache.Aggregate(filter, aggregator);
            Assert.AreEqual(202, result);


            cache.Clear();

            ht = new Hashtable();
            ht.Add("key1", 100);
            ht.Add("key2", 80);
            ht.Add("key3", 19);
            ht.Add("key4", 2);
            ht.Add("key5", null);

            cache.InsertAll(ht);

            aggregator = new LongSum(IdentityExtractor.Instance);
            result     = cache.Aggregate(cache.Keys, aggregator);
            Assert.AreEqual(201, result);

            IFilter greaterFilter = new GreaterFilter(IdentityExtractor.Instance, 1);

            result = cache.Aggregate(greaterFilter, aggregator);
            Assert.AreEqual(201, result);

            CacheFactory.Shutdown();
        }
コード例 #17
0
        public void TestListeners()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();

            SyncListener listen = new SyncListener();

            cache.AddCacheListener(listen, "test", false);
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("t", "a");
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("tes", "b");
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("test", "c");
            Assert.IsNotNull(listen.CacheEvent);
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Inserted);

            listen.CacheEvent = null;
            Assert.IsNull(listen.CacheEvent);
            cache["test"] = "d";
            Assert.IsNotNull(listen.CacheEvent);
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Updated);

            listen.CacheEvent = null;
            Assert.IsNull(listen.CacheEvent);
            cache.Remove("test");
            Assert.IsNotNull(listen.CacheEvent);
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Deleted);

            cache.RemoveCacheListener(listen, "test");
            CacheEventFilter likeFilter = new CacheEventFilter(
                new LikeFilter(IdentityExtractor.Instance, "%ic", '\\', false));

            cache.AddCacheListener(listen, likeFilter, false);

            listen.CacheEvent = null;
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("key1", "Ratko");
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("key2", "PerIc");
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("key3", "RatkoviC");
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("key4", "Perovic");
            Assert.IsNotNull(listen.CacheEvent);
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Inserted);

            cache.RemoveCacheListener(listen);

            cache.Clear();
            cache.AddCacheListener(listen);

            listen.CacheEvent = null;
            Assert.IsNull(listen.CacheEvent);

            cache.Insert("key1", "Ratko");
            Assert.IsNotNull(listen.CacheEvent);
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Inserted);
            cache.Insert("key1", "Ratko NEW");
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Updated);

            cache.Insert("key2", "Pera");
            Assert.IsNotNull(listen.CacheEvent);
            Assert.AreEqual(listen.CacheEvent.EventType, CacheEventType.Inserted);

            cache.RemoveCacheListener(listen);

            CacheFactory.Shutdown();
        }
コード例 #18
0
        /// <summary>
        /// Configure the CacheFactory.
        /// </summary>
        /// <param name="factory">
        /// The rquired singleton <see cref="IConfigurableCacheFactory"/>.
        /// </param>
        /// <param name="ctx">
        /// An optional <see cref="IOperationalContext"/> that contains
        /// operational configuration information.
        /// </param>
        /// <since>Coherence 3.7</since>
        public static void Configure(IConfigurableCacheFactory factory,
                                     IOperationalContext ctx)
        {
            // validate input parameters
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            lock (typeof(CacheFactory))
            {
                IConfigurableCacheFactory factoryOld = s_factory;
                if (factoryOld != null)
                {
                    // shutdown the old factory
                    factoryOld.Shutdown();
                }

                Logger logger = s_logger;
                if (ctx != null && logger != null)
                {
                    // switch to a new logger
                    logger.Shutdown();
                    logger = null;
                }

                if (logger == null)
                {
                    // create, configure, and start a new logger
                    if (ctx == null)
                    {
                        ctx = new DefaultOperationalContext();
                    }
                    logger = new Logger();
                    logger.Configure(ctx);
                    logger.Start();

                    // output the product startup banner
                    logger.Log((int)LogLevel.Always,
                               string.Format("\n{0} Version {1} Build {2}\n {3} Build\n{4}\n",
                                             logger.Product,
                                             logger.Version,
                                             logger.BuildInfo,
                                             logger.Edition + " " + logger.BuildType,
                                             logger.Copyright), null);

                    IList initLogMessages = s_initLogMessages;
                    lock (initLogMessages)
                    {
                        foreach (object[] logMessage in initLogMessages)
                        {
                            var message  = (string)logMessage[0];
                            var exc      = (Exception)logMessage[1];
                            var severity = (LogLevel)logMessage[2];
                            logger.Log((int)severity, exc, message, null);
                        }
                        initLogMessages.Clear();
                    }
                }

                if (factory.Config is IXmlDocument)
                {
                    IXmlDocument doc = (IXmlDocument)factory.Config;
                    doc.IterateThroughAllNodes(PreprocessProp);
                    factory.Config = doc;
                }
                else
                {
                    XmlDocument tempDoc = new XmlDocument();
                    tempDoc.LoadXml(factory.Config.GetString());
                    IXmlDocument doc = XmlHelper.ConvertDocument(tempDoc);
                    doc.IterateThroughAllNodes(PreprocessProp);
                    factory.Config = doc;
                }

                // update all singletons
                s_factory = factory;
                s_logger  = logger;
            }
        }
コード例 #19
0
        public void TestComposite()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache = CacheFactory.GetCache("local-default");

            cache.Clear();

            Address addr1 = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000");
            Address addr2 = new Address("Pere Velimirovica", "Belgrade", "Serbia", "11000");
            Address addr3 = new Address("Rige od Fere", "Belgrade", "Serbia", "11000");

            cache.Insert("addr1", addr1);
            cache.Insert("addr2", addr2);

            Assert.IsTrue(cache.Count == 2);

            LikeFilter         likeXI        = new LikeFilter(new ReflectionExtractor("Street"), "XI%", '\\', true);
            ExtractorProcessor extractStreet = new ExtractorProcessor(new ReflectionExtractor("Street"));
            IEntryProcessor    putAddr3      = new ConditionalPut(AlwaysFilter.Instance, addr3);
            IEntryProcessor    removeLikeXI  = new ConditionalRemove(likeXI, false);

            IEntryProcessor[]  processors = new IEntryProcessor[] { extractStreet, removeLikeXI, putAddr3 };
            CompositeProcessor processor  = new CompositeProcessor(processors);

            Object objResult = cache.Invoke("addr1", processor);

            Assert.IsTrue(cache.Count == 2);
            object[] objResultArr = objResult as object[];
            Assert.IsNotNull(objResultArr);
            Assert.AreEqual(addr1.Street, objResultArr[0]);

            Address res = cache["addr1"] as Address;

            Assert.IsNotNull(res);
            Assert.AreEqual(addr3.City, res.City);
            Assert.AreEqual(addr3.State, res.State);
            Assert.AreEqual(addr3.Street, res.Street);
            Assert.AreEqual(addr3.ZIP, res.ZIP);

            res = cache["addr2"] as Address;
            Assert.IsNotNull(res);
            Assert.AreEqual(addr2.City, res.City);
            Assert.AreEqual(addr2.State, res.State);
            Assert.AreEqual(addr2.Street, res.Street);
            Assert.AreEqual(addr2.ZIP, res.ZIP);

            IDictionary dictResult = cache.InvokeAll(new ArrayList(new object[] { "addr1", "addr2" }), processor);

            Assert.IsTrue(cache.Count == 2);
            Address address = cache["addr1"] as Address;

            Assert.IsNotNull(address);
            Assert.AreEqual(addr3.Street, address.Street);
            address = cache["addr2"] as Address;
            Assert.IsNotNull(address);
            Assert.AreEqual(addr3.Street, address.Street);
            object[] objectArr = dictResult["addr1"] as object[];
            Assert.IsNotNull(objectArr);
            Assert.AreEqual(objectArr[0], addr3.Street);
            objectArr = dictResult["addr2"] as object[];
            Assert.IsNotNull(objectArr);
            Assert.AreEqual(objectArr[0], addr2.Street);

            CacheFactory.Shutdown();
        }
コード例 #20
0
        public void TestLocalNamedCacheInstancing()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache1 = ccf.EnsureCache("local-default");

            Assert.IsNotNull(cache1);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache1);
            LocalNamedCache lnc = cache1 as LocalNamedCache;

            Assert.IsNotNull(lnc);
            LocalCache lc1 = lnc.LocalCache;

            Assert.AreEqual(lc1.ExpiryDelay, LocalCache.DEFAULT_EXPIRE);
            Assert.AreEqual(lc1.FlushDelay, 0);
            Assert.AreEqual(lc1.HighUnits, LocalCache.DEFAULT_UNITS);
            Assert.AreEqual(lc1.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc1.EvictionType, LocalCache.EvictionPolicyType.Hybrid);

            INamedCache cache2 = ccf.EnsureCache("local-with-init");

            Assert.IsNotNull(cache2);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache1);
            lnc = cache2 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc2 = lnc.LocalCache;

            Assert.AreEqual(lc2.ExpiryDelay, 10);
            Assert.AreEqual(lc2.FlushDelay, 1000);
            Assert.AreEqual(lc2.HighUnits, 32000);
            Assert.AreEqual(lc2.LowUnits, 10);
            Assert.AreEqual(lc2.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc2.EvictionType, LocalCache.EvictionPolicyType.LRU);
            Assert.IsNotNull(lc2.CacheLoader);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), lc2.CacheLoader);

            INamedCache cache3 = ccf.EnsureCache("local-custom-impl");

            Assert.IsNotNull(cache3);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), cache3);

            INamedCache cache4 = ccf.EnsureCache("local-custom-impl-with-init");

            Assert.IsNotNull(cache4);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), cache4);
            TestLocalNamedCache tlnc = cache4 as TestLocalNamedCache;

            Assert.IsNotNull(tlnc);
            LocalCache lc4 = tlnc.LocalCache;

            Assert.AreEqual(lc4.ExpiryDelay, 60000);
            Assert.AreEqual(lc4.FlushDelay, 1000);
            Assert.AreEqual(lc4.HighUnits, 32000);
            Assert.AreEqual(lc4.LowUnits, 10);
            Assert.AreEqual(lc4.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc4.EvictionType, LocalCache.EvictionPolicyType.LFU);

            INamedCache cache5 = ccf.EnsureCache("local-ref");

            Assert.IsNotNull(cache5);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache5);
            lnc = cache5 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc5 = lnc.LocalCache;

            Assert.AreEqual(lc2.ExpiryDelay, lc5.ExpiryDelay);
            Assert.AreEqual(lc2.FlushDelay, lc5.FlushDelay);
            Assert.AreEqual(lc2.HighUnits, lc5.HighUnits);
            Assert.AreEqual(lc2.CalculatorType, lc5.CalculatorType);
            Assert.AreEqual(lc2.EvictionType, lc5.EvictionType);

            Assert.IsInstanceOf(typeof(DefaultConfigurableCacheFactory), ccf);
            DefaultConfigurableCacheFactory dccf = ccf as DefaultConfigurableCacheFactory;

            Assert.IsNotNull(dccf);
            DefaultConfigurableCacheFactory.CacheInfo ci = dccf.FindSchemeMapping("local-override-params");
            Assert.IsNotNull(ci);
            Assert.AreEqual(ci.CacheName, "local-override-params");
            Assert.AreEqual(ci.SchemeName, "example-local-7");
            IDictionary attrs = ci.Attributes;

            Assert.IsNotNull(attrs);
            Assert.AreEqual(attrs.Count, 1);
            Assert.IsTrue(attrs.Contains("LowUnits10"));

            INamedCache cache6 = ccf.EnsureCache("local-override-params");

            Assert.IsNotNull(cache6);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache6);
            lnc = cache6 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc6 = lnc.LocalCache;

            Assert.AreEqual(lc6.ExpiryDelay, LocalCache.DEFAULT_EXPIRE);
            Assert.AreEqual(lc6.FlushDelay, 0);
            Assert.AreEqual(lc6.HighUnits, 100);
            Assert.AreEqual(lc6.LowUnits, 10);
            Assert.AreEqual(lc6.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc6.EvictionType, LocalCache.EvictionPolicyType.LFU);

            Assert.IsNotNull(lc6.CacheLoader);
            ICacheLoader cl         = lc6.CacheLoader;
            TestLoader   testLoader = cl as TestLoader;

            Assert.IsNotNull(testLoader);
            Assert.AreEqual(testLoader.StringProperty, ci.CacheName);
            Assert.AreEqual(testLoader.IntProperty, 10);
            Assert.IsTrue(testLoader.BoolProperty);
            INamedCache c = testLoader.CacheProperty;

            Assert.IsNotNull(c);
            Assert.IsInstanceOf(typeof(LocalNamedCache), c);

            Assert.IsTrue(cache1.IsActive);
            Assert.IsTrue(cache2.IsActive);
            Assert.IsTrue(cache3.IsActive);
            Assert.IsTrue(cache4.IsActive);
            Assert.IsTrue(cache5.IsActive);
            Assert.IsTrue(cache6.IsActive);

            CacheFactory.Shutdown();

            Assert.IsFalse(cache1.IsActive);
            Assert.IsFalse(cache2.IsActive);
            Assert.IsFalse(cache3.IsActive);
            Assert.IsFalse(cache4.IsActive);
            Assert.IsFalse(cache5.IsActive);
            Assert.IsFalse(cache6.IsActive);
        }