Exemplo n.º 1
0
        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();
        }
 /// <summary>
 /// Compare the <b>ConditionalPut</b> with another object to
 /// determine equality.
 /// </summary>
 /// <param name="o">
 /// The object to compare with.
 /// </param>
 /// <returns>
 /// <b>true</b> iff this <b>ConditionalPut</b> and the passed object
 /// are equivalent <b>ConditionalPut</b>.
 /// </returns>
 public override bool Equals(object o)
 {
     if (o is ConditionalPut)
     {
         ConditionalPut that = (ConditionalPut)o;
         return(Equals(m_filter, that.m_filter) &&
                Equals(m_value, that.m_value) &&
                m_return == that.m_return);
     }
     return(false);
 }
Exemplo n.º 3
0
        public void TestConditionalPut()
        {
            ConditionalPut       conditionalPut  = new ConditionalPut(AlwaysFilter.Instance, 1500);
            ConditionalPut       conditionalPut1 = new ConditionalPut(AlwaysFilter.Instance, 1500);
            IInvocableCacheEntry entry           = new LocalCache.Entry(new LocalCache(), "key1", 1200);
            Object result = conditionalPut.Process(entry);

            Assert.AreEqual(1500, entry.Value);

            ConditionalPut conditionalPut2 = new ConditionalPut(new GreaterFilter(IdentityExtractor.Instance, 100), 100);

            entry  = new LocalCache.Entry(new LocalCache(), "key1", 1200);
            result = conditionalPut2.Process(entry);
            Assert.AreEqual(100, entry.Value);

            entry  = new LocalCache.Entry(new LocalCache(), "key1", 80);
            result = conditionalPut2.Process(entry);
            Assert.AreEqual(80, entry.Value);

            Assert.AreEqual(conditionalPut, conditionalPut1);
            Assert.AreEqual(conditionalPut.ToString(), conditionalPut1.ToString());
            Assert.AreEqual(conditionalPut.GetHashCode(), conditionalPut1.GetHashCode());

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

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("conditionalPutKey1", 435);
            ht.Add("conditionalPutKey2", 253);
            ht.Add("conditionalPutKey3", 3);
            ht.Add("conditionalPutKey4", 200);
            ht.Add("conditionalPutKey5", 333);
            cache.InsertAll(ht);

            IFilter greaterThen600 = new GreaterFilter(IdentityExtractor.Instance, 600);
            IFilter greaterThen200 = new GreaterFilter(IdentityExtractor.Instance, 200);

            // no entries with value>600
            ICollection keys = cache.GetKeys(greaterThen600);

            Assert.IsTrue(keys.Count == 0);

            // invoke processor for one entry with filter that will evaluate to false
            // again, no entries with value>600
            IEntryProcessor processor = new ConditionalPut(greaterThen600, 666);

            cache.Invoke("conditionalPutKey1", processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.IsTrue(keys.Count == 0);

            // invoke processor for one entry with filter that will evaluate to true
            // this will change one entry
            processor = new ConditionalPut(AlwaysFilter.Instance, 666);
            cache.Invoke("conditionalPutKey1", processor);
            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 1);
            Assert.AreEqual(cache["conditionalPutKey1"], 666);

            // 3 entries with value>200
            keys = cache.GetKeys(greaterThen200);
            Assert.AreEqual(keys.Count, 3);

            // invoke processor for these three entries
            processor = new ConditionalPut(greaterThen200, 666);
            IDictionary results = cache.InvokeAll(cache.Keys, processor);

            keys = cache.GetKeys(greaterThen600);
            Assert.AreEqual(keys.Count, 3);

            CacheFactory.Shutdown();
        }
Exemplo n.º 4
0
        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();
        }