ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [5/7] ignite git commit: IGNITE-6354 .NET: Fix DataStreamer with complex object graphs
Date Wed, 13 Sep 2017 08:44:39 GMT
IGNITE-6354 .NET: Fix DataStreamer with complex object graphs

This closes #2645


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

Branch: refs/heads/ignite-5896
Commit: 67d716f00806c8d69f8339b090e0ddd877b225e3
Parents: ed3d2a5
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Tue Sep 12 17:41:38 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Tue Sep 12 17:41:38 2017 +0300

----------------------------------------------------------------------
 .../Cache/CacheAbstractTest.cs                  | 67 ++++++++------------
 .../Dataload/DataStreamerTest.cs                | 49 ++++++++++++++
 .../Impl/Binary/BinaryWriterExtensions.cs       |  8 +--
 .../Apache.Ignite.Core/Impl/Cache/CacheImpl.cs  | 52 ++++++++-------
 .../Impl/Compute/ComputeImpl.cs                 |  2 +-
 .../Impl/Datastream/DataStreamerBatch.cs        | 10 +--
 .../Impl/Services/ServiceProxySerializer.cs     | 10 ++-
 7 files changed, 120 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
index 27ac3f4..39a18fe 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
@@ -128,14 +128,18 @@ namespace Apache.Ignite.Core.Tests.Cache
             return GetIgnite(idx).GetCache<TK, TV>(CacheName());
         }
 
-        protected ICache<int, int> Cache()
+        protected ICache<int, int> Cache(bool async = false)
         {
-            return Cache<int, int>(0);
+            var cache = Cache<int, int>(0);
+
+            return async ? cache.WrapAsync() : cache;
         }
 
-        private ICache<TK, TV> Cache<TK, TV>()
+        private ICache<TK, TV> Cache<TK, TV>(bool async = false)
         {
-            return Cache<TK, TV>(0);
+            var cache = Cache<TK, TV>(0);
+
+            return async ? cache : cache.WrapAsync();
         }
 
         private ICacheAffinity Affinity()
@@ -404,39 +408,26 @@ namespace Apache.Ignite.Core.Tests.Cache
         }
 
         [Test]
-        public void TestPut()
+        public void TestPut([Values(true, false)] bool async)
         {
-            var cache = Cache();
+            var cache = Cache(async);
 
             cache.Put(1, 1);
 
             Assert.AreEqual(1, cache.Get(1));
-        }
-
-        [Test]
-        public void TestPutxAsync()
-        {
-            var cache = Cache().WrapAsync();
-
-            cache.Put(1, 1);
-
-            Assert.AreEqual(1, cache.Get(1));
-        }
-
-        [Test]
-        public void TestPutIfAbsent()
-        {
-            var cache = Cache();
 
-            Assert.IsFalse(cache.ContainsKey(1));
+            // Objects.
+            var cache2 = Cache<Container, Container>(async);
 
-            Assert.AreEqual(true, cache.PutIfAbsent(1, 1));
+            var obj1 = new Container {Id = 1};
+            var obj2 = new Container {Id = 2};
 
-            Assert.AreEqual(1, cache.Get(1));
+            obj1.Inner = obj2;
+            obj2.Inner = obj1;
 
-            Assert.AreEqual(false, cache.PutIfAbsent(1, 2));
+            cache2[obj1] = obj2;
 
-            Assert.AreEqual(1, cache.Get(1));
+            Assert.AreEqual(2, cache2[obj1].Id);
         }
 
         [Test]
@@ -458,7 +449,7 @@ namespace Apache.Ignite.Core.Tests.Cache
         [Test]
         public void TestGetAndPutIfAbsentAsync()
         {
-            var cache = Cache().WrapAsync();
+            var cache = Cache(true);
 
             Assert.IsFalse(cache.ContainsKey(1));
 
@@ -476,9 +467,9 @@ namespace Apache.Ignite.Core.Tests.Cache
         }
 
         [Test]
