예제 #1
0
        public void testIsPartial()
        {
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new GreaterFilter(extractor, 5);
            var             index     = new ConditionalIndex(filter, extractor, false, null, true);

            Assert.IsFalse(index.IsPartial);

            index.Insert(new CacheEntry("key1", 6));
            Assert.IsFalse(index.IsPartial);

            index.Insert(new CacheEntry("key2", 10));
            Assert.IsFalse(index.IsPartial);

            index.Insert(new CacheEntry("key3", 4));
            Assert.IsTrue(index.IsPartial);

            index = new ConditionalIndex(filter, extractor, false, null, true);
            Assert.IsFalse(index.IsPartial);

            index.Insert(new CacheEntry("key1", 2));
            Assert.IsTrue(index.IsPartial);

            index.Insert(new CacheEntry("key2", 6));
            Assert.IsTrue(index.IsPartial);

            index = new ConditionalIndex(filter, extractor, false, null, true);

            index.Insert(new CacheEntry("key1", 8));
            Assert.IsFalse(index.IsPartial);

            index.Update(new CacheEntry("key1", 2));
            Assert.IsTrue(index.IsPartial);
        }
        public void TestGetKeys()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            IDictionary dict = new Hashtable();

            for (int i = 1; i <= 10; i++)
            {
                dict.Add(GetKeyObject("key" + i), i);
            }
            cache.InsertAll(dict);

            IFilter filter = new GreaterFilter(IdentityExtractor.Instance, 5);

            object[] keys = cache.GetKeys(filter);
            Assert.AreEqual(keys.Length, 5);
            for (int i = 6; i <= 10; i++)
            {
                Assert.Contains(GetKeyObject("key" + i), keys);
            }

            CacheFactory.Shutdown();
        }
예제 #3
0
        public void NearCacheListenNoneInvokeTest()
        {
            LocalNamedCache localcache = new LocalNamedCache();
            INamedCache     safecache  = CacheFactory.GetCache(CacheName);
            NearCache       nearcache  = new NearCache(localcache, safecache, CompositeCacheStrategyType.ListenNone);

            nearcache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("Aleks", 1);
            ht.Add("Ana", 2);
            ht.Add("Goran", 3);
            ht.Add("Ivan", 4);
            nearcache.InsertAll(ht);

            IFilter         filter    = new GreaterFilter(IdentityExtractor.Instance, 199);
            IEntryProcessor processor = new ConditionalPut(filter, 204);

            nearcache.Invoke("Ivan", processor);
            Assert.AreEqual(4, nearcache["Ivan"]);
            Assert.AreEqual(4, nearcache.BackCache["Ivan"]);

            nearcache["Ivan"] = 200;
            nearcache.Invoke("Ivan", processor);
            Assert.AreEqual(200, nearcache["Ivan"]);
            Assert.AreEqual(204, nearcache.BackCache["Ivan"]);

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

            CacheFactory.Shutdown();
        }
예제 #4
0
        public void testGetFilter()
        {
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new GreaterFilter(extractor, 5);
            var             index     = new ConditionalIndex(filter, extractor, false, null, true);

            Assert.AreEqual(filter, index.Filter);
        }
