コード例 #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();
        }
コード例 #2
0
 /// <summary>
 /// Compare the <b>VersionedPut</b> with another object to
 /// determine equality.
 /// </summary>
 /// <param name="o">
 /// The object to compare with.
 /// </param>
 /// <returns>
 /// <b>true</b> iff this <b>VersionedPut</b> and the passed object
 /// are equivalent <b>VersionedPut</b>.
 /// </returns>
 public override bool Equals(object o)
 {
     if (o is VersionedPut)
     {
         VersionedPut that = (VersionedPut)o;
         return(Equals(m_value, that.m_value) &&
                m_insert == that.m_insert &&
                m_return == that.m_return);
     }
     return(false);
 }
コード例 #3
0
        public void TestVersionPut()
        {
            Temperature temperature    = new Temperature(35, 'f', 11);
            Temperature temperatureNew = new Temperature(15, 'C', 10);

            LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "morning", temperature);
            IEntryProcessor  processorVersioned  = new VersionedPut(temperatureNew, true, true);
            IEntryProcessor  processorVersioned1 = new VersionedPut(temperatureNew, true, true);

            Assert.AreEqual(processorVersioned, processorVersioned1);
            Assert.AreEqual(processorVersioned.GetHashCode(), processorVersioned1.GetHashCode());
            Assert.AreEqual(processorVersioned.ToString(), processorVersioned1.ToString());

            Temperature res = (Temperature)processorVersioned.Process(entry);

            Assert.AreEqual(temperature, res);

            temperatureNew     = new Temperature(15, 'C', 11);
            processorVersioned = new VersionedPut(temperatureNew, true, true);
            processorVersioned.Process(entry);
            Assert.AreEqual((entry.Value as Temperature).Grade, temperatureNew.Grade);
            Assert.AreEqual((entry.Value as Temperature).Value, temperatureNew.Value);

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

            cache.Clear();

            Temperature t1 = new Temperature(3, 'c', 8);
            Temperature t2 = new Temperature(24, 'c', 12);
            Temperature t3 = new Temperature(15, 'c', 18);
            Temperature t4 = new Temperature(0, 'c', 0);

            cache.Insert("morning", t1);
            cache.Insert("noon", t2);
            cache.Insert("afternoon", t3);
            cache.Insert("midnight", t4);


            Temperature     t         = new Temperature(35, 'f', 11);
            IEntryProcessor processor = new VersionedPut(t, true, true);
            Temperature     result    = (Temperature)cache.Invoke("morning", processor);

            Assert.AreNotEqual(t.Value, result.Value);
            Assert.AreNotEqual(t.Grade, result.Grade);
            Temperature after = (Temperature)cache["morning"];

            Assert.AreNotEqual(t.Value, after.Value);
            Assert.AreNotEqual(t.Version, after.Version);
            Assert.AreNotEqual(t.Grade, after.Grade);

            t         = new Temperature(35, 'f', 8);
            processor = new VersionedPut(t, true, true);
            result    = (Temperature)cache.Invoke("morning", processor);
            Assert.IsNull(result);
            after = (Temperature)cache["morning"];
            Assert.AreEqual(t.Version + 1, after.Version);
            Assert.AreEqual(t.Value, after.Value);
            Assert.AreEqual(t.Grade, after.Grade);

            t         = new Temperature(38, 'f', 10);
            processor = new VersionedPut(t, true, true);
            result    = (Temperature)cache.Invoke("sometime", processor);
            after     = (Temperature)cache["sometime"];

            Assert.AreEqual(t.Value, after.Value);
            Assert.AreEqual(t.Grade, after.Grade);
            Assert.AreEqual(t.Version + 1, after.Version);

            cache.Remove("sometime");

            processor = new VersionedPut(t, false, true);
            result    = (Temperature)cache.Invoke("sometime", processor);
            after     = (Temperature)cache["sometime"];
            Assert.IsNull(after);

            CacheFactory.Shutdown();
        }