-        public void TestPutIfAbsentAsync()
+        public void TestPutIfAbsent([Values(true, false)] bool async)
         {
-            var cache = Cache().WrapAsync();
+            var cache = Cache(async);
 
             Assert.Throws<KeyNotFoundException>(() => cache.Get(1));
             Assert.IsFalse(cache.ContainsKey(1));
@@ -599,12 +590,7 @@ namespace Apache.Ignite.Core.Tests.Cache
         [Test]
         public void TestPutAll([Values(true, false)] bool async)
         {
-            var cache = Cache();
-
-            if (async)
-            {
-                cache = cache.WrapAsync();
-            }
+            var cache = Cache(async);
 
             // Primitives.
             cache.PutAll(new Dictionary<int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } });
@@ -614,12 +600,7 @@ namespace Apache.Ignite.Core.Tests.Cache
             Assert.AreEqual(3, cache.Get(3));
 
             // Objects.
-            var cache2 = Cache<int, Container>();
-
-            if (async)
-            {
-                cache2 = cache2.WrapAsync();
-            }
+            var cache2 = Cache<int, Container>(async);
 
             var obj1 = new Container();
             var obj2 = new Container();
@@ -2565,6 +2546,8 @@ namespace Apache.Ignite.Core.Tests.Cache
 
         private class Container
         {
+            public int Id;
+
             public Container Inner;
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
index 85ee976..fe5955f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
@@ -168,6 +168,46 @@ namespace Apache.Ignite.Core.Tests.Dataload
         }
 
         /// <summary>
+        /// Tests object graphs with loops.
+        /// </summary>
+        [Test]
+        public void TestObjectGraphs()
+        {
+            var obj1 = new Container();
+            var obj2 = new Container();
+            var obj3 = new Container();
+            var obj4 = new Container();
+
+            obj1.Inner = obj2;
+            obj2.Inner = obj1;
+            obj3.Inner = obj1;
+            obj4.Inner = new Container();
+
+            using (var ldr = _grid.GetDataStreamer<int, Container>(CacheName))
+            {
+                ldr.AllowOverwrite = true;
+
+                ldr.AddData(1, obj1);
+                ldr.AddData(2, obj2);
+                ldr.AddData(3, obj3);
+                ldr.AddData(4, obj4);
+            }
+
+            var cache = _grid.GetCache<int, Container>(CacheName);
+
+            var res = cache[1];
+            Assert.AreEqual(res, res.Inner.Inner);
+
+            Assert.IsNotNull(cache[2].Inner);
+            Assert.IsNotNull(cache[2].Inner.Inner);
+            Assert.IsNotNull(cache[3].Inner);
+            Assert.IsNotNull(cache[3].Inner.Inner);
+            
+            Assert.IsNotNull(cache[4].Inner);
+            Assert.IsNull(cache[4].Inner.Inner);
+        }
+
+        /// <summary>
         /// Test "tryFlush".
         /// </summary>
         [Test]
@@ -572,5 +612,14 @@ namespace Apache.Ignite.Core.Tests.Dataload
         {
             public int Val { get; set; }
         }
+
+        /// <summary>
+        /// Container class.
+        /// </summary>
+        private class Container
+        {
+            public Container Inner;
+        }
+
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriterExtensions.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriterExtensions.cs
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriterExtensions.cs
index 02b5dec..f75fcf8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriterExtensions.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriterExtensions.cs
@@ -92,12 +92,12 @@ namespace Apache.Ignite.Core.Impl.Binary
             if (selector == null)
             {
                 foreach (var val in vals)
-                    writer.Write(val);
+                    writer.WriteObjectDetached(val);
             }
             else
             {
                 foreach (var val in vals)
-                    writer.Write(selector(val));
+                    writer.WriteObjectDetached(selector(val));
             }
         }
 
