ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [11/15] ignite git commit: IGNITE-4614 .NET: Reset binary schema in BinaryReader new frame
Date Thu, 26 Jan 2017 14:53:10 GMT
IGNITE-4614 .NET: Reset binary schema in BinaryReader new frame


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e8067a6a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e8067a6a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e8067a6a

Branch: refs/heads/ignite-comm-balance-master
Commit: e8067a6a38d8d1bea43cc47d1867fcc2a804f969
Parents: 885dc32
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Wed Jan 25 20:33:11 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Wed Jan 25 20:33:11 2017 +0300

----------------------------------------------------------------------
 .../Binary/BinaryStructureTest.cs               | 122 +++++++++++++++++++
 .../Impl/Binary/BinaryReader.cs                 |   6 +
 2 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e8067a6a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs
index 1ab81c5..1bd2bf4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs
@@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Tests.Binary
     using System.Collections.Generic;
     using System.Diagnostics.CodeAnalysis;
     using System.IO;
+    using System.Linq;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Impl;
     using Apache.Ignite.Core.Impl.Binary;
@@ -102,6 +103,49 @@ namespace Apache.Ignite.Core.Tests.Binary
                     desc.WriterTypeStructure.FieldTypes.Keys);
             }
         }
+
+        /// <summary>
+        /// Tests that nested raw object does not inherit outer schema.
+        /// </summary>
+        [Test]
+        public void TestNestedRaw()
+        {
+            var marsh = new Marshaller(new BinaryConfiguration(typeof(RawContainer), typeof(RawNested)));
+
+            var obj = new RawContainer {Int = 3, Raw = new RawNested {Int = 5}};
+
+            var res = marsh.Unmarshal<RawContainer>(marsh.Marshal(obj));
+
+            Assert.AreEqual(obj.Int, res.Int);
+            Assert.AreEqual(0, res.Raw.Int);  // Int is not written and can't be read.
+        }
+
+        /// <summary>
+        /// Tests that nested object schemas do not interfere.
+        /// </summary>
+        [Test]
+        public void TestNested()
+        {
+            var marsh = new Marshaller(new BinaryConfiguration(typeof(Container), typeof(Nested)));
+
+            var obj = new Container
+            {
+                Foo = 2,
+                Bar = 4,
+                Nested = new Nested
+                {
+                    Baz = 3,
+                    Qux = 5
+                }
+            };
+
+            var res = marsh.Unmarshal<Container>(marsh.Marshal(obj));
+
+            Assert.AreEqual(2, res.Foo);
+            Assert.AreEqual(4, res.Bar);
+            Assert.AreEqual(3, res.Nested.Baz);
+            Assert.AreEqual(5, res.Nested.Qux);
+        }
     }
 
     [SuppressMessage("ReSharper", "InconsistentNaming")]
@@ -263,4 +307,82 @@ namespace Apache.Ignite.Core.Tests.Binary
                    f6 == other.f6 && f7 == other.f7 && f8 == other.f8;
         }
     }
+
+    public class RawContainer : IBinarizable
+    {
+        public int Int { get; set; }
+
+        public RawNested Raw { get; set; }
+
+        public void WriteBinary(IBinaryWriter writer)
+        {
+            writer.WriteInt("int", Int);
+            writer.WriteObject("raw", Raw);
+        }
+
+        public void ReadBinary(IBinaryReader reader)
+        {
+            Int = reader.ReadInt("int");
+            Raw = reader.ReadObject<RawNested>("raw");
+        }
+    }
+
+    public class RawNested : IBinarizable
+    {
+        public int Int { get; set; }
+
+        public void WriteBinary(IBinaryWriter writer)
+        {
+            // Write only raw data.
+            writer.GetRawWriter().WriteIntArray(Enumerable.Range(1, 100).ToArray());
+        }
+
+        public void ReadBinary(IBinaryReader reader)
+        {
+            // Attempt to read even though we did not write fields.
+            // If schema is carried over, there will be a broken result.
+            Int = reader.ReadInt("int");
+        }
+    }
+
+    public class Container : IBinarizable
+    {
+        public int Foo { get; set; }
+        public int Bar { get; set; }
+        public Nested Nested { get; set; }
+
+        public void WriteBinary(IBinaryWriter writer)
+        {
+            writer.WriteInt("foo", Foo);
+            writer.WriteInt("bar", Bar);
+            writer.WriteObject("nested", Nested);
+        }
+
+        public void ReadBinary(IBinaryReader reader)
+        {
+            // Read in reverse order to defeat structure optimization.
+            Bar = reader.ReadInt("bar");
+            Foo = reader.ReadInt("foo");
+            Nested = reader.ReadObject<Nested>("nested");
+        }
+    }
+
+    public class Nested : IBinarizable
+    {
+        public int Baz { get; set; }
+        public int Qux { get; set; }
+
+        public void WriteBinary(IBinaryWriter writer)
+        {
+            writer.WriteInt("baz", Baz);
+            writer.WriteInt("qux", Qux);
+        }
+
+        public void ReadBinary(IBinaryReader reader)
+        {
+            // Read in reverse order to defeat structure optimization.
+            Qux = reader.ReadInt("qux");
+            Baz = reader.ReadInt("baz");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/e8067a6a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
index 70417f7..2a59c06 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
@@ -729,6 +729,8 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// </summary>
         private void SetCurSchema(IBinaryTypeDescriptor desc)
         {
+            _frame.SchemaMap = null;
+
             if (_frame.Hdr.HasSchema)
             {
                 _frame.Schema = desc.Schema.Get(_frame.Hdr.SchemaId);
@@ -740,6 +742,10 @@ namespace Apache.Ignite.Core.Impl.Binary
                     desc.Schema.Add(_frame.Hdr.SchemaId, _frame.Schema);
                 }
             }
+            else
+            {
+                _frame.Schema = null;
+            }
         }
 
         /// <summary>


Mime
View raw message