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 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(); }
public void TestNumberMultiplierWithException1() { PropertyManipulator valueManipulator = new PropertyManipulator("Value"); IEntryProcessor processor = new NumberMultiplier(valueManipulator, "badnumber", true); }
public void TestNumberMultiplierWithException() { NumberMultiplier multiplier = new NumberMultiplier("Value", "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); }