/// <summary> /// Compare the <b>PropertyManipulator</b> with another object to /// determine equality. /// </summary> /// <param name="o"> /// The object to compare with. /// </param> /// <returns> /// <b>true</b> iff this <b>PropertyManipulator</b> and the passed /// object are equivalent <b>PropertyManipulator</b>. /// </returns> public override bool Equals(object o) { if (o is PropertyManipulator) { PropertyManipulator that = (PropertyManipulator)o; return m_name.Equals(that.m_name) && m_useIs == that.m_useIs; } return false; }
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(); }
public void TestNumberIncrementor() { Temperature belgrade = new Temperature(25, 'c', 1); int bgdBefore = belgrade.Value; PropertyManipulator valueManipulator = new PropertyManipulator("Value"); IEntryProcessor processor = new NumberIncrementor(valueManipulator, 1, true); IEntryProcessor processor1 = new NumberIncrementor(valueManipulator, 1, true); 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(bgdBefore + 1, ((Temperature)entry.Value).Value); processor.Process(entry); Assert.AreEqual(bgdBefore + 2, ((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); PropertyManipulator manipulator = new PropertyManipulator("Value"); processor = new NumberIncrementor(manipulator, 1, true); object before = cache.Invoke("BGD", processor); Assert.AreEqual(bgd.Value, before); Temperature after = (Temperature)cache["BGD"]; Assert.AreEqual(((int)before) + 1, after.Value); processor = new NumberIncrementor(manipulator, -19, false); object newNYC = cache.Invoke("NYC", processor); Assert.AreEqual(nyc.Value - 19, newNYC); Score score = new Score(1, 1, 1, 1, 1, 1, 1, new RawInt128(new byte[] { 0 }), 1); LocalCache.Entry scoreEntry = new LocalCache.Entry(new LocalCache(), "score", score); valueManipulator = new PropertyManipulator("RawInt128Value"); processor = new NumberIncrementor(valueManipulator, 1, true); processor.Process(scoreEntry); CacheFactory.Shutdown(); }
/// <summary> /// Construct an <b>NumberIncrementor</b> processor that will /// increment a property value by a specified amount, returning /// either the old or the new value as specified. /// </summary> /// <remarks> /// The .NET type of the numInc parameter will dictate the .NET type /// of the original and the new value. /// </remarks> /// <param name="manipulator"> /// The <see cref="PropertyManipulator"/>; could be <c>null</c>. /// </param> /// <param name="numInc"> /// The object representing the magnitude and sign of the increment. /// </param> /// <param name="postIncrement"> /// Pass <b>true</b> to return the value as it was before it was /// incremented, or pass <b>false</b> to return the value as it is /// after it is incremented. /// </param> public NumberIncrementor(PropertyManipulator manipulator, object numInc, bool postIncrement) : base(manipulator) { Debug.Assert(numInc != null); if (numInc != null && !NumberUtils.IsNumber(numInc)) { throw new ArgumentException("Bad parameter format! " + numInc.GetType().Name + " is not supported type."); } m_numInc = numInc; m_postInc = postIncrement; }
public void TestNumberMultiplier() { Temperature belgrade = new Temperature(25, 'c', 1); int bgdBefore = belgrade.Value; PropertyManipulator valueManipulator = new PropertyManipulator("Value"); IEntryProcessor processor = new NumberMultiplier(valueManipulator, 2, true); IEntryProcessor processor1 = new NumberMultiplier(valueManipulator, 2, true); 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(bgdBefore * 2, ((Temperature)entry.Value).Value); 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); PropertyManipulator manipulator = new PropertyManipulator("Value"); processor = new NumberMultiplier(manipulator, 2, false); object newTemp = cache.Invoke("BGD", processor); Assert.AreEqual(bgd.Value * 2, newTemp); Temperature newBGD = (Temperature)cache["BGD"]; Assert.AreEqual(bgd.Value * 2, newBGD.Value); processor = new NumberMultiplier(manipulator, 0.5, false); object newNYC = cache.Invoke("NYC", processor); Assert.AreEqual(49, newNYC); CacheFactory.Shutdown(); }
/// <summary> /// Construct a <b>PropertyProcessor</b> based for the specified /// <see cref="PropertyManipulator"/>. /// </summary> /// <param name="manipulator"> /// A <b>PropertyManipulator</b>; could be <c>null</c>. /// </param> public PropertyProcessor(PropertyManipulator manipulator) { m_manipulator = manipulator; }
public void TestNumberMultiplierWithException1() { PropertyManipulator valueManipulator = new PropertyManipulator("Value"); IEntryProcessor processor = new NumberMultiplier(valueManipulator, "badnumber", true); }
public void TestUnitNumberMultiplier() { Score score = new Score(3, 3, 3, 3L, 3, 3, new decimal(3), new RawInt128(new byte[] { 3 }), 3); Score scoreOrig = new Score(3, 3, 3, 3L, 3, 3, new decimal(3), new RawInt128(new byte[] { 3 }), 3); PropertyManipulator byteManipulator = new PropertyManipulator("ByteValue"); PropertyManipulator shortManipulator = new PropertyManipulator("ShortValue"); PropertyManipulator intManipulator = new PropertyManipulator("IntValue"); PropertyManipulator longManipulator = new PropertyManipulator("LongValue"); PropertyManipulator floatManipulator = new PropertyManipulator("FloatValue"); PropertyManipulator doubleManipulator = new PropertyManipulator("DoubleValue"); PropertyManipulator decimalManipulator = new PropertyManipulator("DecimalValue"); PropertyManipulator int128Manipulator = new PropertyManipulator("RawInt128Value"); NumberMultiplier processorByte = new NumberMultiplier(byteManipulator, 2, true); NumberMultiplier processorByte2 = new NumberMultiplier("ByteValue", 2, false); Assert.IsTrue(processorByte.Equals(processorByte2)); NumberMultiplier processorShort = new NumberMultiplier(shortManipulator, 2, true); NumberMultiplier processorInt = new NumberMultiplier(intManipulator, 2, true); NumberMultiplier processorLong = new NumberMultiplier(longManipulator, 2, true); NumberMultiplier processorFloat = new NumberMultiplier(floatManipulator, 2, true); NumberMultiplier processorDouble = new NumberMultiplier(doubleManipulator, 2, true); NumberMultiplier processorDecimal = new NumberMultiplier(decimalManipulator, new decimal(2), true); Exception e = null; NumberMultiplier processorInt128 = null; try { processorInt128 = new NumberMultiplier(int128Manipulator, new RawInt128(new byte[] { 6 }), true); } catch (Exception ex) { e = ex; } Assert.IsNull(processorInt128); Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); processorInt128 = new NumberMultiplier(int128Manipulator, 2, true); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "score", score); object result1 = processorByte.Process(entry); Assert.IsNotNull(result1); Assert.IsInstanceOf(typeof(byte), result1); Assert.AreEqual((byte)result1, 3); result1 = processorByte2.Process(entry); Assert.IsNotNull(result1); Assert.IsInstanceOf(typeof(byte), result1); Assert.AreEqual((byte)result1, 12); processorShort.Process(entry); processorInt.Process(entry); processorLong.Process(entry); processorFloat.Process(entry); processorDouble.Process(entry); processorDecimal.Process(entry); processorInt128.Process(entry); Assert.AreEqual(scoreOrig.ByteValue * 4, ((Score)entry.Value).ByteValue); Assert.AreEqual(scoreOrig.ShortValue * 2, ((Score)entry.Value).ShortValue); Assert.AreEqual(scoreOrig.IntValue * 2, ((Score)entry.Value).IntValue); Assert.AreEqual(scoreOrig.LongValue * 2, ((Score)entry.Value).LongValue); Assert.AreEqual(scoreOrig.FloatValue * 2, ((Score)entry.Value).FloatValue); Assert.AreEqual(scoreOrig.DoubleValue * 2, ((Score)entry.Value).DoubleValue); Assert.AreEqual(scoreOrig.RawInt128Value.ToDecimal() * 2, ((Score)entry.Value).RawInt128Value.ToDecimal()); Assert.AreEqual(Decimal.Multiply(scoreOrig.DecimalValue, new Decimal(2)), ((Score)entry.Value).DecimalValue); processorShort = new NumberMultiplier(shortManipulator, 2.5, true); processorLong = new NumberMultiplier(longManipulator, 2.5, true); processorByte = new NumberMultiplier(byteManipulator, 2.5, true); processorShort.Process(entry); processorLong.Process(entry); processorByte.Process(entry); Assert.AreEqual(scoreOrig.ByteValue * 10, ((Score)entry.Value).ByteValue); Assert.AreEqual(scoreOrig.ShortValue * 5, ((Score)entry.Value).ShortValue); Assert.AreEqual(scoreOrig.LongValue * 5, ((Score)entry.Value).LongValue); }