Ejemplo 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>UpdaterProcessor</b> with another object to
 /// determine equality.
 /// </summary>
 /// <param name="o">
 /// The object to compare with.
 /// </param>
 /// <returns>
 /// <b>true</b> iff this <b>UpdaterProcessor</b> and the passed object
 /// are equivalent <b>UpdaterProcessor</b>.
 /// </returns>
 public override bool Equals(object o)
 {
     if (o is UpdaterProcessor)
     {
         UpdaterProcessor that = (UpdaterProcessor)o;
         return(Equals(m_updater, that.m_updater) &&
                Equals(m_value, that.m_value));
     }
     return(false);
 }
Ejemplo n.º 3
0
        public void TestUpdaterProcessor()
        {
            Temperature     belgrade   = new Temperature(25, 'c', 1);
            IValueUpdater   updater    = new ReflectionUpdater("Value");
            IEntryProcessor processor  = new UpdaterProcessor(updater, 0);
            IEntryProcessor processor1 = new UpdaterProcessor(updater, 0);

            Assert.AreEqual(processor, processor1);
            Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode());
            Assert.AreEqual(processor.ToString(), processor1.ToString());

            LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "belgrade", belgrade);
            processor.Process(entry);
            Assert.AreEqual(0, ((Temperature)entry.Value).Value);

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

            cache.Clear();

            Temperature bgd = new Temperature(25, 'c', 12);
            Temperature nyc = new Temperature(99, 'f', 12);

            cache.Insert("BGD", bgd);
            cache.Insert("NYC", nyc);

            updater   = new ReflectionUpdater("setValue");
            processor = new UpdaterProcessor(updater, 0);
            object newTemp = cache.Invoke("BGD", processor);

            Temperature newBGD = (Temperature)cache["BGD"];

            Assert.AreEqual(0, newBGD.Value);

            updater = new ReflectionUpdater("setValue");
            IValueUpdater compositeupdater = new CompositeUpdater(IdentityExtractor.Instance, updater);

            processor = new UpdaterProcessor(compositeupdater, 5);
            cache.Invoke("NYC", processor);
            Temperature newNYC = (Temperature)cache["NYC"];

            Assert.AreEqual(5, newNYC.Value);

            CacheFactory.Shutdown();
        }