public void TestDoubleAverageAggregator()
        {
            DoubleAverage agg1 = new DoubleAverage(IdentityExtractor.Instance);

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

            DoubleAverage agg2 = new DoubleAverage("dummy");

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

            DoubleAverage agg3 = new DoubleAverage("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((173.6 + 173.22 + 185.1 + 164.08) / 4, agg1.Aggregate(al));

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

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("doubleAvgKey1", 100);
            ht.Add("doubleAvgKey2", 80.5);
            ht.Add("doubleAvgKey3", 19.5);
            ht.Add("doubleAvgKey4", 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 filter = new AlwaysFilter();

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

            CacheFactory.Shutdown();
        }
        public void TestComparableMaxAggregator()
        {
            ComparableMax agg1 = new ComparableMax(IdentityExtractor.Instance);

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

            ComparableMax agg2 = new ComparableMax("dummy");

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

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

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

            ArrayList al = new ArrayList();

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

            string[] array = new string[] { "Ana", "Ivan", "Goran" };
            Assert.AreEqual("Ivan", agg1.AggregateResults(array));

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

            cache.Clear();

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

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

            Assert.AreEqual(max, 435);

            IFilter filter = new AlwaysFilter();

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

            CacheFactory.Shutdown();
        }
        public void TestDecimalMinAggregator()
        {
            DecimalMin agg1 = new DecimalMin(IdentityExtractor.Instance);

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

            DecimalMin agg2 = new DecimalMin("dummy");

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

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

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

            ArrayList al = new ArrayList();

            al.Add(new TestInvocableCacheEntry("Ivan", -173.6M));
            al.Add(new TestInvocableCacheEntry("Goran", 185.1M));
            al.Add(new TestInvocableCacheEntry("Ana", 1643426876432.08M));
            Assert.AreEqual(-173.6M, agg1.Aggregate(al));

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

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("key1", 100M);
            ht.Add("key2", 80.523423423423M);
            ht.Add("key3", 4643321321426876432.08M);
            ht.Add("key4", 1643426876432.08M);
            ht.Add("key5", 1011M);
            cache.InsertAll(ht);

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

            Assert.AreEqual(80.523423423423M, result);

            cache.Insert("key10", -10.23896128635231234M);
            IFilter filter = new AlwaysFilter();

            result = cache.Aggregate(filter, aggregator);
            Assert.AreEqual(-10.23896128635231234M, result);

            CacheFactory.Shutdown();
        }
        public void TestDecimalSumAggregator()
        {
            DecimalSum agg1 = new DecimalSum(IdentityExtractor.Instance);

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

            DecimalSum agg2 = new DecimalSum("dummy");

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

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

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

            ArrayList al = new ArrayList();

            al.Add(new TestInvocableCacheEntry("Ivan", 132131273.643M));
            al.Add(new TestInvocableCacheEntry("Goran", -0.43432M));
            al.Add(new TestInvocableCacheEntry("Ana", 0M));
            Assert.AreEqual((132131273.643M + -0.43432M + 0M), agg1.Aggregate(al));

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

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("key1", 100M);
            ht.Add("key2", 80.5M);
            ht.Add("key3", 19.589328917623187963289176M);
            ht.Add("key4", 1M);

            cache.InsertAll(ht);

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

            Assert.AreEqual((100M + 80.5M + 19.589328917623187963289176M + 1M), result);

            IFilter filter = new AlwaysFilter();

            result = cache.Aggregate(filter, aggregator);
            Assert.AreEqual((100M + 80.5M + 19.589328917623187963289176M + 1M), result);

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