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 ConverterInvocableCacheTests()
        {
            IInvocableCache cache     = InstantiateCache();
            IConverter      cDown     = new ConvertDown();
            IConverter      cUp       = new ConvertUp();
            IEntryProcessor processor = new ConditionalPut(AlwaysFilter.Instance, "value_converted", false);

            IInvocableCache convCache = ConverterCollections.GetInvocableCache(cache, cUp, cDown, cUp, cDown);

            Assert.IsNotNull(convCache);
            Assert.AreEqual(cache.Count, 0);
            convCache.Invoke("key", processor);
            Assert.AreEqual(cache.Count, 1);
            Assert.AreEqual(convCache["key"], cUp.Convert("value_converted"));

            ArrayList keys = new ArrayList();

            keys.Add("key");
            keys.Add("anotherkey");
            processor = new ConditionalPut(AlwaysFilter.Instance, "newvalue_converted", false);
            IDictionary result = convCache.InvokeAll(keys, processor);

            //results should be empty since return is set to false
            Assert.AreEqual(result.Count, 0);
            Assert.AreEqual(convCache.Count, 2);
            foreach (object key in result.Keys)
            {
                Assert.IsTrue(convCache.Contains(key));
                Assert.AreEqual(convCache[key], cUp.Convert("newvalue_converted"));
            }

            processor = new ConditionalPut(AlwaysFilter.Instance, "value_converted", false);
            result    = convCache.InvokeAll(AlwaysFilter.Instance, processor);
            //results should be empty since return is set to false
            Assert.AreEqual(result.Count, 0);
            Assert.AreEqual(convCache.Count, 2);
            foreach (object key in result.Keys)
            {
                Assert.IsTrue(convCache.Contains(key));
                Assert.AreEqual(convCache[key], cUp.Convert("value_converted"));
            }

            convCache.Clear();
            for (int i = 0; i < 5; i++)
            {
                convCache.Add(i, i + 1);
            }

            IEntryAggregator aggregator = new ComparableMax(IdentityExtractor.Instance);

            keys.Clear();
            keys.Add("2");
            keys.Add("3");
            object o = convCache.Aggregate(keys, aggregator);

            Assert.IsNotNull(o);
            Assert.AreEqual(o, "4");

            o = convCache.Aggregate(AlwaysFilter.Instance, aggregator);
            Assert.IsNotNull(o);
            Assert.AreEqual(o, "5");

            Assert.IsInstanceOf(typeof(ConverterCollections.ConverterInvocableCache), convCache);
            ConverterCollections.ConverterInvocableCache cc =
                convCache as ConverterCollections.ConverterInvocableCache;
            Assert.IsNotNull(cc);
            Assert.AreEqual(cc.InvocableCache, cache);
        }