예제 #5
0
        public void TestConditionalRemove()
        {
            ConditionalRemove conditionalRemove  = new ConditionalRemove(new GreaterFilter(IdentityExtractor.Instance, 100), true);
            ConditionalRemove conditionalRemove1 = new ConditionalRemove(new GreaterFilter(IdentityExtractor.Instance, 100), true);

            Assert.AreEqual(conditionalRemove, conditionalRemove1);
            Assert.AreEqual(conditionalRemove.ToString(), conditionalRemove1.ToString());
            Assert.AreEqual(conditionalRemove.GetHashCode(), conditionalRemove1.GetHashCode());

            IInvocableCacheEntry entry = new LocalCache.Entry(new LocalCache(), "key1", 1200);
            Object result = conditionalRemove.Process(entry);

            Assert.IsNull(entry.Value);

            entry  = new LocalCache.Entry(new LocalCache(), "key1", 50);
            result = conditionalRemove.Process(entry);
            Assert.AreEqual(50, entry.Value);

            // testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable ht = new Hashtable();

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

            IFilter greaterThen300 = new GreaterFilter(IdentityExtractor.Instance, 300);
            IFilter lessThen300    = new LessFilter(IdentityExtractor.Instance, 300);

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

            // remove key1 with greaterThen300 filter applied
            ConditionalRemove processor = new ConditionalRemove(greaterThen300, false);

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

            // remove all entries that satisfy filter criteria
            processor = new ConditionalRemove(greaterThen300, false);
            cache.InvokeAll(ht.Keys, processor);
            Assert.IsTrue(cache.Count == 2);
            Assert.IsNotNull(cache["conditionalPutAllKey2"]);
            Assert.IsNotNull(cache["conditionalPutAllKey3"]);

            processor = new ConditionalRemove(lessThen300, false);
            cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 200), processor);
            Assert.IsTrue(cache.Count == 1);
            Assert.IsNotNull(cache["conditionalPutAllKey3"]);

            CacheFactory.Shutdown();
        }
        public void TestExtract()
        {
            IValueExtractor extractor = new ReflectionExtractor("getId");
            IFilter         filter    = new GreaterFilter(extractor, 5);
            var             person    = new Person("123456789", DateTime.Now);

            var condExtractor = new ConditionalExtractor(filter, extractor, true);

            condExtractor.Extract(person);
        }
        public void TestGetEntries()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            IDictionary dict = new Hashtable();

            for (int i = 1; i <= 10; i++)
            {
                dict.Add(GetKeyObject("key" + i), i);
            }
            cache.InsertAll(dict);

            IFilter filter = new GreaterFilter(IdentityExtractor.Instance, 5);

            ICacheEntry[] entries = cache.GetEntries(filter);
            Assert.AreEqual(entries.Length, 5);
            object[] keys   = new object[5];
            object[] values = new object[5];
            for (int i = 0; i < 5; i++)
            {
                ICacheEntry entry = entries[i];
                keys[i]   = entry.Key;
                values[i] = entry.Value;
            }
            for (int i = 6; i <= 10; i++)
            {
                Assert.Contains(GetKeyObject("key" + i), keys);
                Assert.Contains(i, values);
            }

            entries = cache.GetEntries(filter, SafeComparer.Instance);
            Assert.AreEqual(entries.Length, 5);
            keys   = new object[5];
            values = new object[5];
            for (int i = 0; i < 5; i++)
            {
                ICacheEntry entry = entries[i];
                keys[i]   = entry.Key;
                values[i] = entry.Value;
            }
            for (int i = 6; i <= 10; i++)
            {
                Assert.Contains(GetKeyObject("key" + i), keys);
                Assert.Contains(i, values);
            }
            Assert.AreEqual(values[0], 6);
            Assert.AreEqual(values[1], 7);
            Assert.AreEqual(values[2], 8);
            Assert.AreEqual(values[3], 9);
            Assert.AreEqual(values[4], 10);

            CacheFactory.Shutdown();
        }
