/// <summary> /// Copies the local properties. /// </summary> internal void CopyLocalProperties(BinaryConfiguration cfg) { Debug.Assert(cfg != null); IdMapper = cfg.IdMapper; NameMapper = cfg.NameMapper; KeepDeserialized = cfg.KeepDeserialized; ForceTimestamp = cfg.ForceTimestamp; TimestampConverter = cfg.TimestampConverter; if (cfg.Serializer != null) { Serializer = cfg.Serializer; } TypeConfigurations = cfg.TypeConfigurations == null ? null : cfg.TypeConfigurations.Select(x => new BinaryTypeConfiguration(x)).ToList(); Types = cfg.Types == null ? null : cfg.Types.ToList(); if (cfg.CompactFooterInternal != null) { CompactFooter = cfg.CompactFooterInternal.Value; } }
/// <summary> /// Constrcutor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="name">Type name.</param> public BinarySurrogateTypeDescriptor(BinaryConfiguration cfg, string name) { _cfg = cfg; _name = name; _id = BinaryUtils.TypeId(name, cfg.DefaultNameMapper, cfg.DefaultIdMapper); }
public void TestStructure() { for (int i = 1; i <= RepeatCnt; i++) { Console.WriteLine(">>> Iteration started: " + i); // 1. Generate and shuffle objects. IList<BranchedType> objs = new List<BranchedType>(); for (int j = 0; j < 6 * ObjectsPerMode; j++) objs.Add(new BranchedType((j%6) + 1)); objs = IgniteUtils.Shuffle(objs); // 2. Create new marshaller. BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType)); BinaryConfiguration cfg = new BinaryConfiguration { TypeConfigurations = new List<BinaryTypeConfiguration> { typeCfg } }; Marshaller marsh = new Marshaller(cfg); // 3. Marshal all data and ensure deserialized object is fine. // Use single stream to test object offsets using (var stream = new BinaryHeapStream(128)) { var writer = marsh.StartMarshal(stream); foreach (var obj in objs) { Console.WriteLine(">>> Write object [mode=" + obj.mode + ']'); writer.WriteObject(obj); } stream.Seek(0, SeekOrigin.Begin); var reader = marsh.StartUnmarshal(stream); foreach (var obj in objs) { var other = reader.ReadObject<BranchedType>(); Assert.IsTrue(obj.Equals(other)); } } Console.WriteLine(); // 4. Ensure that all fields are recorded. var desc = marsh.GetDescriptor(typeof (BranchedType)); CollectionAssert.AreEquivalent(new[] {"mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8"}, desc.WriterTypeStructure.FieldTypes.Keys); } }
/// <summary> /// Initializes a new instance of the <see cref="BinaryConfiguration" /> class. /// </summary> /// <param name="cfg">The binary configuration to copy.</param> public BinaryConfiguration(BinaryConfiguration cfg) { IgniteArgumentCheck.NotNull(cfg, "cfg"); DefaultIdMapper = cfg.DefaultIdMapper; DefaultNameMapper = cfg.DefaultNameMapper; DefaultKeepDeserialized = cfg.DefaultKeepDeserialized; DefaultSerializer = cfg.DefaultSerializer; TypeConfigurations = cfg.TypeConfigurations == null ? null : cfg.TypeConfigurations.Select(x => new BinaryTypeConfiguration(x)).ToList(); Types = cfg.Types == null ? null : cfg.Types.ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryConfiguration" /> class. /// </summary> /// <param name="cfg">The binary configuration to copy.</param> public BinaryConfiguration(BinaryConfiguration cfg) { IgniteArgumentCheck.NotNull(cfg, "cfg"); IdMapper = cfg.IdMapper; NameMapper = cfg.NameMapper; KeepDeserialized = cfg.KeepDeserialized; Serializer = cfg.Serializer; TypeConfigurations = cfg.TypeConfigurations == null ? null : cfg.TypeConfigurations.Select(x => new BinaryTypeConfiguration(x)).ToList(); Types = cfg.Types == null ? null : cfg.Types.ToList(); CompactFooter = cfg.CompactFooter; }
/// <summary> /// Copying constructor. /// </summary> /// <param name="cfg">Configuration to copy.</param> public BinaryConfiguration(BinaryConfiguration cfg) { DefaultIdMapper = cfg.DefaultIdMapper; DefaultNameMapper = cfg.DefaultNameMapper; DefaultKeepDeserialized = cfg.DefaultKeepDeserialized; DefaultSerializer = cfg.DefaultSerializer; Types = cfg.Types != null ? new List<string>(cfg.Types) : null; if (cfg.TypeConfigurations != null) { TypeConfigurations = new List<BinaryTypeConfiguration>(cfg.TypeConfigurations.Count); foreach (BinaryTypeConfiguration typeCfg in cfg.TypeConfigurations) TypeConfigurations.Add(new BinaryTypeConfiguration(typeCfg)); } }
public void TestStructure() { for (int i = 1; i <= RepeatCnt; i++) { Console.WriteLine(">>> Iteration started: " + i); // 1. Generate and shuffle objects. IList<BranchedType> objs = new List<BranchedType>(); for (int j = 0; j < 6 * ObjectsPerMode; j++) objs.Add(new BranchedType((j%6) + 1)); objs = IgniteUtils.Shuffle(objs); // 2. Create new marshaller. BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType)); BinaryConfiguration cfg = new BinaryConfiguration { TypeConfigurations = new List<BinaryTypeConfiguration> { typeCfg } }; Marshaller marsh = new Marshaller(cfg); // 3. Marshal all data and ensure deserialized object is fine. foreach (BranchedType obj in objs) { Console.WriteLine(">>> Write object [mode=" + obj.mode + ']'); byte[] data = marsh.Marshal(obj); BranchedType other = marsh.Unmarshal<BranchedType>(data); Assert.IsTrue(obj.Equals(other)); } Console.WriteLine(); // 4. Ensure that all fields are recorded. var desc = marsh.GetDescriptor(typeof (BranchedType)); CollectionAssert.AreEquivalent(new[] {"mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8"}, desc.WriterTypeStructure.FieldTypes.Keys); } }
/// <summary> /// Copying constructor. /// </summary> /// <param name="cfg">Configuration to copy.</param> public BinaryConfiguration(BinaryConfiguration cfg) { DefaultIdMapper = cfg.DefaultIdMapper; DefaultNameMapper = cfg.DefaultNameMapper; DefaultKeepDeserialized = cfg.DefaultKeepDeserialized; DefaultSerializer = cfg.DefaultSerializer; Types = cfg.Types != null ? new List <string>(cfg.Types) : null; if (cfg.TypeConfigurations != null) { TypeConfigurations = new List <BinaryTypeConfiguration>(cfg.TypeConfigurations.Count); foreach (BinaryTypeConfiguration typeCfg in cfg.TypeConfigurations) { TypeConfigurations.Add(new BinaryTypeConfiguration(typeCfg)); } } }
/// <summary> /// Merges other config into this. /// </summary> internal void MergeTypes(BinaryConfiguration localConfig) { if (TypeConfigurations == null) { TypeConfigurations = localConfig.TypeConfigurations; } else if (localConfig.TypeConfigurations != null) { // Both configs are present. // Local configuration is more complete and takes preference when it exists for a given type. var localTypeNames = new HashSet <string>(localConfig.TypeConfigurations.Select(x => x.TypeName), StringComparer.OrdinalIgnoreCase); var configs = new List <BinaryTypeConfiguration>(localConfig.TypeConfigurations); configs.AddRange(TypeConfigurations.Where(x => !localTypeNames.Contains(x.TypeName))); TypeConfigurations = configs; } }
/// <summary> /// Create configuration. /// </summary> /// <param name="name">Grid name.</param> /// <param name="springCfg">Spring configuration.</param> /// <returns>Configuration.</returns> private static IgniteConfigurationEx CreateConfiguration(string name, string springCfg) { IgniteConfigurationEx cfg = new IgniteConfigurationEx(); BinaryConfiguration portCfg = new BinaryConfiguration(); ICollection<BinaryTypeConfiguration> portTypeCfgs = new List<BinaryTypeConfiguration>(); portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(DynamicTestKey))); portTypeCfgs.Add(new BinaryTypeConfiguration(typeof(DynamicTestValue))); portCfg.TypeConfigurations = portTypeCfgs; cfg.GridName = name; cfg.BinaryConfiguration = portCfg; cfg.JvmClasspath = TestUtils.CreateTestClasspath(); cfg.JvmOptions = TestUtils.TestJavaOptions(); cfg.SpringConfigUrl = springCfg; return cfg; }
/// <summary> /// Initializes a new instance of the <see cref="BinaryConfiguration" /> class. /// </summary> /// <param name="cfg">The binary configuration to copy.</param> public BinaryConfiguration(BinaryConfiguration cfg) { IgniteArgumentCheck.NotNull(cfg, "cfg"); CopyLocalProperties(cfg); }
/// <summary> /// Configuration for node. /// </summary> /// <param name="path">Path to Java XML configuration.</param> /// <returns>Node configuration.</returns> protected IgniteConfiguration Configuration(string path) { IgniteConfiguration cfg = new IgniteConfiguration(); if (!_fork) { BinaryConfiguration portCfg = new BinaryConfiguration(); ICollection<BinaryTypeConfiguration> portTypeCfgs = new List<BinaryTypeConfiguration>(); GetBinaryTypeConfigurations(portTypeCfgs); portCfg.TypeConfigurations = portTypeCfgs; cfg.BinaryConfiguration = portCfg; } cfg.JvmClasspath = TestUtils.CreateTestClasspath(); cfg.JvmOptions = TestUtils.TestJavaOptions(); cfg.SpringConfigUrl = path; return cfg; }
/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="id">Type ID.</param> public BinarySurrogateTypeDescriptor(BinaryConfiguration cfg, int id) { _cfg = cfg; _id = id; }