/// <summary> /// Compare the <b>PropertyProcessor</b> with another object to /// determine equality. /// </summary> /// <param name="o"> /// The object to compare with. /// </param> /// <returns> /// <b>true</b> iff this <b>PropertyProcessor</b> and the passed object /// are equivalent <b>PropertyProcessor</b>. /// </returns> public override bool Equals(object o) { if (o is ExtractorProcessor) { ExtractorProcessor that = (ExtractorProcessor)o; return(Equals(m_extractor, that.m_extractor)); } return(false); }
public void TestProcessorSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); CompositeProcessor compositeProcessor = new CompositeProcessor(); ConditionalProcessor conditionalProcessor = new ConditionalProcessor(); ConditionalPut conditionalPut = new ConditionalPut(AlwaysFilter.Instance, 1); ConditionalPutAll conditionalPutAll = new ConditionalPutAll(AlwaysFilter.Instance, new Hashtable()); ConditionalRemove conditionalRemove = new ConditionalRemove(AlwaysFilter.Instance, true); ExtractorProcessor extractorProcessor = new ExtractorProcessor("member1"); NumberIncrementor numberIncrementor = new NumberIncrementor("name1", 5, true); NumberMultiplier numberMultiplier = new NumberMultiplier("name2", 10, false); PreloadRequest preloadRequest = new PreloadRequest(); PriorityProcessor priorityProcessor = new PriorityProcessor(); PropertyManipulator propertyManipulator = new PropertyManipulator("name3"); UpdaterProcessor updaterProcessor = new UpdaterProcessor("member2", 20); VersionedPut versionedPut = new VersionedPut(); VersionedPutAll versionedPutAll = new VersionedPutAll(new Hashtable()); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), compositeProcessor); ctx.Serialize(new DataWriter(stream), conditionalProcessor); ctx.Serialize(new DataWriter(stream), conditionalPut); ctx.Serialize(new DataWriter(stream), conditionalPutAll); ctx.Serialize(new DataWriter(stream), conditionalRemove); ctx.Serialize(new DataWriter(stream), extractorProcessor); ctx.Serialize(new DataWriter(stream), numberIncrementor); ctx.Serialize(new DataWriter(stream), numberMultiplier); ctx.Serialize(new DataWriter(stream), preloadRequest); ctx.Serialize(new DataWriter(stream), priorityProcessor); ctx.Serialize(new DataWriter(stream), propertyManipulator); ctx.Serialize(new DataWriter(stream), updaterProcessor); ctx.Serialize(new DataWriter(stream), versionedPut); ctx.Serialize(new DataWriter(stream), versionedPutAll); stream.Position = 0; Assert.AreEqual(compositeProcessor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(conditionalProcessor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(conditionalPut, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(conditionalPutAll.GetType(), ctx.Deserialize(new DataReader(stream)).GetType()); Assert.AreEqual(conditionalRemove, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(extractorProcessor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(numberIncrementor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(numberMultiplier, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(preloadRequest, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(priorityProcessor.GetType(), ctx.Deserialize(new DataReader(stream)).GetType()); Assert.AreEqual(propertyManipulator, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(updaterProcessor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(versionedPut, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(versionedPutAll.GetType(), ctx.Deserialize(new DataReader(stream)).GetType()); stream.Close(); }
public void TestExtractor() { Address addr = new Address("Champs-Elysees", "Paris", "France", "1616"); ExtractorProcessor extractorProcessor = new ExtractorProcessor(new ReflectionExtractor("Street")); ExtractorProcessor extractorProcessor1 = new ExtractorProcessor(new ReflectionExtractor("Street")); Assert.AreEqual(extractorProcessor, extractorProcessor1); Assert.AreEqual(extractorProcessor.GetHashCode(), extractorProcessor1.GetHashCode()); Assert.AreEqual(extractorProcessor.ToString(), extractorProcessor1.ToString()); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "addr1", addr); Object result = extractorProcessor.Process(entry); Assert.AreEqual("Champs-Elysees", result); extractorProcessor = new ExtractorProcessor(new KeyExtractor(IdentityExtractor.Instance)); result = extractorProcessor.Process(entry); Assert.AreEqual("addr1", result); // testing on Remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); ExtractorProcessor processor = new ExtractorProcessor(new ReflectionExtractor("getStreet")); Address addr1 = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000"); Address addr2 = new Address("Pere Velimirovica", "Uzice", "Serbia", "11000"); Address addr3 = new Address("Rige od Fere", "Novi Sad", "Serbia", "11000"); cache.Insert("addr1", addr1); cache.Insert("addr2", addr2); cache.Insert("addr3", addr3); Assert.IsTrue(cache.Count == 3); result = cache.Invoke("addr1", processor); Assert.IsNotNull(result); Assert.AreEqual(addr1.Street, result as String); processor = new ExtractorProcessor(new ReflectionExtractor("getCity")); IDictionary dictResult = cache.InvokeAll(cache.Keys, processor); Assert.AreEqual(addr1.City, dictResult["addr1"]); Assert.AreEqual(addr2.City, dictResult["addr2"]); Assert.AreEqual(addr3.City, dictResult["addr3"]); CacheFactory.Shutdown(); }
public void TestComposite() { Address addr1 = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000"); Address addr2 = new Address("Pere Velimirovica", "Belgrade", "Serbia", "11000"); Address addr3 = new Address("Rige od Fere", "Belgrade", "Serbia", "11000"); Address addrNEW = new Address("NEW Pere", "NEW Belgrade", "Serbia", "11000"); IEntryProcessor putLikeXI = new ConditionalPut(new LikeFilter(new ReflectionExtractor("Street"), "XI%", '\\', true), addr2); IEntryProcessor putLikeRig = new ConditionalPut(new LikeFilter(new ReflectionExtractor("Street"), "Rige%", '\\', true), addrNEW); IEntryProcessor[] processors = new IEntryProcessor[] { putLikeXI, putLikeRig }; CompositeProcessor processor = new CompositeProcessor(processors); CompositeProcessor processor1 = new CompositeProcessor(processors); Assert.AreEqual(processor, processor1); Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode()); Assert.AreEqual(processor.ToString(), processor1.ToString()); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "addr1", addr1); processor.Process(entry); Assert.AreEqual(addr2, entry.Value); entry = new LocalCache.Entry(new LocalCache(), "addr2", addr2); processor.Process(entry); Assert.AreEqual(addr2, entry.Value); entry = new LocalCache.Entry(new LocalCache(), "addr3", addr3); processor.Process(entry); Assert.AreEqual(addrNEW, entry.Value); // testing on Remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); cache.Insert("addr1", addr1); cache.Insert("addr2", addr2); Assert.IsTrue(cache.Count == 2); LikeFilter likeXI = new LikeFilter(new ReflectionExtractor("getStreet"), "XI%", '\\', true); ExtractorProcessor extractStreet = new ExtractorProcessor(new ReflectionExtractor("getStreet")); IEntryProcessor putAddr3 = new ConditionalPut(AlwaysFilter.Instance, addr3); IEntryProcessor removeLikeXI = new ConditionalRemove(likeXI, false); processors = new IEntryProcessor[] { extractStreet, removeLikeXI, putAddr3 }; processor = new CompositeProcessor(processors); Object objResult = cache.Invoke("addr1", processor); Assert.IsTrue(cache.Count == 2); Assert.AreEqual(addr1.Street, (objResult as Object[])[0]); Address res = cache["addr1"] as Address; Assert.AreEqual(addr3.City, res.City); Assert.AreEqual(addr3.State, res.State); Assert.AreEqual(addr3.Street, res.Street); Assert.AreEqual(addr3.ZIP, res.ZIP); res = cache["addr2"] as Address; Assert.AreEqual(addr2.City, res.City); Assert.AreEqual(addr2.State, res.State); Assert.AreEqual(addr2.Street, res.Street); Assert.AreEqual(addr2.ZIP, res.ZIP); IDictionary dictResult = cache.InvokeAll(new ArrayList(new object[] { "addr1", "addr2" }), processor); Assert.IsTrue(cache.Count == 2); Assert.AreEqual(addr3.Street, (cache["addr1"] as Address).Street); Assert.AreEqual(addr3.Street, (cache["addr2"] as Address).Street); Assert.AreEqual((dictResult["addr1"] as object[])[0], addr3.Street); Assert.AreEqual((dictResult["addr2"] as object[])[0], addr2.Street); CacheFactory.Shutdown(); }