예제 #8
0
        public void testIsOrdered()
        {
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new GreaterFilter(extractor, 5);
            var             index     = new ConditionalIndex(filter, extractor, false, null, true);

            Assert.IsFalse(index.IsOrdered);

            index = new ConditionalIndex(filter, extractor, true, null, true);

            Assert.IsTrue(index.IsOrdered);
        }
        public void TestLongSumAggregator()
        {
            LongSum agg1 = new LongSum(IdentityExtractor.Instance);

            Assert.IsNotNull(agg1);
            Assert.AreSame(IdentityExtractor.Instance, agg1.Extractor);

            LongSum agg2 = new LongSum("dummy");

            Assert.IsNotNull(agg2);
            Assert.IsInstanceOf(typeof(ReflectionExtractor), agg2.Extractor);

            LongSum agg3 = new LongSum("another.dummy");

            Assert.IsNotNull(agg3);
            Assert.IsInstanceOf(typeof(ChainedExtractor), agg3.Extractor);

            ArrayList al = new ArrayList();

            al.Add(new TestInvocableCacheEntry("Ivan", 173.6));
            al.Add(new TestInvocableCacheEntry("Milica", 173.22));
            al.Add(new TestInvocableCacheEntry("Goran", 185.1));
            al.Add(new TestInvocableCacheEntry("Ana", 164.08));
            Assert.AreEqual(174 + 173 + 185 + 164, agg1.Aggregate(al));

            // aggragation on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable 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);

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

            Assert.AreEqual(201, result);

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

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

            CacheFactory.Shutdown();
        }
        public void TestRemove()
        {
            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("conditionalPutAllKey1", 435);
            ht.Add("conditionalPutAllKey2", 253);
            ht.Add("conditionalPutAllKey3", 200);
            ht.Add("conditionalPutAllKey4", 333);
            cache.InsertAll(ht);

            IFilter greaterThen300 = new GreaterFilter(IdentityExtractor.Instance, 300);
            IFilter lessThen300    = new LessFilter(IdentityExtractor.Instance, 300);
            IFilter key3           = new LikeFilter(new KeyExtractor(IdentityExtractor.Instance), "%Key3", '\\', false);

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

            // remove key1 with greaterThen300 filter applied
            ConditionalRemove processor = new ConditionalRemove(greaterThen300, false);

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

            // remove all entries that satisfy filter criteria
            processor = new ConditionalRemove(greaterThen300, false);
            cache.InvokeAll(ht.Keys, processor);
            Assert.IsTrue(cache.Count == 2);
            Assert.IsNotNull(cache["conditionalPutAllKey2"]);
            Assert.IsNotNull(cache["conditionalPutAllKey3"]);

            processor = new ConditionalRemove(lessThen300, false);
            cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 200), processor);
            Assert.IsTrue(cache.Count == 1);
            Assert.IsNotNull(cache["conditionalPutAllKey3"]);

            processor = new ConditionalRemove(key3, false);
            cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 100), processor);
            Assert.IsTrue(cache.Count == 0);

            CacheFactory.Shutdown();
        }
        public void TestCountAggregator()
        {
            Count agg1 = new Count();

            Assert.IsNotNull(agg1);

            ArrayList al = new ArrayList();

            al.Add(new TestInvocableCacheEntry("Ivan", 173));
            al.Add(new TestInvocableCacheEntry("Goran", 185));
            al.Add(new TestInvocableCacheEntry("Ana", 164));
            Assert.AreEqual(3, agg1.Aggregate(al));

            Assert.AreEqual(10, agg1.AggregateResults(new object[] { agg1.Aggregate(al), 7 }));

            // aggragation on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("countKey1", 435);
            ht.Add("countKey2", 253);
            ht.Add("countKey3", 3);
            ht.Add("countKey4", null);
            ht.Add("countKey5", -3);
            cache.InsertAll(ht);

            IEntryAggregator aggregator = new Count();
            object           count      = cache.Aggregate(cache.Keys, aggregator);

            Assert.AreEqual(ht.Count, count);

            IFilter filter = new GreaterFilter(IdentityExtractor.Instance, 100);

            count = cache.Aggregate(filter, aggregator);
            Assert.AreEqual(2, count);

            CacheFactory.Shutdown();
        }
        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();
        }
        public void TestCreateIndex()
        {
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new GreaterFilter(extractor, 5);
            IDictionary     map       = new HashDictionary();

            var condExtractor = new ConditionalExtractor(filter, extractor, true);

            var index = condExtractor.CreateIndex(false, null, map);

            Assert.IsTrue(index is ConditionalIndex);
            Assert.AreEqual(filter, ((ConditionalIndex)index).Filter);
            Assert.AreEqual(extractor, index.ValueExtractor);

            // make sure that the index map has been updated with the created
            // index
            var index2 = map[extractor] as ICacheIndex;

            Assert.IsNotNull(index2);
            Assert.AreEqual(index, index2);
        }
        public void TestDestroyIndex()
        {
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new GreaterFilter(extractor, 5);
            IDictionary     map       = new HashDictionary();

            var condExtractor = new ConditionalExtractor(filter, extractor, true);

            var index = condExtractor.CreateIndex(false, null, map);

            // make sure that the index map has been updated with the created
            // index
            var index2 = map[extractor] as ICacheIndex;

            Assert.IsNotNull(index2);
            Assert.AreEqual(index, index2);

            condExtractor.DestroyIndex(map);

            // make sure that the index has been removed from the index map
            Assert.IsNull(map[extractor]);
        }
        public void TestListeners()
        {
            INamedCache namedCache = CacheFactory.GetCache(CacheName);

            Hashtable ht = new Hashtable();

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

            IFilter greaterThan300          = new GreaterFilter(IdentityExtractor.Instance, 300);
            IFilter listenerFilter          = new CacheEventFilter(new GreaterFilter(IdentityExtractor.Instance, 350));
            ContinuousQueryCache queryCache = new ContinuousQueryCache(namedCache, greaterThan300);
            Listener             listener   = new SyncListener();

            // listener
            queryCache.AddCacheListener(listener);

            listener.CacheEvent = null;
            queryCache.Insert(GetKeyObject("Key7"), 400);
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Inserted, listener.CacheEvent.EventType);

            listener.CacheEvent = null;
            queryCache.Insert(GetKeyObject("Key7"), 350);
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Updated, listener.CacheEvent.EventType);

            listener.CacheEvent = null;
            queryCache.Remove(GetKeyObject("Key5"));
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Deleted, listener.CacheEvent.EventType);

            queryCache.RemoveCacheListener(listener);

            // listener, key, lite
            namedCache.Clear();
            namedCache.InsertAll(ht);
            queryCache.AddCacheListener(listener, GetKeyObject("Key5"), false);

            listener.CacheEvent = null;
            queryCache.Insert(GetKeyObject("Key6"), 400);
            Assert.IsNull(listener.CacheEvent);

            queryCache.Insert(GetKeyObject("Key5"), 400);
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Updated, listener.CacheEvent.EventType);

            listener.CacheEvent = null;
            queryCache.Remove(GetKeyObject("Key1"));
            Assert.IsNull(listener.CacheEvent);

            queryCache.Remove(GetKeyObject("Key5"));
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Deleted, listener.CacheEvent.EventType);

            queryCache.RemoveCacheListener(listener, GetKeyObject("Key5"));

            // listener, filter, lite
            namedCache.Clear();
            namedCache.InsertAll(ht);
            queryCache.AddCacheListener(listener, listenerFilter, false);

            listener.CacheEvent = null;
            queryCache.Insert(GetKeyObject("Key6"), 320);
            Assert.IsNull(listener.CacheEvent);

            queryCache.Insert(GetKeyObject("Key5"), 350);
            Assert.IsNull(listener.CacheEvent);

            queryCache.Insert(GetKeyObject("Key6"), 400);
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Updated, listener.CacheEvent.EventType);

            listener.CacheEvent = null;
            queryCache.Insert(GetKeyObject("Key7"), 340);
            Assert.IsNull(listener.CacheEvent);

            queryCache.Remove(GetKeyObject("Key7"));
            Assert.IsNull(listener.CacheEvent);

            queryCache.Remove(GetKeyObject("Key6"));
            Assert.IsNotNull(listener.CacheEvent);
            Assert.AreEqual(CacheEventType.Deleted, listener.CacheEvent.EventType);

            queryCache.RemoveCacheListener(listener, listenerFilter);

            // non-sync listener, filter, heavy
            // COH-2529: Filter-based cache events are reevaluated on the client unncessarily
            listener       = new Listener();
            listenerFilter = new CacheEventFilter(new EqualsFilter("getZip", "02144"));
            namedCache.Clear();
            namedCache.AddCacheListener(listener, listenerFilter, false);

            listener.CacheEvent = null;
            namedCache[GetKeyObject("Jason")] = new Address("3 TBR #8", "Somerville", "MA", "02144");
            listener.waitForEvent(5000);
            Assert.IsNotNull(listener.CacheEvent);
            Assert.IsNotNull(listener.CacheEvent.NewValue);
            Assert.AreEqual(CacheEventType.Inserted, listener.CacheEvent.EventType);

            listener.CacheEvent = null;
            listener.waitForEvent(5000);
            namedCache[GetKeyObject("Oracle")] = new Address("8 NEEP", "Burlington", "MA", "01803");
            Assert.IsNull(listener.CacheEvent);

            namedCache.RemoveCacheListener(listener, listenerFilter);

            CacheFactory.Shutdown();
        }
