示例#1
0
        public void TestConditionalPutAll()
        {
            Hashtable ht = new Hashtable();

            ht.Add("key1", 100);
            ht.Add("key2", 200);
            ht.Add("key3", 300);
            ConditionalPutAll conditionalPutAll  = new ConditionalPutAll(AlwaysFilter.Instance, ht);
            ConditionalPutAll conditionalPutAll1 = new ConditionalPutAll(AlwaysFilter.Instance, ht);

            Assert.AreEqual(conditionalPutAll.ToString(), conditionalPutAll1.ToString());

            LocalCache           lCache = new LocalCache();
            IInvocableCacheEntry entry  = new LocalCache.Entry(lCache, "key2", 400);
            Object result = conditionalPutAll.Process(entry);

            Assert.AreEqual(200, entry.Value);

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

            cache.Clear();

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

            Hashtable htPut = new Hashtable();

            htPut.Add("conditionalPutAllKey1", 100);
            htPut.Add("conditionalPutAllKey6", 80);
            htPut.Add("conditionalPutAllKey3", 10);

            // put key1 and compare cache value with the put one
            ConditionalPutAll processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut);

            cache.Invoke("conditionalPutAllKey1", processor);
            Assert.IsNotNull(cache["conditionalPutAllKey1"]);
            Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]);

            // put all keys from htPut and compare cache values with put ones
            cache.InvokeAll(htPut.Keys, processor);
            Assert.IsTrue(cache.Count == 5);
            Assert.AreEqual(cache["conditionalPutAllKey1"], htPut["conditionalPutAllKey1"]);
            Assert.AreEqual(cache["conditionalPutAllKey6"], htPut["conditionalPutAllKey6"]);
            Assert.AreEqual(cache["conditionalPutAllKey3"], htPut["conditionalPutAllKey3"]);

            htPut.Clear();
            htPut.Add("conditionalPutAllKey4", 355);
            processor = new ConditionalPutAll(AlwaysFilter.Instance, htPut);

            cache.InvokeAll(new GreaterFilter(IdentityExtractor.Instance, 300), processor);
            Assert.AreEqual(cache["conditionalPutAllKey4"], htPut["conditionalPutAllKey4"]);

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