@@ -142,7 +142,7 @@ namespace Apache.Ignite.Core.Impl.Binary
             {
                 foreach (var val in vals)
                 {
-                    writer.Write(val);
+                    writer.WriteObjectDetached(val);
 
                     size++;
                 }
@@ -151,7 +151,7 @@ namespace Apache.Ignite.Core.Impl.Binary
             {
                 foreach (var val in vals)
                 {
-                    writer.Write(selector(val));
+                    writer.WriteObjectDetached(selector(val));
 
                     size++;
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
index 64eee8d..05644cd 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
@@ -250,17 +250,21 @@ namespace Apache.Ignite.Core.Impl.Cache
                 var p0 = new CacheEntryFilterHolder(p, (k, v) => p.Invoke(new CacheEntry<TK,
TV>((TK) k, (TV) v)),
                     Marshaller, IsKeepBinary);
 
-                writer.WriteObject(p0);
+                writer.WriteObjectDetached(p0);
             }
             else
-                writer.WriteObject<CacheEntryFilterHolder>(null);
+            {
+                writer.WriteObjectDetached<CacheEntryFilterHolder>(null);
+            }
 
             if (args != null && args.Length > 0)
             {
                 writer.WriteInt(args.Length);
 
                 foreach (var o in args)
-                    writer.WriteObject(o);
+                {
+                    writer.WriteObjectDetached(o);
+                }
             }
             else
             {
@@ -337,7 +341,7 @@ namespace Apache.Ignite.Core.Impl.Cache
             var res = DoOutInOpX((int)CacheOp.Peek,
                 w =>
                 {
-                    w.Write(key);
+                    w.WriteObjectDetached(key);
                     w.WriteInt(EncodePeekModes(modes));
                 },
                 (s, r) => r == True ? new CacheResult<TV>(Unmarshal<TV>(s))
: new CacheResult<TV>(),
@@ -473,8 +477,8 @@ namespace Apache.Ignite.Core.Impl.Cache
 
             return DoOutOpAsync(CacheOp.GetAndPutAsync, w =>
             {
-                w.WriteObject(key);
-                w.WriteObject(val);
+                w.WriteObjectDetached(key);
+                w.WriteObjectDetached(val);
             }, r => GetCacheResult(r));
         }
 
@@ -499,8 +503,8 @@ namespace Apache.Ignite.Core.Impl.Cache
 
             return DoOutOpAsync(CacheOp.GetAndReplaceAsync, w =>
             {
-                w.WriteObject(key);
-                w.WriteObject(val);
+                w.WriteObjectDetached(key);
+                w.WriteObjectDetached(val);
             }, r => GetCacheResult(r));
         }
 
@@ -567,8 +571,8 @@ namespace Apache.Ignite.Core.Impl.Cache
 
             return DoOutOpAsync(CacheOp.GetAndPutIfAbsentAsync, w =>
             {
-                w.WriteObject(key);
-                w.WriteObject(val);
+                w.WriteObjectDetached(key);
+                w.WriteObjectDetached(val);
             }, r => GetCacheResult(r));
         }
 
@@ -617,9 +621,9 @@ namespace Apache.Ignite.Core.Impl.Cache
 
             return DoOutOpAsync<bool>(CacheOp.Replace3Async, w =>
             {
-                w.WriteObject(key);
-                w.WriteObject(oldVal);
-                w.WriteObject(newVal);
+                w.WriteObjectDetached(key);
+                w.WriteObjectDetached(oldVal);
+                w.WriteObjectDetached(newVal);
             });
         }
 
@@ -838,8 +842,8 @@ namespace Apache.Ignite.Core.Impl.Cache
             return DoOutInOpX((int) CacheOp.Invoke,
                 writer =>
                 {
-                    writer.Write(key);
-                    writer.Write(holder);
+                    writer.WriteObjectDetached(key);
+                    writer.WriteObjectDetached(holder);
                 },
                 (input, res) => res == True ? Unmarshal<TRes>(input) : default(TRes),
                 _readException);
