This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-dotnet-core-client.git


The following commit(s) were added to refs/heads/develop by this push:
     new c885c1e  Update to get in sync with recent changes in native - 
apache_geode_CreateCacheFactory takes a client parameter
c885c1e is described below

commit c885c1ef2d4786fdffe1019c3dfa7b2c39e1f7f5
Author: Blake Bender <[email protected]>
AuthorDate: Wed May 26 14:51:17 2021 -0700

    Update to get in sync with recent changes in native
    - apache_geode_CreateCacheFactory takes a client parameter
---
 NetCore.Test/CacheFactoryUnitTest.cs  | 14 +++----
 NetCore.Test/CacheUnitTest.cs         | 15 +++----
 NetCore.Test/ObjectLeakUnitTest.cs    |  2 +-
 NetCore.Test/PoolFactoryUnitTest.cs   | 73 ++++++++++++++++++-----------------
 NetCore.Test/PoolManagerUnitTest.cs   | 14 +++----
 NetCore.Test/RegionFactoryUnitTest.cs | 32 ++++++++-------
 NetCore/Cache.cs                      | 10 ++++-
 NetCore/CacheFactory.cs               | 10 ++---
 NetCore/GeodeNativeObject.cs          |  7 ++++
 NetCore/PoolFactory.cs                |  6 ---
 10 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/NetCore.Test/CacheFactoryUnitTest.cs 
b/NetCore.Test/CacheFactoryUnitTest.cs
index 20b246a..6dee7fe 100644
--- a/NetCore.Test/CacheFactoryUnitTest.cs
+++ b/NetCore.Test/CacheFactoryUnitTest.cs
@@ -16,7 +16,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     Assert.IsNotNull(cacheFactory);
                 }
@@ -28,7 +28,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     var version = cacheFactory.Version;
                     Assert.AreNotEqual(version, String.Empty);
@@ -43,7 +43,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     var description = cacheFactory.ProductDescription;
                     Assert.AreNotEqual(description, String.Empty);
@@ -58,7 +58,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     cacheFactory.PdxIgnoreUnreadFields = true;
                     cacheFactory.PdxIgnoreUnreadFields = false;
@@ -73,7 +73,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     cacheFactory.PdxReadSerialized = true;
                     cacheFactory.PdxReadSerialized = false;
@@ -88,7 +88,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     using (var cache = cacheFactory.CreateCache())
                     {
@@ -105,7 +105,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
                     cacheFactory.SetProperty("log-level", "none")
                         .SetProperty("log-file", "geode_native.log");
diff --git a/NetCore.Test/CacheUnitTest.cs b/NetCore.Test/CacheUnitTest.cs
index 20eced5..65de6e0 100644
--- a/NetCore.Test/CacheUnitTest.cs
+++ b/NetCore.Test/CacheUnitTest.cs
@@ -17,7 +17,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "debug")
                     .SetProperty("log-file", 
"TestClientCacheGetPdxReadSerialized.log"))
                 {
@@ -51,7 +51,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "none")
                     .SetProperty("log-file", "geode_native.log"))
                 {
@@ -77,7 +77,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "none")
                     .SetProperty("log-file", "geode_native.log"))
                 {
@@ -85,6 +85,7 @@ namespace GemfireDotNetTest
                     using (var cache = cacheFactory.CreateCache())
                     {
                         var poolManager = cache.PoolManager;
+                        poolManager.Dispose();
                     }
                 }
 
