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(); }
public void TestUnitNumberIncrementor() { Score score = new Score(1, 1, 1, 1L, 1, 1, new decimal(1), new RawInt128(new byte[] { 1 }), 1); Score scoreOrig = new Score(1, 1, 1, 1L, 1, 1, new decimal(1), new RawInt128(new byte[] { 1 }), 1); 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"); NumberIncrementor processorByte = new NumberIncrementor(byteManipulator, 2, true); NumberIncrementor processorByte2 = new NumberIncrementor("ByteValue", 2, false); Assert.IsTrue(processorByte.Equals(processorByte2)); NumberIncrementor processorShort = new NumberIncrementor(shortManipulator, 2, true); NumberIncrementor processorInt = new NumberIncrementor(intManipulator, 2, true); NumberIncrementor processorLong = new NumberIncrementor(longManipulator, 2, true); NumberIncrementor processorFloat = new NumberIncrementor(floatManipulator, 2, true); NumberIncrementor processorDouble = new NumberIncrementor(doubleManipulator, 2, true); NumberIncrementor processorDecimal = new NumberIncrementor(decimalManipulator, new decimal(2), true); Exception e = null; NumberIncrementor processorInt128 = null; try { processorInt128 = new NumberIncrementor(int128Manipulator, new RawInt128(new byte[] { 6 }), true); } catch (Exception ex) { e = ex; } Assert.IsNull(processorInt128); Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); 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, 1); result1 = processorByte2.Process(entry); Assert.IsNotNull(result1); Assert.IsInstanceOf(typeof(byte), result1); Assert.AreEqual((byte)result1, 5); processorShort.Process(entry); processorInt.Process(entry); processorLong.Process(entry); processorFloat.Process(entry); processorDouble.Process(entry); processorDecimal.Process(entry); e = null; try { processorInt128 = new NumberIncrementor("v", null, false); Assert.IsNotNull(processorInt128); processorInt128.Process(entry); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentNullException), e); processorInt128 = new NumberIncrementor(int128Manipulator, 5, false); 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() + 5, ((Score)entry.Value).RawInt128Value.ToDecimal()); Assert.AreEqual(Decimal.Add(scoreOrig.DecimalValue, new Decimal(2)), ((Score)entry.Value).DecimalValue); }