in clicache/integration-test/ThinClientFunctionExecutionTestsN.cs [225:419]
public void PoolStepOne(string locators)
{
IRegion<object, object> region = CacheHelper.GetVerifyRegion<object, object>(QERegionName);
for (int i = 0; i < 230; i++)
{
region["KEY--" + i] = "VALUE--" + i;
}
Object[] routingObj = new Object[17];
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);
object args = true;
//test data dependant function execution
// test get function with result
Apache.Geode.Client.Execution<object> exc = Client.FunctionService<object>.OnRegion<object, object>(region);
Client.IResultCollector<object> rc = exc.WithArgs<object>(args).WithFilter<object>(routingObj).Execute(getFuncName);
ICollection<object> executeFunctionResult = rc.GetResult();
List<object> resultList = new List<object>();
//resultList.Clear();
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 == 34, "result count check failed");
for (int i = 0; i < resultList.Count; i++)
{
Util.Log("on region:get:result[{0}]={1}.", i, (string)resultList[i]);
}
//---------------------Test for function execution with sendException------------------------//
for (int i = 1; i <= 230; i++) {
region["execKey-" + i] = i;
}
Util.Log("Put on region complete for execKeys");
List<Object> arrList = new List<Object>(20);
for (int i = 100; i < 120; i++) {
arrList.Add("execKey-" + i);
}
Object[] filter = new Object[20];
j = 0;
for (int i = 100; i < 120; i++) {
filter[j] = "execKey-" + i;
j++;
}
Util.Log("filter count= {0}.", filter.Length);
args = true;
exc = Client.FunctionService<object>.OnRegion<object, object>(region);
rc = exc.WithArgs<object>(args).WithFilter<object>(filter).Execute(exFuncNameSendException);
executeFunctionResult = rc.GetResult();
Assert.IsTrue(executeFunctionResult.Count == 1, "executeFunctionResult count check failed");
foreach (UserFunctionExecutionException item in executeFunctionResult) {
Util.Log("Item returned for bool arguement is {0} ", item.Message);
}
Util.Log("Executing exFuncNameSendException on region for execKeys for bool arguement done.");
rc = exc.WithArgs<object>(arrList).WithFilter<object>(filter).Execute(exFuncNameSendException);
executeFunctionResult = rc.GetResult();
Util.Log("exFuncNameSendException for arrList result->size() = {0} ", executeFunctionResult.Count);
Assert.IsTrue(executeFunctionResult.Count == arrList.Count + 1, "region get: resultList count is not as arrList count + exception");
foreach (object item in executeFunctionResult) {
Util.Log("Items returned for arrList arguement is {0} ", item);
}
Util.Log("Executing exFuncNameSendException on region for execKeys for arrList arguement done.");
MyResultCollector<object> myRC1 = new MyResultCollector<object>();
rc = exc.WithArgs<object>(args).WithCollector(myRC1).Execute(exFuncNameSendException);
executeFunctionResult = rc.GetResult();
Util.Log("add result count= {0}.", myRC1.GetAddResultCount());
Util.Log("get result count= {0}.", myRC1.GetGetResultCount());
Util.Log("end result count= {0}.", myRC1.GetEndResultCount());
Assert.IsTrue(myRC1.GetAddResultCount() == 1, "add result count check failed");
Assert.IsTrue(myRC1.GetGetResultCount() == 1, "get result count check failed");
Assert.IsTrue(myRC1.GetEndResultCount() == 1, "end result count check failed");
Util.Log("on Region with collector: result count= {0}.", executeFunctionResult.Count);
Assert.IsTrue(executeFunctionResult.Count == 1, "result count check failed");
foreach (object item in executeFunctionResult) {
Util.Log("on Region with collector: get:result {0}", (item as UserFunctionExecutionException).Message);
}
//---------------------Test for function execution with sendException Done-----------------------//
Pool/*<object, object>*/ pl = CacheHelper.DCache.GetPoolManager().Find(poolName);
//test date independant fucntion execution on one server
// test get function with result
exc = Client.FunctionService<object>.OnServer(pl);
ArrayList args1 = new ArrayList();
for (int i = 0; i < routingObj.Length; i++)
{
Util.Log("routingObj[{0}]={1}.", i, (string)routingObj[i]);
args1.Add(routingObj[i]);
}
rc = exc.WithArgs<ArrayList>(args1).Execute(getFuncIName);
executeFunctionResult = rc.GetResult();
resultList.Clear();
foreach (List<object> item in executeFunctionResult)
{
foreach (object item2 in item)
{
resultList.Add(item2);
}
}
Util.Log("on one server: 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 one server: get:result[{0}]={1}.", i, (string)resultList[i]);
}
//test data independant fucntion execution on all servers
// test get function with result
exc = Client.FunctionService<object>.OnServers(pl);
rc = exc.WithArgs<ArrayList>(args1).Execute(getFuncIName);
executeFunctionResult = rc.GetResult();
resultList.Clear();
foreach (List<object> item in executeFunctionResult)
{
foreach (object item2 in item)
{
resultList.Add(item2);
}
}
Util.Log("on all servers: result count= {0}.", resultList.Count);
Assert.IsTrue(resultList.Count == 34, "result count check failed");
for (int i = 0; i < resultList.Count; i++)
{
Util.Log("on all servers: get:result[{0}]={1}.", i, (string)resultList[i]);
}
//TODO::enable it once the StringArray conversion is fixed.
//test withCollector
MyResultCollector<object> myRC = new MyResultCollector<object>();
rc = exc.WithArgs<ArrayList>(args1).WithCollector(myRC).Execute(getFuncIName);
//executeFunctionResult = rc.GetResult();
Util.Log("add result count= {0}.", myRC.GetAddResultCount());
Util.Log("get result count= {0}.", myRC.GetGetResultCount());
Util.Log("end result count= {0}.", myRC.GetEndResultCount());
Util.Log("on all servers with collector: result count= {0}.", executeFunctionResult.Count);
Assert.IsTrue(myRC.GetResult().Count == 2, "result count check failed");
IList res = (IList)myRC.GetResult();
foreach (object o in res)
{
IList resList = (IList)o;
Util.Log("results " + resList.Count);
Assert.AreEqual(17, resList.Count);
}
MyResultCollector<object> myRC2 = new MyResultCollector<object>();
rc = exc.WithArgs<object>(args).WithCollector(myRC2).Execute(exFuncNameSendException);
executeFunctionResult = rc.GetResult();
Util.Log("add result count= {0}.", myRC2.GetAddResultCount());
Util.Log("get result count= {0}.", myRC2.GetGetResultCount());
Util.Log("end result count= {0}.", myRC2.GetEndResultCount());
Assert.IsTrue(myRC2.GetAddResultCount() == 2, "add result count check failed");
Assert.IsTrue(myRC2.GetGetResultCount() == 1, "get result count check failed");
Assert.IsTrue(myRC2.GetEndResultCount() == 1, "end result count check failed");
Util.Log("on Region with collector: result count= {0}.", executeFunctionResult.Count);
Assert.IsTrue(executeFunctionResult.Count == 2, "result count check failed");
foreach (object item in executeFunctionResult) {
Util.Log("on Region with collector: get:result {0}", (item as UserFunctionExecutionException).Message);
}
}