You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/11/26 16:38:45 UTC

ignite git commit: IGNITE-1965 .NET: Introduce wrapper for enums, similar to "IBinaryObject". - never read enum fields in binary mode - fix store test config - fix npe in writer - add test for a standalone enum in stream

Repository: ignite
Updated Branches:
  refs/heads/ignite-1956 a938dc853 -> da2df40a0


IGNITE-1965 .NET: Introduce wrapper for enums, similar to "IBinaryObject".
- never read enum fields in binary mode
- fix store test config
- fix npe in writer
- add test for a standalone enum in stream


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

Branch: refs/heads/ignite-1956
Commit: da2df40a06c88f605d9a9bd9cb6a28e21eeb6c76
Parents: a938dc8
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Thu Nov 26 18:38:32 2015 +0300
Committer: Pavel Tupitsyn <pt...@gridgain.com>
Committed: Thu Nov 26 18:38:32 2015 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs  |  8 +++++++-
 .../Config/native-client-test-cache-store.xml          |  1 +
 .../Apache.Ignite.Core/Impl/Binary/BinaryReader.cs     |  9 +++++----
 .../Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs     | 13 ++++++++-----
 4 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/da2df40a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
index edf11f1..88328ec 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
@@ -508,7 +508,13 @@ namespace Apache.Ignite.Core.Tests.Binary
 
             TestEnum val = TestEnum.Val1;
 
-            Assert.AreEqual(marsh.Unmarshal<TestEnum>(marsh.Marshal(val)), val);
+            var data = marsh.Marshal(val);
+
+            Assert.AreEqual(marsh.Unmarshal<TestEnum>(data), val);
+
+            var binEnum = marsh.Unmarshal<IBinaryObject>(data, true);
+
+            Assert.AreEqual(val, (TestEnum) binEnum.EnumValue);
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/da2df40a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/native-client-test-cache-store.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/native-client-test-cache-store.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/native-client-test-cache-store.xml
index b414a91..25a1d16 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/native-client-test-cache-store.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/native-client-test-cache-store.xml
@@ -41,6 +41,7 @@
                     <property name="atomicityMode" value="TRANSACTIONAL"/>
                     <property name="writeThrough" value="true"/>
                     <property name="readThrough" value="true"/>
+                    <property name="keepBinaryInStore" value="true"/>
 
                     <property name="cacheStoreFactory">
                         <bean class="org.apache.ignite.platform.dotnet.PlatformDotNetCacheStoreFactory">

http://git-wip-us.apache.org/repos/asf/ignite/blob/da2df40a/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 63fd62a..7b887a9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
@@ -413,7 +413,8 @@ namespace Apache.Ignite.Core.Impl.Binary
                     return default(T);
 
                 case BinaryUtils.TypeEnum:
-                    return ReadEnum0<T>(this);
+                    // Never read enums in binary mode when reading a field (we do not support half-binary objects)
+                    return ReadEnum0<T>(this, false);  
 
                 case BinaryUtils.HdrFull:
                     // Unregistered enum written as serializable
@@ -582,7 +583,7 @@ namespace Apache.Ignite.Core.Impl.Binary
                     return true;
 
                 case BinaryUtils.TypeEnum:
-                    res = ReadEnum0<T>(this);
+                    res = ReadEnum0<T>(this, _mode != BinaryMode.Deserialize);
 
                     return true;
             }
@@ -986,13 +987,13 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// <summary>
         /// Reads the enum.
         /// </summary>
-        private static T ReadEnum0<T>(BinaryReader reader)
+        private static T ReadEnum0<T>(BinaryReader reader, bool keepBinary)
         {
             var enumType = reader.ReadInt();
 
             var enumValue = reader.ReadInt();
 
-            if (reader._mode == BinaryMode.Deserialize)
+            if (!keepBinary)
                 return BinaryUtils.GetEnumValue<T>(enumValue, enumType, reader.Marshaller);
 
             return TypeCaster<T>.Cast(new BinaryEnum(enumType, enumValue, reader.Marshaller));

http://git-wip-us.apache.org/repos/asf/ignite/blob/da2df40a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
index 25d9b98..189cd50 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
@@ -1445,12 +1445,15 @@ namespace Apache.Ignite.Core.Impl.Binary
 
                 if (_metas.TryGetValue(desc.TypeId, out meta))
                 {
-                    IDictionary<string, int> existingFields = meta.GetFieldsMap();
-
-                    foreach (KeyValuePair<string, int> field in fields)
+                    if (fields != null)
                     {
-                        if (!existingFields.ContainsKey(field.Key))
-                            existingFields[field.Key] = field.Value;
+                        IDictionary<string, int> existingFields = meta.GetFieldsMap();
+
+                        foreach (KeyValuePair<string, int> field in fields)
+                        {
+                            if (!existingFields.ContainsKey(field.Key))
+                                existingFields[field.Key] = field.Value;
+                        }
                     }
                 }
                 else