public void TestExtractorSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); ChainedExtractor chainedExtractor = new ChainedExtractor("member1"); ComparisonValueExtractor comparisonValueExtractor = new ComparisonValueExtractor("member2", "member3"); IdentityExtractor identityExtractor = new IdentityExtractor(); KeyExtractor keyExtractor = new KeyExtractor("member4"); MultiExtractor multiExtractor = new MultiExtractor("member5,member6,member7"); ReflectionExtractor reflectionExtractor = new ReflectionExtractor("member8"); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), chainedExtractor); ctx.Serialize(new DataWriter(stream), comparisonValueExtractor); ctx.Serialize(new DataWriter(stream), identityExtractor); ctx.Serialize(new DataWriter(stream), keyExtractor); ctx.Serialize(new DataWriter(stream), multiExtractor); ctx.Serialize(new DataWriter(stream), reflectionExtractor); stream.Position = 0; Assert.AreEqual(chainedExtractor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(comparisonValueExtractor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(identityExtractor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(keyExtractor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(multiExtractor, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(reflectionExtractor, ctx.Deserialize(new DataReader(stream))); stream.Close(); }
public void TestGetUserTypeIdWithUnknownType1() { String nonExistingType = "Dummy"; ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); ctx.GetUserTypeIdentifier(nonExistingType); }
public void TestGetUserTypeIdWithUnknownType2() { Type nonExistingType = typeof(PersonLite); ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); ctx.GetUserTypeIdentifier(nonExistingType); }
public void TestCheckNotInit() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); IXmlElement config = ctx.Config; ctx.Config = config; }
/// <summary> /// Encode and write a binary representation of the given /// <b>IMessage</b> to the given <see cref="DataWriter"/>. /// </summary> /// <remarks> /// Using the passed <see cref="IChannel"/>, the Codec has access to /// both the <see cref="IMessageFactory"/> for the <b>IChannel</b> /// and the underlying <see cref="IConnection"/>. /// </remarks> /// <param name="channel"> /// The <b>IChannel</b> object through which the binary-encoded /// <b>IMessage</b> was passed. /// </param> /// <param name="message"> /// The <b>IMessage</b> to encode. /// </param> /// <param name="writer"> /// The <b>DataWriter</b> to write the binary representation of the /// <b>IMessage</b> to. /// </param> /// <exception cref="IOException"> /// If an error occurs encoding or writing the <b>IMessage</b>. /// </exception> /// <seealso cref="ICodec.Encode"/> public virtual void Encode(IChannel channel, IMessage message, DataWriter writer) { Debug.Assert(channel is IPofContext); Debug.Assert(message is IPortableObject); IPofContext context = (IPofContext)channel; PofStreamWriter pofwriter = new PofStreamWriter.UserTypeWriter(writer, context, message.TypeId, 0); ISerializer serializer = channel.Serializer; if (serializer is ConfigurablePofContext) { ConfigurablePofContext pofCtx = (ConfigurablePofContext)serializer; if (pofCtx.IsReferenceEnabled) { pofwriter.EnableReference(); } } // set the version identifier bool isEvolvable = message is IEvolvable; IEvolvable evolvable = null; if (isEvolvable) { evolvable = (IEvolvable)message; pofwriter.VersionId = Math.Max(evolvable.DataVersion, evolvable.ImplVersion); } // write the Message properties ((IPortableObject)message).WriteExternal(pofwriter); // write the future properties pofwriter.WriteRemainder(isEvolvable ? evolvable.FutureData : null); }
public void TestGetPofSerializerWithNull() { Int32 nonExistingId = 333; ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); ctx.GetPofSerializer(nonExistingId); }
public void TestLocalMemberPof() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence/Tangosol.Config/coherence-pof-config.xml"); Type type = ctx.GetType(160); Assert.AreEqual(typeof(LocalMember), type); LocalMember member = new LocalMember(); member.MachineName = "machine1"; member.MemberName = "member1"; member.ProcessName = "process1"; member.RackName = "rack1"; member.RoleName = "role1"; member.SiteName = "site1"; MemoryStream memstream = new MemoryStream(); ctx.Serialize(new DataWriter(memstream), member); memstream.Position = 0; LocalMember copy = (LocalMember)ctx.Deserialize(new DataReader(memstream)); Assert.AreEqual(member.MachineName, copy.MachineName); Assert.AreEqual(member.MemberName, copy.MemberName); Assert.AreEqual(member.ProcessName, copy.ProcessName); Assert.AreEqual(member.RackName, copy.RackName); Assert.AreEqual(member.RoleName, copy.RoleName); Assert.AreEqual(member.SiteName, copy.SiteName); }
public void TestEnableReferenceConfig() { const string path = "config/reference-pof-config.xml"; var ctx = new ConfigurablePofContext(path); IXmlElement config = ctx.Config; Assert.IsTrue(ctx.IsReferenceEnabled); }
public void TestPofAnnotationSerializer() { ConfigurablePofContext ctx = new ConfigurablePofContext("config/multiple-include-pof-config.xml"); Assert.IsInstanceOf(typeof(PortableObjectSerializer), ctx.GetPofSerializer(2000)); Assert.IsInstanceOf(typeof(PofAnnotationSerializer), ctx.GetPofSerializer(2003)); Assert.IsInstanceOf(typeof(PofAnnotationSerializer), ctx.GetPofSerializer(2004)); }
public void TestInitialize() { ConfigurablePofContext ctx1 = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); IXmlElement config1 = ctx1.Config; ConfigurablePofContext ctx2 = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); IXmlElement config2 = ctx2.Config; Assert.AreEqual(config1, config2); }
public void TestConfigPofContextAllowSubclasses() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config-allowsubclass.xml"); int typeId = ctx.GetUserTypeIdentifier(typeof(EvolvablePortablePerson)); Assert.AreEqual(ctx.GetUserTypeIdentifier(typeof(PortablePerson)), typeId); Assert.AreEqual(ctx.GetUserTypeIdentifier(typeof(PortablePerson)), ctx.GetUserTypeIdentifier(typeof(EvolvablePortablePerson))); }
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 TestGenericCollection() { MemoryStream buffer = new MemoryStream(1000); DataWriter writer = new DataWriter(buffer); DataReader reader = new DataReader(buffer); ConfigurablePofContext cpc = new ConfigurablePofContext("config/include-pof-config.xml"); GenericCollectionsType gct = new GenericCollectionsType(); cpc.Serialize(writer, gct); buffer.Position = 0; cpc.Deserialize(reader); }
public void testNestedReferences() { const String sPath = "config/reference-pof-config.xml"; m_ctx = new ConfigurablePofContext(sPath); IXmlElement config = ((ConfigurablePofContext)m_ctx).Config; var pm = new PofMaster(); var pc1 = new PofChild(); var pc2 = new PofChild(); ArrayList list1 = null; var list2 = new ArrayList(); var list3 = new ArrayList(); IDictionary map1 = null; IDictionary map2 = new Hashtable(); IDictionary map3 = map2; list3.Add(0); map3.Add("key1", pc1); map3.Add("key2", pc2); pc1.setId("child1"); pc2.setId("child2"); pm.setList1(list1); pm.setList2(list2); pm.setList3(list3); pm.setMap1(map1); pm.setMap2(map2); pm.setMap3(map3); pm.setNumber(9999); pm.setText("cross fingers"); pm.setChildren(new PofChild[] { pc1, pc2, pc2 }); initPOFWriter(); m_ctx.Serialize(m_writer, pm); initPOFReader(); var pm2 = (PofMaster)m_ctx.Deserialize(m_reader); Assert.IsTrue(pm.Equals(pm2)); IDictionary map2R = pm2.getMap2(); IDictionary map3R = pm2.getMap3(); Assert.IsTrue(map2R != map3R); Assert.IsTrue(map2R["key1"] == map3R["key1"]); Assert.IsTrue(map2R["key2"] == map3R["key2"]); PofChild[] children = pm2.getChildren(); Assert.IsTrue(children[0] == map2R["key1"]); Assert.IsTrue(children[1] == children[2]); }
public void TestConfigPofContextWithPortableObject() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.AreEqual(typeof(PortableObjectSerializer), ctx.GetPofSerializer(1201).GetType()); Type type = ctx.GetType(1201); Assert.AreEqual(typeof(Address), type); type = ctx.GetType(1005); Assert.AreEqual(typeof(PortablePerson), type); // adding tests for null implementations that are included in POF config type = ctx.GetType(10); Assert.AreEqual(typeof(NullFilter), type); type = ctx.GetType(11); Assert.AreEqual(typeof(NullImplementation.NullCollection), type); type = ctx.GetType(12); Assert.AreEqual(typeof(NullImplementation.NullObservableCache), type); type = ctx.GetType(13); Assert.AreEqual(typeof(NullImplementation.NullValueExtractor), type); IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); ctx = new ConfigurablePofContext(config); IXmlElement res = ctx.Config; Assert.AreEqual(res, config); Assert.AreEqual("Tangosol.Address", ctx.GetTypeName(1201)); Assert.AreEqual("Tangosol.PortablePerson", ctx.GetTypeName(1005)); Assert.AreEqual(1002, ctx.GetUserTypeIdentifier(typeof(PortablePersonLite))); Assert.AreEqual(1005, ctx.GetUserTypeIdentifier("Tangosol.PortablePerson, Coherence.Tests")); Address home = new Address("Palmira Toljatija 50", "Belgrade", "Serbia", "11070"); Assert.AreEqual(1201, ctx.GetUserTypeIdentifier(home)); ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config-include.xml"); Assert.AreEqual("Tangosol.Address", ctx.GetTypeName(1201)); Assert.AreEqual("Tangosol.PortablePerson", ctx.GetTypeName(1005)); Assert.AreEqual("Tangosol.SkippingPersonLite", ctx.GetTypeName(2002)); Assert.AreEqual(1002, ctx.GetUserTypeIdentifier(typeof(PortablePersonLite))); Assert.AreEqual(1005, ctx.GetUserTypeIdentifier("Tangosol.PortablePerson, Coherence.Tests")); Assert.AreEqual(2001, ctx.GetUserTypeIdentifier(typeof(BadPersonLite))); Assert.IsTrue(ctx.IsUserType("Tangosol.PortablePersonLite, Coherence.Tests")); }
public void TestSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config-include.xml"); Address home = new Address("Palmira Toljatija 50", "Belgrade", "Serbia", "11070"); MemoryStream memstream = new MemoryStream(); ctx.Serialize(new DataWriter(memstream), home); memstream.Position = 0; Address res = (Address)ctx.Deserialize(new DataReader(memstream)); Assert.AreEqual(home.Street, res.Street); Assert.AreEqual(home.State, res.State); Assert.AreEqual(home.City, res.City); Assert.AreEqual(home.ZIP, res.ZIP); }
public void TestSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); SemiLiteEventTransformer semiLiteEventTransformer = new SemiLiteEventTransformer(); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), semiLiteEventTransformer); stream.Position = 0; Assert.AreEqual(semiLiteEventTransformer, ctx.Deserialize(new DataReader(stream))); stream.Close(); }
public void TestDefaultConstructor() { ConfigurablePofContext ctx = new ConfigurablePofContext(); IPofSerializer ser = ctx.GetPofSerializer(14); Assert.AreEqual(typeof(PortableObjectSerializer), ser.GetType()); ser = ctx.GetPofSerializer(0); Assert.AreEqual(typeof(ExceptionPofSerializer), ser.GetType()); Type type = ctx.GetType(0); Assert.AreEqual(typeof(Exception), type); type = ctx.GetType(14); Assert.AreEqual(typeof(UUID), type); type = ctx.GetType(1201); Assert.AreEqual(typeof(Address), type); }
public void TestUpdaterSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); CompositeUpdater compositeUpdater = new CompositeUpdater("name"); ReflectionUpdater reflectionUpdater = new ReflectionUpdater("member"); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), compositeUpdater); ctx.Serialize(new DataWriter(stream), reflectionUpdater); stream.Position = 0; Assert.AreEqual(compositeUpdater, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(reflectionUpdater, ctx.Deserialize(new DataReader(stream))); stream.Close(); }
public void testSerialization() { String sPath = "config/reference-pof-config.xml"; var ctx = new ConfigurablePofContext(sPath); var bal = new Balance(); var p = new Product(bal); var c = new Customer("Customer", p, bal); bal.setBalance(2.0); bal.setCustomer(c); initPOFWriter(); m_pofwriter = new PofStreamWriter(m_writer, ctx); m_pofwriter.EnableReference(); m_pofwriter.WriteObject(0, c); initPOFReader(); m_pofreader = new PofStreamReader(m_reader, ctx); var cResult = (Customer)m_pofreader.ReadObject(0); Assert.IsTrue(cResult.getProduct().getBalance() == cResult.getBalance()); }
/// <summary> /// Deserialize a user type instance from a POF stream by reading its /// state using the specified <see cref="IPofReader"/> object. /// </summary> /// <remarks> /// An implementation of <b>IPofSerializer</b> is required to follow /// the following steps in sequence for reading in an object of a /// user type: /// <list type="number"> /// <item> /// <description> /// If the object is evolvable, the implementation must get the /// version by calling <see cref="IPofWriter.VersionId"/>. /// </description> /// </item> /// <item> /// <description> /// The implementation may read any combination of the /// properties of the user type by using "read" methods of the /// <b>IPofReader</b>, but it must do so in the order of the property /// indexes. /// </description> /// </item> /// <item> /// <description> /// After all desired properties of the user type have been read, /// the implementation must terminate the reading of the user type by /// calling <see cref="IPofReader.ReadRemainder"/>. /// </description> /// </item> /// </list> /// </remarks> /// <param name="reader"> /// The <b>IPofReader</b> with which to read the object's state. /// </param> /// <returns> /// The deserialized user type instance. /// </returns> /// <exception cref="IOException"> /// If an I/O error occurs. /// </exception> public Object Deserialize(IPofReader reader) { String typeName = reader.ReadString(0); Binary bin = reader.ReadBinary(1); reader.ReadRemainder(); ConfigurablePofContext ctx = m_pofContext; IPortableObject po; try { po = (IPortableObject)ObjectUtils.CreateInstance(TypeResolver.Resolve(typeName)); } catch (Exception e) { throw new Exception("Unable to instantiate PortableObject class: " + typeName, e); } DataReader dataReader = bin.GetReader(); int nType = dataReader.ReadPackedInt32(); if (nType != TYPE_PORTABLE) { throw new IOException("Invalid POF type: " + nType + " (" + TYPE_PORTABLE + " expected)"); } int iVersion = dataReader.ReadPackedInt32(); IPofReader pofReader = new PofStreamReader.UserTypeReader( dataReader, ctx, TYPE_PORTABLE, iVersion); m_serializer.Initialize(po, pofReader); Register(typeName); return(po); }
public void TestSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); SimpleDocument sd = new SimpleDocument(); sd.Name = "doc"; sd.DtdUri = "test.dtd"; sd.DtdName = "public name"; sd.Encoding = "UTF-8"; sd.DocumentComment = "comment"; Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), sd); stream.Position = 0; SimpleDocument sdd = (SimpleDocument)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sd, sdd); }
public void testSetSerializer() { IPofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); var set = new HashSet(); Assert.IsTrue(ctx.IsUserType(set)); Assert.IsTrue(ctx.IsUserType(typeof(HashSet))); Assert.IsTrue(ctx.IsUserType(typeof(HashSet).AssemblyQualifiedName)); var buffer = new MemoryStream(1024); var writer = new DataWriter(buffer); ctx.Serialize(writer, new HashSet()); var reader = new DataReader(buffer); buffer.Position = 0; object o = ctx.Deserialize(reader); Assert.IsTrue(o is HashSet); buffer.Close(); ctx = new SafeConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsTrue(ctx.IsUserType(set)); Assert.IsTrue(ctx.IsUserType(typeof(HashSet))); Assert.IsTrue(ctx.IsUserType(typeof(HashSet).AssemblyQualifiedName)); buffer = new MemoryStream(1024); writer = new DataWriter(buffer); ctx.Serialize(writer, new HashSet()); reader = new DataReader(buffer); buffer.Position = 0; o = ctx.Deserialize(reader); Assert.IsTrue(o is HashSet); buffer.Close(); }
public void TestSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); SimpleElement se = new SimpleElement("name", 5); se.Comment = "comment"; se.AddElement("child1"); se.AddElement("child2"); se.AddAttribute("attr1"); se.AddAttribute("attr2"); se.AddAttribute("attr3"); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), se); stream.Position = 0; SimpleElement sed = (SimpleElement)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(se, sed); }
public void TestMultipleIncludes() { ConfigurablePofContext ctx = new ConfigurablePofContext("config/multiple-include-pof-config.xml"); ctx.IsUserType(typeof(PortablePerson)); }
public TestPofSerializer() { ctx = new ConfigurablePofContext(); }
private void setPofContext(ConfigurablePofContext Context) { m_Context = Context; }
public void TestDuplicateObjectReferences() { // loop twice, one for SimplePofContext, one for // ConfigurablePofContext. for (int loop = 0; loop < 2; loop++) { if (loop == 0) { m_ctx = new SimplePofContext(); ((SimplePofContext)m_ctx).RegisterUserType(101, typeof(PortablePerson), new PortableObjectSerializer(101)); ((SimplePofContext)m_ctx).RegisterUserType(201, typeof(CompositeKey), new PortableObjectSerializer(201)); ((SimplePofContext)m_ctx).IsReferenceEnabled = true; } else { const String sPath = "config/reference-pof-config.xml"; m_ctx = new ConfigurablePofContext(sPath); } initPOFWriter(); var joe = new PortablePerson("Joe Smith", new DateTime(78, 4, 25)); var differentJoe = new PortablePerson("Joe Smith", new DateTime(78, 4, 25)); var key = new CompositeKey(joe, joe); Assert.IsTrue(key.PrimaryKey == key.SecondaryKey); // test a collection of duplicate object references ICollection <PortablePerson> list = new List <PortablePerson>(); list.Add(joe); list.Add(joe); list.Add(differentJoe); list.Add(differentJoe); m_pofWriter.EnableReference(); m_pofWriter.WriteObject(0, key); m_pofWriter.WriteObject(0, list); initPOFReader(); var result = (CompositeKey)m_pofReader.ReadObject(0); Assert.IsTrue(result.PrimaryKey == result.SecondaryKey); ICollection <object> result2 = new List <object>(); m_pofReader.ReadCollection(0, result2); PortablePerson person = null; int i = 0; for (IEnumerator iter = result2.GetEnumerator(); iter.MoveNext();) { var personNext = (PortablePerson)iter.Current; if (person == null) { person = personNext; i++; } else { Assert.IsTrue(person.Equals(personNext)); if (i == 1 || i == 3) { Assert.IsTrue(person == personNext); } else { person = personNext; } i++; } } } }
public TestPofSerializer(string s) { ctx = new ConfigurablePofContext(s); }
public void TestSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); bool v1 = true; SimpleValue sv1 = new SimpleValue(v1); int v2 = 5; SimpleValue sv2 = new SimpleValue(v2); long v3 = 999L; SimpleValue sv3 = new SimpleValue(v3); double v4 = 5.257; SimpleValue sv4 = new SimpleValue(v4); decimal v5 = decimal.MinusOne; SimpleValue sv5 = new SimpleValue(v5); string v6 = "test"; SimpleValue sv6 = new SimpleValue(v6); Binary v7 = new Binary(new byte[] { 99, 50, 27 }); SimpleValue sv7 = new SimpleValue(v7); DateTime v8 = new DateTime(1976, 4, 19); SimpleValue sv8 = new SimpleValue(v8); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), sv1); ctx.Serialize(new DataWriter(stream), sv2); ctx.Serialize(new DataWriter(stream), sv3); ctx.Serialize(new DataWriter(stream), sv4); ctx.Serialize(new DataWriter(stream), sv5); ctx.Serialize(new DataWriter(stream), sv6); ctx.Serialize(new DataWriter(stream), sv7); ctx.Serialize(new DataWriter(stream), sv8); stream.Position = 0; SimpleValue sv1d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv1, sv1d); SimpleValue sv2d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv2, sv2d); SimpleValue sv3d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv3, sv3d); SimpleValue sv4d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv4, sv4d); SimpleValue sv5d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv5, sv5d); SimpleValue sv6d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv6, sv6d); SimpleValue sv7d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv7, sv7d); SimpleValue sv8d = (SimpleValue)ctx.Deserialize(new DataReader(stream)); Assert.AreEqual(sv8, sv8d); }