@@ -858,8 +862,8 @@ namespace Apache.Ignite.Core.Impl.Cache
 
             return DoOutOpAsync(CacheOp.InvokeAsync, writer =>
                 {
-                    writer.Write(key);
-                    writer.Write(holder);
+                    writer.WriteObjectDetached(key);
+                    writer.WriteObjectDetached(holder);
                 },
                 r =>
                 {
@@ -1319,8 +1323,8 @@ namespace Apache.Ignite.Core.Impl.Cache
         {
             return DoOutInOpX((int) op, w =>
             {
-                w.Write(x);
-                w.Write(y);
+                w.WriteObjectDetached(x);
+                w.WriteObjectDetached(y);
             }, _readException);
         }
 
@@ -1331,9 +1335,9 @@ namespace Apache.Ignite.Core.Impl.Cache
         {
             return DoOutInOpX((int) op, w =>
             {
-                w.Write(x);
-                w.Write(y);
-                w.Write(z);
+                w.WriteObjectDetached(x);
+                w.WriteObjectDetached(y);
+                w.WriteObjectDetached(z);
             }, _readException);
         }
 
@@ -1364,8 +1368,8 @@ namespace Apache.Ignite.Core.Impl.Cache
             return DoOutInOpX((int)cacheOp,
                 w =>
                 {
-                    w.Write(x);
-                    w.Write(y);
+                    w.WriteObjectDetached(x);
+                    w.WriteObjectDetached(y);
                 },
                 (stream, res) => res == True ? new CacheResult<TV>(Unmarshal<TV>(stream))
: new CacheResult<TV>(),
                 _readException);

http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Compute/ComputeImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Compute/ComputeImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Compute/ComputeImpl.cs
index 06f9ad4..3c684ae 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Compute/ComputeImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Compute/ComputeImpl.cs
@@ -590,7 +590,7 @@ namespace Apache.Ignite.Core.Impl.Compute
 
             try
             {
-                writer.WriteObject(jobHolder);
+                writer.WriteObjectDetached(jobHolder);
             }
             catch (Exception)
             {

http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Datastream/DataStreamerBatch.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Datastream/DataStreamerBatch.cs
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Datastream/DataStreamerBatch.cs
index 66ee695..38a8ea8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Datastream/DataStreamerBatch.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Datastream/DataStreamerBatch.cs
@@ -221,8 +221,8 @@ namespace Apache.Ignite.Core.Impl.Datastream
                 {
                     foreach (KeyValuePair<TK, TV> item in entries)
                     {
-                        writer.Write(item.Key);
-                        writer.Write(item.Value);
+                        writer.WriteObjectDetached(item.Key);
+                        writer.WriteObjectDetached(item.Value);
                     }
 
                     continue;
@@ -232,8 +232,8 @@ namespace Apache.Ignite.Core.Impl.Datastream
                 DataStreamerEntry<TK, TV> entry = val as DataStreamerEntry<TK, TV>;
 
                 if (entry != null) {
-                    writer.Write(entry.Key);
-                    writer.Write(entry.Value);
+                    writer.WriteObjectDetached(entry.Key);
+                    writer.WriteObjectDetached(entry.Value);
 
                     continue;
                 }
@@ -243,7 +243,7 @@ namespace Apache.Ignite.Core.Impl.Datastream
 
                 if (rmvEntry != null)
                 {
-                    writer.Write(rmvEntry.Key);
+                    writer.WriteObjectDetached(rmvEntry.Key);
                     writer.Write<object>(null);
                 }
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/67d716f0/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs
index b4273b1..fc6009a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceProxySerializer.cs
@@ -56,7 +56,9 @@ namespace Apache.Ignite.Core.Impl.Services
                 {
                     // Write as is
                     foreach (var arg in arguments)
-                        writer.WriteObject(arg);
+                    {
+                        writer.WriteObjectDetached(arg);
+                    }
                 }
                 else
                 {
@@ -200,9 +202,13 @@ namespace Apache.Ignite.Core.Impl.Services
             var hnd = GetPlatformArgWriter(param, arg);
 
             if (hnd != null)
+            {
                 hnd(writer, arg);
+            }
             else
-                writer.WriteObject(arg);
+            {
+                writer.WriteObjectDetached(arg);
+            }
         }
 
         /// <summary>


Mime
View raw message