public void TestTransform() { ExtractorEventTransformer transformer = new ExtractorEventTransformer(null, IdentityExtractor.Instance); LocalCache cache = new LocalCache(); CacheEventArgs evt = new CacheEventArgs(cache, CacheEventType.Inserted, "inserted", "old value", "new value", false); CacheEventArgs evtNew = transformer.Transform(evt); Assert.IsNotNull(evtNew); Assert.AreEqual(evt.Cache, evtNew.Cache); Assert.AreEqual(evt.EventType, evtNew.EventType); Assert.AreEqual(evt.Key, evtNew.Key); Assert.AreNotEqual(evt.OldValue, evtNew.OldValue); Assert.IsNotNull(evt.OldValue); Assert.IsNull(evtNew.OldValue); Assert.AreEqual(evt.NewValue, evtNew.NewValue); Assert.AreEqual(evt.IsSynthetic, evtNew.IsSynthetic); evt = ConverterCollections.GetCacheEventArgs(cache, evt, NullImplementation.GetConverter(), NullImplementation.GetConverter()); Assert.IsNotNull(evt); Assert.IsInstanceOf(typeof(ConverterCollections.ConverterCacheEventArgs), evt); ConverterCollections.ConverterCacheEventArgs convEvt = evt as ConverterCollections.ConverterCacheEventArgs; Assert.IsNotNull(convEvt); evtNew = transformer.Transform(convEvt); Assert.IsNotNull(evtNew); }
/// <summary> /// Invoke the passed <see cref="IEntryProcessor"/> against the /// entries specified by the passed cache and entries. /// </summary> /// <remarks> /// The invocation is made thread safe by locking the corresponding /// keys on the cache. If an attempt to lock all the entries at once /// fails, they will be processed individually one-by-one. /// </remarks> /// <param name="cache"> /// The <see cref="IConcurrentCache"/> that the /// <b>IEntryProcessor</b> works against. /// </param> /// <param name="entries"> /// A collection of <see cref="IInvocableCacheEntry"/> objects to /// process. /// </param> /// <param name="agent"> /// The <b>IEntryProcessor</b> to use to process the specified keys. /// </param> /// <returns> /// An <b>IDictionary</b> containing the results of invoking the /// <b>IEntryProcessor</b> against each of the specified entry. /// </returns> public static IDictionary InvokeAllLocked(IConcurrentCache cache, ICollection entries, IEntryProcessor agent) { ICollection keys = ConverterCollections.GetCollection(entries, ENTRY_TO_KEY_CONVERTER, NullImplementation.GetConverter()); // try to lock them all at once var listLocked = LockAll(cache, keys, 0); if (listLocked == null) { // the attempt failed; do it one-by-one var result = new HashDictionary(entries.Count); foreach (IInvocableCacheEntry entry in entries) { result[entry.Key] = InvokeLocked(cache, entry, agent); } return(result); } try { return(agent.ProcessAll(entries)); } finally { UnlockAll(cache, listLocked); } }