Esempio 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();
        }
Esempio n. 2
0
        public void TestConditionalRemove()
        {
            ConditionalRemove conditionalRemove  = new ConditionalRemove(new GreaterFilter(IdentityExtractor.Instance, 100), true);
            ConditionalRemove conditionalRemove1 = new ConditionalRemove(new GreaterFilter(IdentityExtractor.Instance, 100), true);

            Assert.AreEqual(conditionalRemove, conditionalRemove1);
            Assert.AreEqual(conditionalRemove.ToString(), conditionalRemove1.ToString());
            Assert.AreEqual(conditionalRemove.GetHashCode(), conditionalRemove1.GetHashCode());

            IInvocableCacheEntry entry = new LocalCache.Entry(new LocalCache(), "key1", 1200);
            Object result = conditionalRemove.Process(entry);

            Assert.IsNull(entry.Value);

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

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

            cache.Clear();

            Hashtable ht = new Hashtable();

            ht.Add("conditionalPutAllKey1", 435);
            ht.Add("conditionalPutAllKey2", 253);
            ht.Add("conditionalPutAllKey3", 200);
            ht.Add("conditionalPutAllKey4", 333);
            cache.InsertAll(ht);

            IFilter greaterThen300 = new GreaterFilter(IdentityExtractor.Instance, 300);
            IFilter lessThen300    = new LessFilter(IdentityExtractor.Instance, 300);

            Assert.IsTrue(cache.Count == 4);

            // remove key1 with greaterThen300 filter applied
            ConditionalRemove processor = new ConditionalRemove(greaterThen300, false);

            cache.Invoke("conditionalPutAllKey1", processor);
            Assert.IsTrue(cache.Count == 3);

            // remove all entries that satisfy filter criteria
            processor = new ConditionalRemove(greaterThen300, false);
            cache.InvokeAll(ht.Keys, processor);
            Assert.IsTrue(cache.Count == 2);
            Assert.IsNotNull(cache["conditionalPutAllKey2"]);
            Assert.IsNotNull(cache["conditionalPutAllKey3"]);

            processor = new ConditionalRemove(lessThen300, false);
            cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 200), processor);
            Assert.IsTrue(cache.Count == 1);
            Assert.IsNotNull(cache["conditionalPutAllKey3"]);

            CacheFactory.Shutdown();
        }
Esempio n. 3
0
 /// <summary>
 /// Compare the <b>ConditionalRemove</b> with another object to
 /// determine equality.
 /// </summary>
 /// <param name="o">
 /// The object to compare with.
 /// </param>
 /// <returns>
 /// <b>true</b> iff this <b>ConditionalRemove</b> and the passed object
 /// are equivalent <b>ConditionalRemove</b>.
 /// </returns>
 public override bool Equals(object o)
 {
     if (o is ConditionalRemove)
     {
         ConditionalRemove that = (ConditionalRemove)o;
         return(Equals(m_filter, that.m_filter) &&
                m_return == that.m_return);
     }
     return(false);
 }
Esempio 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();
        }