Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Update to get in sync with recent changes in native
- apache_geode_CreateCacheFactory takes a client parameter
  • Loading branch information
Blake Bender committed May 26, 2021
1 parent 0df0672 commit c885c1ef2d4786fdffe1019c3dfa7b2c39e1f7f5
Showing 10 changed files with 101 additions and 82 deletions.
@@ -16,7 +16,7 @@ public void TestCreateFactory()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create())
using (var cacheFactory = CacheFactory.Create(client))
{
Assert.IsNotNull(cacheFactory);
}
@@ -28,7 +28,7 @@ public void TestCacheFactoryGetVersion()
{
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 @@ public void TestCacheFactoryGetProductDescription()
{
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 @@ public void TestCacheFactorySetPdxIgnoreUnreadFields()
{
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 @@ public void TestCacheFactorySetPdxReadSerialized()
{
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 @@ public void TestCacheFactoryCreateCache()
{
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 @@ public void TestCacheFactorySetProperty()
{
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");
@@ -17,7 +17,7 @@ public void TestClientCacheGetPdxReadSerialized()
{
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 @@ public void TestClientCacheGetPdxIgnoreUnreadFields()
{
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,14 +77,15 @@ public void TestClientCacheGetPoolManager()
{
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"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
var poolManager = cache.PoolManager;
poolManager.Dispose();
}
}

@@ -97,7 +98,7 @@ public void TestClientCacheCreateRegionFactory()
{
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 @@ public void TestClientCacheGetName()
{
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 @@ public void TestClientCacheClose()
{
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 @@ public void TestClientCacheCloseWithKeepalive()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
using (var cacheFactory = CacheFactory.Create(client)
.SetProperty("log-level", "none"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
@@ -16,7 +16,7 @@ public void TestLeakCacheFactory()
{
var client = new Client();

using (var cacheFactory = CacheFactory.Create())
using (var cacheFactory = CacheFactory.Create(client))
{
Assert.Throws<InvalidOperationException>(() => client.Dispose());
}
@@ -14,17 +14,20 @@ public void Setup()
[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 @@ public void TestPoolFactoryAddLocator()
[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();
}
}
}
@@ -14,17 +14,17 @@ public void Setup()
[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())
{
}
}
}
}
@@ -90,14 +90,17 @@ private void CreateRegionAndDoWork(IGeodeCache cache, string regionName, RegionS
[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 @@ public void TestRegionFactoryCreateProxyRegion()
[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();
@@ -14,7 +14,6 @@ public class Cache : GeodeNativeObject, IGeodeCache
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 @@ public RegionFactory CreateRegionFactory(RegionShortcut regionType)

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;
}
@@ -14,7 +14,7 @@ public class CacheFactory : GeodeNativeObject, ICacheFactory
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 @@ public class CacheFactory : GeodeNativeObject, ICacheFactory
[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
@@ -18,6 +18,13 @@ public void Dispose()
GC.SuppressFinalize(this);
}

public IntPtr ContainedObject {
get
{
return _containedObject;
}
}

protected virtual void Dispose(bool disposing)
{
if (_disposed)

0 comments on commit c885c1e

Please sign in to comment.