/// <summary> /// For every key-value pair input, Map method is executed, to get a more specific and meaningful data. /// </summary> /// <param name="key">Key value of cache Entry.</param> /// <param name="value">Value for the key</param> /// <param name="context">Emitted output value for each key-value pair</param> public void Map(object key, object value, IOutputMap context) { if (value != null) { context.Emit(_aggKey, _valueExtractor.Extract(value)); } }
public void TestNullValueExtractor() { IValueExtractor nullValueExtractor = NullImplementation.GetValueExtractor(); Assert.IsNotNull(nullValueExtractor); Assert.IsInstanceOf(typeof(NullImplementation.NullValueExtractor), nullValueExtractor); object o = new object(); object o1 = nullValueExtractor.Extract(o); Assert.AreEqual(o, o1); }
/// <summary> /// Transform the specified <b>CacheEventArgs</b> using the /// corresponding extractors. /// </summary> /// <param name="eventArgs"> /// <b>CacheEventArgs</b> object to transform. /// </param> /// <returns> /// A modified <b>CacheEventArgs</b> object that contains extracted /// values. /// </returns> public virtual CacheEventArgs Transform(CacheEventArgs eventArgs) { IValueExtractor extractorOld = OldValueExtractor; IValueExtractor extractorNew = NewValueExtractor; return(new CacheEventArgs(eventArgs.Cache, eventArgs.EventType, eventArgs.Key, extractorOld == null ? null : extractorOld.Extract(eventArgs.OldValue), extractorNew == null ? null : extractorNew.Extract(eventArgs.NewValue), eventArgs.IsSynthetic)); }
public void TestIdentityExtractor() { IValueExtractor extractor = IdentityExtractor.Instance; IValueExtractor extractor1 = IdentityExtractor.Instance; Assert.IsNotNull(extractor); Assert.AreEqual(extractor, extractor1); Assert.AreEqual(extractor.ToString(), extractor1.ToString()); Assert.AreEqual(extractor.GetHashCode(), extractor1.GetHashCode()); object o = new DictionaryEntry("key", "value"); object o1 = extractor.Extract(o); Assert.AreEqual(o, o1); IdentityExtractor ie = extractor as IdentityExtractor; Assert.AreEqual(ie.Compare("ana", "cikic"), -1); TestQueryCacheEntry entry1 = new TestQueryCacheEntry("1", 1); TestQueryCacheEntry entry2 = new TestQueryCacheEntry("2", 2); Assert.AreEqual(ie.CompareEntries(entry2, entry1), 1); //testing on remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Hashtable ht = new Hashtable(); ht.Add("identityExtractorKey1", 435); ht.Add("identityExtractorKey2", 253); ht.Add("identityExtractorKey3", 3); ht.Add("identityExtractorKey4", null); ht.Add("identityExtractorKey5", -3); cache.InsertAll(ht); IFilter filter = new EqualsFilter(extractor, 253); ICollection keys = cache.GetKeys(filter); Assert.Contains("identityExtractorKey2", (IList)keys); Assert.AreEqual(keys.Count, 1); CacheFactory.Shutdown(); }
/// <summary> /// Extract a value from the "original value" of the specified entry /// using the specified extractor. /// </summary> /// <param name="extractor"> /// The extractor to use. /// </param> /// <param name="entry"> /// The entry to extract from. /// </param> /// <returns> /// The extracted original value. /// </returns> /// <since>Coherence 3.7</since> public static object ExtractOriginalFromEntry(IValueExtractor extractor, CacheEntry entry) { return(extractor is AbstractExtractor ? ((AbstractExtractor)extractor).ExtractOriginalFromEntry(entry) : extractor.Extract(entry.OriginalValue)); }