public void TestClassDefinitionConfigWithErrors() { var serializationConfig = new SerializationConfig(); serializationConfig.AddPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new TestPortableFactory()); serializationConfig.SetPortableVersion(1); serializationConfig.AddClassDefinition( new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.RAW_DATA_PORTABLE) .AddLongField("l") .AddCharArrayField("c") .AddPortableField("p", CreateNamedPortableClassDefinition()) .Build()); try { new SerializationServiceBuilder().SetConfig(serializationConfig).Build(); Assert.Fail("Should throw HazelcastSerializationException!"); } catch (HazelcastSerializationException) { } new SerializationServiceBuilder().SetConfig(serializationConfig).SetCheckClassDefErrors(false).Build(); // -- OR -- serializationConfig.SetCheckClassDefErrors(false); new SerializationServiceBuilder().SetConfig(serializationConfig).Build(); }
public void TestClassDefinitionConfig() { var serializationConfig = new SerializationConfig(); serializationConfig.AddPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new TestPortableFactory()); serializationConfig.SetPortableVersion(1); serializationConfig .AddClassDefinition( new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.RAW_DATA_PORTABLE) .AddLongField("l") .AddCharArrayField("c") .AddPortableField("p", CreateNamedPortableClassDefinition()) .Build()) .AddClassDefinition( new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE) .AddUTFField("name").AddIntField("myint").Build()); var serializationService = new SerializationServiceBuilder() .SetConfig(serializationConfig) .AddDataSerializableFactory(TestSerializationConstants.DATA_SERIALIZABLE_FACTORY_ID, GetDataSerializableFactory()) .Build(); var p = new RawDataPortable(DateTime.Now.ToFileTime(), "test chars".ToCharArray(), new NamedPortable("named portable", 34567), 9876, "Testing raw portable", new ByteArrayDataSerializable(Encoding.UTF8.GetBytes("test bytes"))); var data = serializationService.ToData(p); Assert.AreEqual(p, serializationService.ToObject <RawDataPortable>(data)); }
public void TestAddPortableFactoryWithBadId() { var config = new SerializationConfig(); config.AddPortableFactory(-1, new KitchenSinkPortableFactory()); var service = new SerializationServiceBuilder().SetConfig(config).Build(); }
public void TestAddPortableFactoryClassWithDuplicateId() { var config = new SerializationConfig(); config.AddPortableFactory(1, new KitchenSinkPortableFactory()); config.AddPortableFactoryClass(1, typeof(KitchenSinkPortableFactory)); var service = new SerializationServiceBuilder().SetConfig(config).Build(); }
public void TestAddPortableFactoryWithBadId() { Assert.Throws <ArgumentException>(() => { var config = new SerializationConfig(); config.AddPortableFactory(-1, new KitchenSinkPortableFactory()); var service = new SerializationServiceBuilder().SetConfig(config).Build(); }); }
public void TestAddPortableFactory() { var service1 = new SerializationServiceBuilder().Build(); var data = service1.ToData(new KitchenSinkPortable()); var config = new SerializationConfig(); config.AddPortableFactory(1, new KitchenSinkPortableFactory()); var service = new SerializationServiceBuilder().SetConfig(config).Build(); var obj = service.ToObject <object>(data); Assert.IsInstanceOf <KitchenSinkPortable>(obj); }