Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix parallel test running
- Geode 'Client' is a singleton, so needs to be a global resource in
  tests
- XUnit uses a 'Collection' for this, so added NetCoreCollectionFixture
  and NetCoreCollection classes.  Now Client is created before any tests
  run, and torn down when the last test completes.
  • Loading branch information
Blake Bender committed Jun 10, 2021
1 parent 1de160e commit e484ef50291d6e3faa66833d0b68039362b26591
Showing 8 changed files with 172 additions and 282 deletions.
@@ -4,97 +4,77 @@

namespace GemfireDotNetTest
{
public class CacheFactoryUnitTests
[Collection("Geode .net Core Collection")]
public class CacheFactoryUnitTests
{
[Fact]
public void TestCreateFactory()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
{
Assert.NotNull(cacheFactory);
}
Assert.NotNull(cacheFactory);
}
}

[Fact]
public void TestCacheFactoryGetVersion()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
{
var version = cacheFactory.Version;
Assert.NotEqual(version, String.Empty);
}
var version = cacheFactory.Version;
Assert.NotEqual(version, String.Empty);
}
}

[Fact]
public void TestCacheFactoryGetProductDescription()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
{
var description = cacheFactory.ProductDescription;
Assert.NotEqual(description, String.Empty);
}
var description = cacheFactory.ProductDescription;
Assert.NotEqual(description, String.Empty);
}
}

[Fact]
public void TestCacheFactorySetPdxIgnoreUnreadFields()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
{
cacheFactory.PdxIgnoreUnreadFields = true;
cacheFactory.PdxIgnoreUnreadFields = false;
}
cacheFactory.PdxIgnoreUnreadFields = true;
cacheFactory.PdxIgnoreUnreadFields = false;
}
}

[Fact]
public void TestCacheFactorySetPdxReadSerialized()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
{
cacheFactory.PdxReadSerialized = true;
cacheFactory.PdxReadSerialized = false;
}
cacheFactory.PdxReadSerialized = true;
cacheFactory.PdxReadSerialized = false;
}
}

[Fact]
public void TestCacheFactoryCreateCache()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
using (var cache = cacheFactory.CreateCache())
{
using (var cache = cacheFactory.CreateCache())
{
;
}
;
}
}
}

[Fact]
public void TestCacheFactorySetProperty()
{
using (var client = new Client())
using (var cacheFactory = CacheFactory.Create())
{
using (var cacheFactory = CacheFactory.Create())
{
cacheFactory.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log");
}
cacheFactory.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log");
}
}
}
@@ -5,166 +5,115 @@

namespace GemfireDotNetTest
{
[Collection("Geode .net Core Collection")]
public class CacheUnitTests
{
[Fact]
public void TestClientCacheGetPdxReadSerialized()
{
using (var client = new Client())
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "debug")
.SetProperty("log-file", "TestClientCacheGetPdxReadSerialized.log");
try
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "debug")
.SetProperty("log-file", "TestClientCacheGetPdxReadSerialized.log"))
{
try
{
cacheFactory.PdxReadSerialized = true;
using (var cache = cacheFactory.CreateCache())
{
Assert.True(cache.GetPdxReadSerialized());
}
cacheFactory.PdxReadSerialized = true;
using var cache = cacheFactory.CreateCache();

cacheFactory.PdxReadSerialized = false;
using (var otherCache = cacheFactory.CreateCache())
{
Assert.False(otherCache.GetPdxReadSerialized());
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
Assert.True(cache.GetPdxReadSerialized());

cacheFactory.PdxReadSerialized = false;
using var otherCache = cacheFactory.CreateCache();

Assert.False(otherCache.GetPdxReadSerialized());
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}

[Fact]
public void TestClientCacheGetPdxIgnoreUnreadFields()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
Assert.True(cache.GetPdxIgnoreUnreadFields());
}
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log");
cacheFactory.PdxIgnoreUnreadFields = true;
using var cache = cacheFactory.CreateCache();

cacheFactory.PdxIgnoreUnreadFields = false;
using (var otherCache = cacheFactory.CreateCache())
{
Assert.False(otherCache.GetPdxIgnoreUnreadFields());
}
}
}
Assert.True(cache.GetPdxIgnoreUnreadFields());

cacheFactory.PdxIgnoreUnreadFields = false;
using var otherCache = cacheFactory.CreateCache();
Assert.False(otherCache.GetPdxIgnoreUnreadFields());
}

[Fact]
public void TestClientCacheGetPoolManager()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
var poolManager = cache.PoolManager;
poolManager.Dispose();
}
}
}
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log");

cacheFactory.PdxIgnoreUnreadFields = true;
using var cache = cacheFactory.CreateCache();
using var poolManager = cache.PoolManager;
}

[Fact]
public void TestClientCacheCreateRegionFactory()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
using (var regionFactory = cache.CreateRegionFactory(RegionShortcut.Proxy))
{
;
}
}
}
}
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log");
cacheFactory.PdxIgnoreUnreadFields = true;
using var cache = cacheFactory.CreateCache();
using var regionFactory = cache.CreateRegionFactory(RegionShortcut.Proxy);
}

[Fact]
public void TestClientCacheGetName()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
var cacheName = cache.Name;
Assert.NotEqual(cacheName, String.Empty);
}
}
}
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none");
cacheFactory.PdxIgnoreUnreadFields = true;
using var cache = cacheFactory.CreateCache();

var cacheName = cache.Name;
Assert.NotEqual(cacheName, String.Empty);
}

[Fact]
public void TestClientCacheClose()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
Assert.False(cache.Closed);
cache.Close();
Assert.True(cache.Closed);
}
}
}
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none");
cacheFactory.PdxIgnoreUnreadFields = true;
using var cache = cacheFactory.CreateCache();

Assert.False(cache.Closed);
cache.Close();
Assert.True(cache.Closed);
}

[Fact]
public void TestClientCacheCloseWithKeepalive()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none"))
{
cacheFactory.PdxIgnoreUnreadFields = true;
using (var cache = cacheFactory.CreateCache())
{
Assert.False(cache.Closed);
cache.Close(true);
Assert.True(cache.Closed);
using var cacheFactory = CacheFactory.Create()
.SetProperty("log-level", "none");
cacheFactory.PdxIgnoreUnreadFields = true;
using var cache = cacheFactory.CreateCache();

Assert.False(cache.Closed);
cache.Close(true);
Assert.True(cache.Closed);

}
using var otherCache = cacheFactory.CreateCache();

using (var otherCache = cacheFactory.CreateCache())
{
Assert.False(otherCache.Closed);
otherCache.Close(false);
Assert.True(otherCache.Closed);
}
}
}
Assert.False(otherCache.Closed);
otherCache.Close(false);
Assert.True(otherCache.Closed);
}
}
}
@@ -0,0 +1,22 @@
using System;
using Apache.Geode.NetCore;
using Xunit;

public class NetCoreCollectionFixture : IDisposable
{
public NetCoreCollectionFixture()
{
client_ = new Client();
}
public void Dispose()
{
client_.Dispose();
}

Client client_;
}

[CollectionDefinition("Geode .net Core Collection")]
public class NetCoreCollection : ICollectionFixture<NetCoreCollectionFixture>
{
}
@@ -4,7 +4,8 @@

namespace GemfireDotNetTest
{
public class ObjectLeakUnitTests
[Collection("Geode .net Core Collection")]
public class ObjectLeakUnitTests
{
[Fact]
public void TestLeakCacheFactory()

0 comments on commit e484ef5

Please sign in to comment.