You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/03/20 16:54:45 UTC
[3/3] geode-native git commit: GEODE-2657: Tests Function Execution
with AppDomains.
GEODE-2657: Tests Function Execution with AppDomains.
This closes #54.
This closes #63.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/b4fe674a
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/b4fe674a
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/b4fe674a
Branch: refs/heads/develop
Commit: b4fe674a127695836f0351e49f1c06c7b818114e
Parents: d4d4a93
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Sat Mar 18 00:21:20 2017 +0000
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Mon Mar 20 09:53:55 2017 -0700
----------------------------------------------------------------------
...ThinClientAppDomainFunctionExecutionTests.cs | 282 +++++++++++++++++++
.../integration-test/UnitTests.csproj.in | 1 +
src/clicache/src/CacheFactory.cpp | 7 +
src/clicache/src/DistributedSystem.cpp | 4 -
4 files changed, 290 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/b4fe674a/src/clicache/integration-test/ThinClientAppDomainFunctionExecutionTests.cs
----------------------------------------------------------------------
diff --git a/src/clicache/integration-test/ThinClientAppDomainFunctionExecutionTests.cs b/src/clicache/integration-test/ThinClientAppDomainFunctionExecutionTests.cs
new file mode 100644
index 0000000..c238118
--- /dev/null
+++ b/src/clicache/integration-test/ThinClientAppDomainFunctionExecutionTests.cs
@@ -0,0 +1,282 @@
+//=========================================================================
+// Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+// This product is protected by U.S. and international copyright
+// and intellectual property laws. Pivotal products are covered by
+// more patents listed at http://www.pivotal.io/patents.
+//========================================================================
+
+using System;
+using System.Collections.Generic;
+using System.Collections;
+using System.Threading;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client.Tests;
+
+ using Apache.Geode.Client;
+ using Region = Apache.Geode.Client.IRegion<Object, Object>;
+
+ public class MyAppDomainResultCollector<TResult> : IResultCollector<TResult>
+ {
+ #region Private members
+ private bool m_resultReady = false;
+ ICollection<TResult> m_results = null;
+ private int m_addResultCount = 0;
+ private int m_getResultCount = 0;
+ private int m_endResultCount = 0;
+ #endregion
+ public int GetAddResultCount()
+ {
+ return m_addResultCount;
+ }
+ public int GetGetResultCount()
+ {
+ return m_getResultCount;
+ }
+ public int GetEndResultCount()
+ {
+ return m_endResultCount;
+ }
+ public MyAppDomainResultCollector()
+ {
+ m_results = new List<TResult>();
+ }
+ public void AddResult(TResult result)
+ {
+ Util.Log("MyAppDomainResultCollector " + result + " : " + result.GetType());
+ m_addResultCount++;
+ m_results.Add(result);
+ }
+ public ICollection<TResult> GetResult()
+ {
+ return GetResult(50);
+ }
+
+ public ICollection<TResult> GetResult(UInt32 timeout)
+ {
+ m_getResultCount++;
+ if (m_resultReady == true)
+ {
+ return m_results;
+ }
+ else
+ {
+ for (int i = 0; i < timeout; i++)
+ {
+ Thread.Sleep(1000);
+ if (m_resultReady == true)
+ {
+ return m_results;
+ }
+
+ }
+ throw new FunctionExecutionException(
+ "Result is not ready, endResults callback is called before invoking getResult() method");
+
+ }
+ }
+ public void EndResults()
+ {
+ m_endResultCount++;
+ m_resultReady = true;
+ }
+ public void ClearResults(/*bool unused*/)
+ {
+ m_results.Clear();
+ m_addResultCount = 0;
+ m_getResultCount = 0;
+ m_endResultCount = 0;
+ }
+ }
+
+
+ [TestFixture]
+ [Category("group3")]
+ [Category("unicast_only")]
+ [Category("generics")]
+ public class ThinClientAppDomainFunctionExecutionTests : ThinClientRegionSteps
+ {
+ #region Private members
+
+ private static string[] FunctionExecutionRegionNames = { "partition_region", "partition_region1" };
+ private static string poolName = "__TEST_POOL1__";
+ private static string serverGroup = "ServerGroup1";
+ private static string QERegionName = "partition_region";
+ private static string OnServerHAExceptionFunction = "OnServerHAExceptionFunction";
+ private static string OnServerHAShutdownFunction = "OnServerHAShutdownFunction";
+
+ #endregion
+
+ protected override ClientBase[] GetClients()
+ {
+ return new ClientBase[] { };
+ }
+
+ [TestFixtureSetUp]
+ public override void InitTests()
+ {
+ Util.Log("InitTests: AppDomain: " + AppDomain.CurrentDomain.Id);
+ Properties<string, string> config = new Properties<string, string>();
+ config.Insert("appdomain-enabled", "true");
+ CacheHelper.InitConfig(config);
+ }
+
+ [TearDown]
+ public override void EndTest()
+ {
+ Util.Log("EndTest: AppDomain: " + AppDomain.CurrentDomain.Id);
+ try
+ {
+ CacheHelper.ClearEndpoints();
+ CacheHelper.ClearLocators();
+ }
+ finally
+ {
+ CacheHelper.StopJavaServers();
+ CacheHelper.StopJavaLocators();
+ }
+ base.EndTest();
+ }
+
+ public void createRegionAndAttachPool(string regionName, string poolName)
+ {
+ CacheHelper.CreateTCRegion_Pool<object, object>(regionName, true, true, null, null, poolName, false, serverGroup);
+ }
+ public void createPool(string name, string locators, string serverGroup,
+ int redundancy, bool subscription, bool prSingleHop, bool threadLocal = false)
+ {
+ CacheHelper.CreatePool<object, object>(name, locators, serverGroup, redundancy, subscription, prSingleHop, threadLocal);
+ }
+
+ public void OnServerHAStepOne()
+ {
+
+ Region region = CacheHelper.GetVerifyRegion<object, object>(QERegionName);
+ for (int i = 0; i < 34; i++)
+ {
+ region["KEY--" + i] = "VALUE--" + i;
+ }
+
+ object[] routingObj = new object[17];
+
+ ArrayList args1 = new ArrayList();
+
+ int j = 0;
+ for (int i = 0; i < 34; i++)
+ {
+ if (i % 2 == 0) continue;
+ routingObj[j] = "KEY--" + i;
+ j++;
+ }
+ Util.Log("routingObj count= {0}.", routingObj.Length);
+
+ for (int i = 0; i < routingObj.Length; i++)
+ {
+ Console.WriteLine("routingObj[{0}]={1}.", i, (string)routingObj[i]);
+ args1.Add(routingObj[i]);
+ }
+
+ Boolean getResult = true;
+ //test data independant function execution with result onServer
+ Pool/*<TKey, TValue>*/ pool = PoolManager/*<TKey, TValue>*/.Find(poolName);
+
+ Apache.Geode.Client.Execution<object> exc = FunctionService<object>.OnServer(pool);
+ Assert.IsTrue(exc != null, "onServer Returned NULL");
+
+ IResultCollector<object> rc = exc.WithArgs<ArrayList>(args1).Execute(OnServerHAExceptionFunction, 15);
+
+ ICollection<object> executeFunctionResult = rc.GetResult();
+
+ List<object> resultList = new List<object>();
+
+ Console.WriteLine("executeFunctionResult.Length = {0}", executeFunctionResult.Count);
+
+ foreach (List<object> item in executeFunctionResult)
+ {
+ foreach (object item2 in item)
+ {
+ resultList.Add(item2);
+ }
+ }
+
+ Util.Log("on region: result count= {0}.", resultList.Count);
+ Assert.IsTrue(resultList.Count == 17, "result count check failed");
+ for (int i = 0; i < resultList.Count; i++)
+ {
+ Util.Log("on region:get:result[{0}]={1}.", i, (string)resultList[i]);
+ Assert.IsTrue(((string)resultList[i]) != null, "onServer Returned NULL");
+ }
+
+ rc = exc.WithArgs<ArrayList>(args1).Execute(OnServerHAShutdownFunction, 15);
+
+ ICollection<object> executeFunctionResult1 = rc.GetResult();
+
+ List<object> resultList1 = new List<object>();
+
+ foreach (List<object> item in executeFunctionResult1)
+ {
+ foreach (object item2 in item)
+ {
+ resultList1.Add(item2);
+ }
+ }
+
+ Util.Log("on region: result count= {0}.", resultList1.Count);
+
+ Console.WriteLine("resultList1.Count = {0}", resultList1.Count);
+
+ Assert.IsTrue(resultList1.Count == 17, "result count check failed");
+ for (int i = 0; i < resultList1.Count; i++)
+ {
+ Util.Log("on region:get:result[{0}]={1}.", i, (string)resultList1[i]);
+ Assert.IsTrue(((string)resultList1[i]) != null, "onServer Returned NULL");
+ }
+
+ // Bring down the region
+ //region.LocalDestroyRegion();
+ }
+
+ [Test]
+ public void OnServerHAExecuteFunction()
+ {
+ Util.Log("OnServerHAExecuteFunction: AppDomain: " + AppDomain.CurrentDomain.Id);
+ CacheHelper.SetupJavaServers(true, "func_cacheserver1_pool.xml",
+ "func_cacheserver2_pool.xml", "func_cacheserver3_pool.xml");
+ CacheHelper.StartJavaLocator(1, "GFELOC");
+ Util.Log("Locator 1 started.");
+ CacheHelper.StartJavaServerWithLocators(1, "GFECS1", 1);
+ Util.Log("Cacheserver 1 started.");
+ CacheHelper.StartJavaServerWithLocators(2, "GFECS2", 1);
+ Util.Log("Cacheserver 2 started.");
+ CacheHelper.StartJavaServerWithLocators(3, "GFECS3", 1);
+ Util.Log("Cacheserver 3 started.");
+
+ createPool(poolName, CacheHelper.Locators, serverGroup, 1, true, true, /*threadLocal*/true);
+ createRegionAndAttachPool(QERegionName, poolName);
+ Util.Log("Client 1 (pool locator) regions created");
+
+ OnServerHAStepOne();
+
+ Close();
+ Util.Log("Client 1 closed");
+
+ CacheHelper.StopJavaServer(1);
+ Util.Log("Cacheserver 1 stopped.");
+
+ CacheHelper.StopJavaServer(2);
+ Util.Log("Cacheserver 2 stopped.");
+
+ CacheHelper.StopJavaServer(3);
+ Util.Log("Cacheserver 3 stopped.");
+
+ CacheHelper.StopJavaLocator(1);
+ Util.Log("Locator 1 stopped.");
+
+ CacheHelper.ClearEndpoints();
+ CacheHelper.ClearLocators();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/b4fe674a/src/clicache/integration-test/UnitTests.csproj.in
----------------------------------------------------------------------
diff --git a/src/clicache/integration-test/UnitTests.csproj.in b/src/clicache/integration-test/UnitTests.csproj.in
index df7ab71..328c1ab 100644
--- a/src/clicache/integration-test/UnitTests.csproj.in
+++ b/src/clicache/integration-test/UnitTests.csproj.in
@@ -183,6 +183,7 @@
<Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\ThinClientSecurityAuthzTestsN.cs" />
<Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\ThinClientQueryTestsN.cs" />
<Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\ThinClientAppDomainQueryTests.cs" />
+ <Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\ThinClientAppDomainFunctionExecutionTests.cs" />
<Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\BuiltinCacheableWrappersN.cs" />
<Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\CacheableWrapperN.cs" />
<Compile Include="$(CMAKE_CURRENT_SOURCE_DIR)\DupListenerN.cs" />
http://git-wip-us.apache.org/repos/asf/geode-native/blob/b4fe674a/src/clicache/src/CacheFactory.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CacheFactory.cpp b/src/clicache/src/CacheFactory.cpp
index 7c84ac1..02420e8 100644
--- a/src/clicache/src/CacheFactory.cpp
+++ b/src/clicache/src/CacheFactory.cpp
@@ -28,6 +28,7 @@
//#pragma warning(disable:4091)
//#include <msclr/lock.h>
//#pragma warning(disable:4091)
+#include "impl/AppDomainContext.hpp"
using namespace System;
@@ -84,6 +85,12 @@ namespace Apache
//TODO::split
SafeConvertClassGeneric::SetAppDomainEnabled(appDomainEnable);
+ if (appDomainEnable)
+ {
+ // Register managed AppDomain context with unmanaged.
+ apache::geode::client::createAppDomainContext = &Apache::Geode::Client::createAppDomainContext;
+ }
+
Serializable::RegisterTypeGeneric(
apache::geode::client::GeodeTypeIds::PdxType,
gcnew TypeFactoryMethodGeneric(Apache::Geode::Client::Internal::PdxType::CreateDeserializable),
http://git-wip-us.apache.org/repos/asf/geode-native/blob/b4fe674a/src/clicache/src/DistributedSystem.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/DistributedSystem.cpp b/src/clicache/src/DistributedSystem.cpp
index cdc8bf2..f170a5b 100644
--- a/src/clicache/src/DistributedSystem.cpp
+++ b/src/clicache/src/DistributedSystem.cpp
@@ -53,7 +53,6 @@
#include "impl/PdxType.hpp"
#include "impl/EnumInfo.hpp"
#include "impl/ManagedPersistenceManager.hpp"
-#include "impl/AppDomainContext.hpp"
// disable spurious warning
#pragma warning(disable:4091)
@@ -752,9 +751,6 @@ namespace Apache
{
//to create .net memory pressure handler
Create(apache::geode::client::DistributedSystem::getInstance().ptr());
-
- // Register managed AppDomain context with unmanaged.
- apache::geode::client::createAppDomainContext = &Apache::Geode::Client::createAppDomainContext;
}
void DistributedSystem::UnregisterBuiltinManagedTypes()