예제 #16
0
        public void TestConditionalPut()
        {
            ConditionalPut       conditionalPut  = new ConditionalPut(AlwaysFilter.Instance, 1500);
            ConditionalPut       conditionalPut1 = new ConditionalPut(AlwaysFilter.Instance, 1500);
            IInvocableCacheEntry entry           = new LocalCache.Entry(new LocalCache(), "key1", 1200);
            Object result = conditionalPut.Process(entry);

            Assert.AreEqual(1500, entry.Value);

            ConditionalPut conditionalPut2 = new ConditionalPut(new GreaterFilter(IdentityExtractor.Instance, 100), 100);

            entry  = new LocalCache.Entry(new LocalCache(), "key1", 1200);
            result = conditionalPut2.Process(entry);
            Assert.AreEqual(100, entry.Value);

            entry  = new LocalCache.Entry(new LocalCache(), "key1", 80);
            result = conditionalPut2.Process(entry);
            Assert.AreEqual(80, entry.Value);

            Assert.AreEqual(conditionalPut, conditionalPut1);
            Assert.AreEqual(conditionalPut.ToString(), conditionalPut1.ToString());
            Assert.AreEqual(conditionalPut.GetHashCode(), conditionalPut1.GetHashCode());

            // testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            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);
            IDictionary results = cache.InvokeAll(cache.Keys, processor);

            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 3);

            CacheFactory.Shutdown();
        }
        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();
        }
        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();
        }
        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();
        }