public void TestCompositeAggregator() { IEntryAggregator agg1 = CompositeAggregator.CreateInstance( new IEntryAggregator[] { GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count()), new LongMax((IdentityExtractor.Instance)) }); ArrayList al = new ArrayList(); al.Add(new TestInvocableCacheEntry("key1", 173)); al.Add(new TestInvocableCacheEntry("key2", 173)); al.Add(new TestInvocableCacheEntry("key3", 185)); al.Add(new TestInvocableCacheEntry("key4", 164)); al.Add(new TestInvocableCacheEntry("key5", 164)); al.Add(new TestInvocableCacheEntry("key6", 164)); object result = agg1.Aggregate(al); if (result is IList) { IDictionary results = (IDictionary)((IList)result)[0]; Assert.AreEqual(results[185], 1); Assert.AreEqual(results[164], 3); Assert.AreEqual(((IList)result)[1], 185); } // aggragation on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); HashDictionary hd = new HashDictionary(); hd.Add("Key1", 435); hd.Add("Key2", 253); hd.Add("Key3", 435); hd.Add("Key4", 435); hd.Add(null, -3); cache.InsertAll(hd); IEntryAggregator aggregator = CompositeAggregator.CreateInstance( new IEntryAggregator[] { GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count()), new LongMax((IdentityExtractor.Instance)) }); result = cache.Aggregate(cache.Keys, aggregator); if (result is IList) { IDictionary results = (IDictionary)((IList)result)[0]; Assert.AreEqual(results[435], 3); Assert.AreEqual(results[-3], 1); Assert.AreEqual(((IList)result)[1], 435); } CacheFactory.Shutdown(); }
public void TestGroupAggregator() { GroupAggregator agg1 = GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count()); Assert.IsNotNull(agg1); Assert.AreSame(IdentityExtractor.Instance, agg1.Extractor); Assert.IsInstanceOf(typeof(Count), agg1.Aggregator); GroupAggregator agg2 = GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count(), new LessFilter( IdentityExtractor.Instance, 3)); Assert.IsNotNull(agg2); Assert.IsInstanceOf(typeof(IdentityExtractor), agg2.Extractor); GroupAggregator agg3 = GroupAggregator.CreateInstance("dummy", new Count()); Assert.IsNotNull(agg3); Assert.IsInstanceOf(typeof(ReflectionExtractor), agg3.Extractor); agg3 = GroupAggregator.CreateInstance("dummy.test", new Count()); Assert.IsNotNull(agg3); Assert.IsInstanceOf(typeof(ChainedExtractor), agg3.Extractor); agg3 = GroupAggregator.CreateInstance("dummy.test1, dummy.test2", new Count()); Assert.IsNotNull(agg3); Assert.IsInstanceOf(typeof(MultiExtractor), agg3.Extractor); ArrayList al = new ArrayList(); al.Add(new TestInvocableCacheEntry("key1", 173)); al.Add(new TestInvocableCacheEntry("key2", 173)); al.Add(new TestInvocableCacheEntry("key3", 185)); al.Add(new TestInvocableCacheEntry("key4", 164)); al.Add(new TestInvocableCacheEntry("key5", 164)); al.Add(new TestInvocableCacheEntry("key6", 164)); object result = agg2.Aggregate(al); if (result is IDictionary) { Assert.AreEqual(((IDictionary)result)[173], 2); Assert.AreEqual(((IDictionary)result)[185], 1); Assert.AreEqual(((IDictionary)result)[164], null); } // aggragation on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); ht.Add("Key1", 435); ht.Add("Key2", 253); ht.Add("Key3", 435); ht.Add("Key4", 435); ht.Add("Key5", -3); cache.InsertAll(ht); IEntryAggregator aggregator = GroupAggregator.CreateInstance(IdentityExtractor.Instance, new Count()); result = cache.Aggregate(cache.Keys, aggregator); if (result is IDictionary) { Assert.AreEqual(((IDictionary)result)[435], 3); Assert.AreEqual(((IDictionary)result)[-3], 1); } CacheFactory.Shutdown(); }