@@ -97,7 +98,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "none")
                     .SetProperty("log-file", "geode_native.log"))
                 {
@@ -120,7 +121,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "none"))
                 {
                     cacheFactory.PdxIgnoreUnreadFields = true;
@@ -140,7 +141,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "none"))
                 {
                     cacheFactory.PdxIgnoreUnreadFields = true;
@@ -161,7 +162,7 @@ namespace GemfireDotNetTest
         {
             using (var client = new Client())
             {
-                using (var cacheFactory = CacheFactory.Create()
+                using (var cacheFactory = CacheFactory.Create(client)
                     .SetProperty("log-level", "none"))
                 {
                     cacheFactory.PdxIgnoreUnreadFields = true;
diff --git a/NetCore.Test/ObjectLeakUnitTest.cs 
b/NetCore.Test/ObjectLeakUnitTest.cs
index a266d6e..93c51c2 100644
--- a/NetCore.Test/ObjectLeakUnitTest.cs
+++ b/NetCore.Test/ObjectLeakUnitTest.cs
@@ -16,7 +16,7 @@ namespace GemfireDotNetTest
         {
             var client = new Client();
             
-            using (var cacheFactory = CacheFactory.Create())
+            using (var cacheFactory = CacheFactory.Create(client))
             {
                 Assert.Throws<InvalidOperationException>(() => 
client.Dispose());
             }
diff --git a/NetCore.Test/PoolFactoryUnitTest.cs 
b/NetCore.Test/PoolFactoryUnitTest.cs
index 7e9ccb8..349b48a 100644
--- a/NetCore.Test/PoolFactoryUnitTest.cs
+++ b/NetCore.Test/PoolFactoryUnitTest.cs
@@ -14,17 +14,20 @@ namespace GemfireDotNetTest
         [Test]
         public void TestPoolFactoryAddLocator()
         {
-            using (var cacheFactory = CacheFactory.Create()
-                    .SetProperty("log-level", "none")
-                    .SetProperty("log-file", "geode_native.log"))
+            using (var client = new Client())
             {
-                using (var cache = cacheFactory.CreateCache())
+                using (var cacheFactory = CacheFactory.Create(client)
+                        .SetProperty("log-level", "none")
+                        .SetProperty("log-file", "geode_native.log"))
                 {
-                    using (var poolManager = cache.PoolManager)
+                    using (var cache = cacheFactory.CreateCache())
                     {
-                        using (var poolFactory = 
poolManager.CreatePoolFactory())
+                        using (var poolManager = cache.PoolManager)
                         {
-                            poolFactory.AddLocator("localhost", 10334);
+                            using (var poolFactory = 
poolManager.CreatePoolFactory())
+                            {
+                              poolFactory.AddLocator("localhost", 10334);
+                            }
                         }
                     }
                 }
@@ -35,51 +38,51 @@ namespace GemfireDotNetTest
         [Test]
         public void TestPoolFactoryCreatePool()
         {
-            using (var cacheFactory = CacheFactory.Create()
-                    .SetProperty("log-level", "none")
-                    .SetProperty("log-file", "geode_native.log"))
+            using (var client = new Client())
             {
-                using (var cache = cacheFactory.CreateCache())
+                using (var cacheFactory = CacheFactory.Create(client)
+                        .SetProperty("log-level", "none")
+                        .SetProperty("log-file", "geode_native.log"))
                 {
-                    using (var poolManager = cache.PoolManager)
+                    using (var cache = cacheFactory.CreateCache())
                     {
-                        using (var poolFactory = 
poolManager.CreatePoolFactory())
+                        using (var poolManager = cache.PoolManager)
                         {
-                            poolFactory.AddLocator("localhost", 10334);
-                            using (var pool = poolFactory.CreatePool("myPool"))
+                            using (var poolFactory = 
poolManager.CreatePoolFactory())
                             {
-                                ;
+                                poolFactory.AddLocator("localhost", 10334);
+                                using (var pool = 
poolFactory.CreatePool("myPool"))
+                                {
+                                    ;
+                                }
                             }
                         }
                     }
                 }
+                Assert.Pass();
             }
-            Assert.Pass();
         }
 
         [Test]
         public void TestCreatePoolWithoutPoolManager()
         {
-          using (var cacheFactory = CacheFactory.Create()
-                  .SetProperty("log-level", "none")
-                  .SetProperty("log-file", "geode_native.log"))
-          {
-            using (var cache = cacheFactory.CreateCache())
+            using (var client = new Client())
             {
-              using (var poolFactory = cache.PoolFactory)
-              {
-                //using (var poolFactory = poolManager.CreatePoolFactory())
-                //{
-                  poolFactory.AddLocator("localhost", 10334);
-                  using (var pool = poolFactory.CreatePool("myPool"))
-                  {
-                    ;
-                  }
-                //}
-              }
+                using (var cacheFactory = CacheFactory.Create(client))
+                {
+                    using (var cache = cacheFactory.CreateCache())
+                    {
+                        using (var poolFactory = cache.PoolFactory)
+                        {
+                            poolFactory.AddLocator("localhost", 10334);
+                            using (var pool = poolFactory.CreatePool("myPool"))
+                            {
+                            }
+                        }
+                    }
+                }
+                Assert.Pass();
             }
-          }
-          Assert.Pass();
         }
   }
 }
diff --git a/NetCore.Test/PoolManagerUnitTest.cs 
b/NetCore.Test/PoolManagerUnitTest.cs
index bd387c8..88fef25 100644
--- a/NetCore.Test/PoolManagerUnitTest.cs
+++ b/NetCore.Test/PoolManagerUnitTest.cs
@@ -14,17 +14,17 @@ namespace GemfireDotNetTest
         [Test]
         public void TestPoolManagerCreatePoolFactory()
         {
-            using (var cacheFactory = CacheFactory.Create()
-                    .SetProperty("log-level", "none")
-                    .SetProperty("log-file", "geode_native.log"))
+            using (var client = new Client())
             {
-                using (var cache = cacheFactory.CreateCache())
+                using (var cacheFactory = CacheFactory.Create(client))
                 {
-                    using (var poolManager = cache.PoolManager)
+                    using (var cache = cacheFactory.CreateCache())
                     {
-                        using (var poolFactory = 
poolManager.CreatePoolFactory())
+                        using (var poolManager = cache.PoolManager)
                         {
-                            ;
+                            using (var poolFactory = 
poolManager.CreatePoolFactory())
+                            {
+                            }
                         }
                     }
                 }
diff --git a/NetCore.Test/RegionFactoryUnitTest.cs 
b/NetCore.Test/RegionFactoryUnitTest.cs
index 211fde3..d90e7b1 100644
--- a/NetCore.Test/RegionFactoryUnitTest.cs
+++ b/NetCore.Test/RegionFactoryUnitTest.cs
@@ -90,14 +90,17 @@ namespace GemfireDotNetTest
         [Test]
         public void TestRegionFactoryCreateProxyRegion()
         {
-            using (var cacheFactory = CacheFactory.Create()
-                .SetProperty("log-level", "none")
-                .SetProperty("log-file", "geode_native.log"))
+            using (var client = new Client())
             {
-                using (var cache = cacheFactory.CreateCache())
+                using (var cacheFactory = CacheFactory.Create(client)
+                    .SetProperty("log-level", "none")
+                    .SetProperty("log-file", "geode_native.log"))
                 {
-                    createPool(cache, 10334);
-                    CreateRegionAndDoWork(cache, "exampleRegion", 
RegionShortcut.Proxy);
+                    using (var cache = cacheFactory.CreateCache())
+                    {
+                        createPool(cache, 10334);
+                        CreateRegionAndDoWork(cache, "exampleRegion", 
RegionShortcut.Proxy);
+                    }
                 }
             }
             Assert.Pass();
@@ -106,15 +109,18 @@ namespace GemfireDotNetTest
         [Test]
         public void TestRegionFactoryCreateRegionWithAuthentication()
         {
-            using (var cacheFactory = CacheFactory.Create()
-                .SetProperty("log-level", "debug")
-                .SetProperty("log-file", "geode_native_with_auth.log"))
+            using (var client = new Client())
             {
-                cacheFactory.AuthInitialize = new SimpleAuthInitialize();
-                using (var cache = cacheFactory.CreateCache())
+                using (var cacheFactory = CacheFactory.Create(client)
+                    .SetProperty("log-level", "debug")
+                    .SetProperty("log-file", "geode_native_with_auth.log"))
                 {
-                    createPool(cache, 10335);
-                    CreateRegionAndDoWork(cache, "authExampleRegion", 
RegionShortcut.CachingProxy);
+                    cacheFactory.AuthInitialize = new SimpleAuthInitialize();
+                    using (var cache = cacheFactory.CreateCache())
+                    {
+                        createPool(cache, 10335);
+                        CreateRegionAndDoWork(cache, "authExampleRegion", 
RegionShortcut.CachingProxy);
+                    }
                 }
             }
             Assert.Pass();
diff --git a/NetCore/Cache.cs b/NetCore/Cache.cs
index de5cb07..27d087e 100644
--- a/NetCore/Cache.cs
+++ b/NetCore/Cache.cs
@@ -14,7 +14,6 @@ namespace Apache
                 private string _name = String.Empty;
                 private PoolManager _poolManager = null;
                 private PoolFactory _poolFactory = null;
-                private bool _closed = false;
                 private IAuthInitialize _authInitialize;
                 private GetCredentialsDelegateInternal _getCredentialsDelegate;
                 private CloseDelegateInternal _closeDelegate;
@@ -161,6 +160,15 @@ namespace Apache
 
                 protected override void DestroyContainedObject()
                 {
+                    // It turns out, C# "wrapper" objects need to get rid of
+                    // *all* contained objects, due to vagaries of Geode 
+                    // Native object graph, in order to ensure a leak-free
+                    // shutdown.  We get rid of our non-cache objects first
+                    // here, in case it makes a difference.
+                    _poolManager?.Dispose();
+                    _poolManager = null;
+                    _poolFactory?.Dispose();
+                    _poolFactory = null;
                     apache_geode_DestroyCache(_containedObject);
                     _containedObject = IntPtr.Zero;
                 }
diff --git a/NetCore/CacheFactory.cs b/NetCore/CacheFactory.cs
index 4c2fad1..1a15d27 100644
--- a/NetCore/CacheFactory.cs
+++ b/NetCore/CacheFactory.cs
@@ -14,7 +14,7 @@ namespace Apache
                 private IAuthInitialize _authInitialize;
 
                 [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
-                private static extern IntPtr apache_geode_CreateCacheFactory();
+                private static extern IntPtr 
apache_geode_CreateCacheFactory(IntPtr client);
 
                 [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
                 private static extern void 
apache_geode_DestroyCacheFactory(IntPtr factory);
@@ -35,14 +35,14 @@ namespace Apache
                 [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
                 private static extern void 
apache_geode_CacheFactory_SetProperty(IntPtr factory, IntPtr key, IntPtr value);
 
-                public static ICacheFactory Create()
+                public static ICacheFactory Create(Client client)
                 {
-                    return new CacheFactory();
+                    return new CacheFactory(client);
                 }
 
-                public CacheFactory()
+                public CacheFactory(GeodeNativeObject client)
                 {
-                    _containedObject = apache_geode_CreateCacheFactory();
+                    _containedObject = 
apache_geode_CreateCacheFactory(client.ContainedObject);
                 }
 
                 public string Version
diff --git a/NetCore/GeodeNativeObject.cs b/NetCore/GeodeNativeObject.cs
index 293b142..390f59f 100644
--- a/NetCore/GeodeNativeObject.cs
+++ b/NetCore/GeodeNativeObject.cs
@@ -18,6 +18,13 @@ namespace Apache
                     GC.SuppressFinalize(this);
                 }
 
+                public IntPtr ContainedObject {
+                    get 
+                    {
+                        return _containedObject;
+                    }
+                }
+                
                 protected virtual void Dispose(bool disposing)
                 {
                     if (_disposed)
diff --git a/NetCore/PoolFactory.cs b/NetCore/PoolFactory.cs
index dc405bd..4e8f9dc 100644
--- a/NetCore/PoolFactory.cs
+++ b/NetCore/PoolFactory.cs
@@ -43,12 +43,6 @@ namespace Apache
                     return new Pool(_containedObject, poolName);
                 }
 
-                public void Dispose()
-                {
-                    Dispose(true);
-                    GC.SuppressFinalize(this);
-                }
-
                 protected override void DestroyContainedObject()
                 {
                     apache_geode_DestroyPoolFactory(_containedObject);

Reply via email to