use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverMultiKeyExecutionNoResult.
public static void serverMultiKeyExecutionNoResult(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(false, TEST_FUNCTION7);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
String msg = "<ExpectedException action=add>" + "FunctionException" + "</ExpectedException>";
cache.getLogger().info(msg);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
rc1.getResult();
Thread.sleep(20000);
fail("Test failed after the put operation");
} catch (FunctionException expected) {
expected.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : " + expected.getMessage());
assertTrue(expected.getMessage().startsWith((LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any"))));
} catch (Exception notexpected) {
Assert.fail("Test failed during execute or sleeping", notexpected);
} finally {
cache.getLogger().info("<ExpectedException action=remove>" + "FunctionException" + "</ExpectedException>");
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class FunctionCommands method executeFunction.
Result executeFunction(InternalCache cache, Set<DistributedMember> DsMembers, String functionId) {
// unregister on a set of of members
Function unregisterFunction = new UnregisterFunction();
FunctionService.registerFunction(unregisterFunction);
List resultList = null;
if (DsMembers.isEmpty()) {
return ResultBuilder.createInfoResult("No members for execution");
}
Object[] obj = new Object[1];
obj[0] = functionId;
Execution execution = FunctionService.onMembers(DsMembers).setArguments(obj);
if (execution == null) {
cache.getLogger().error("executeUnregister execution is null");
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.DESTROY_FUNCTION__MSG__CANNOT_EXECUTE);
return (ResultBuilder.buildResult(errorResultData));
}
try {
resultList = (ArrayList) execution.execute(unregisterFunction).getResult();
} catch (FunctionException ex) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(ex.getMessage());
return (ResultBuilder.buildResult(errorResultData));
}
String resultStr = ((String) resultList.get(0));
if (resultStr.equals("Succeeded in unregistering")) {
StringBuilder members = new StringBuilder();
for (DistributedMember member : DsMembers) {
members.append(member.getId());
members.append(",");
}
return ResultBuilder.createInfoResult("Destroyed " + functionId + " Successfully on " + members.toString().substring(0, members.toString().length() - 1));
} else {
return ResultBuilder.createInfoResult("Failed in unregistering");
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class FunctionCommands method executeAndGetResults.
void executeAndGetResults(String functionId, String filterString, String resultCollector, String[] arguments, InternalCache cache, DistributedMember member, TabularResultData resultTable, String onRegion) {
StringBuilder resultMessege = new StringBuilder();
try {
Function function = new UserFunctionExecution();
Object[] args = new Object[5];
args[0] = functionId;
if (filterString != null) {
args[1] = filterString;
}
if (resultCollector != null) {
args[2] = resultCollector;
}
if (arguments != null && arguments.length > 0) {
args[3] = new String();
for (String str : arguments) {
// send via CSV separated value format
if (str != null) {
args[3] = args[3] + str + ",";
}
}
}
args[4] = onRegion;
Execution execution = FunctionService.onMember(member).setArguments(args);
if (execution != null) {
List<Object> results = (List<Object>) execution.execute(function).getResult();
if (results != null) {
for (Object resultObj : results) {
if (resultObj != null) {
if (resultObj instanceof String) {
resultMessege.append(((String) resultObj));
} else if (resultObj instanceof Exception) {
resultMessege.append(((Exception) resultObj).getMessage());
} else {
resultMessege.append(resultObj);
}
}
}
}
toTabularResultData(resultTable, member.getId(), resultMessege.toString());
} else {
toTabularResultData(resultTable, member.getId(), CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_RETRIEVING_EXECUTOR);
}
} catch (FunctionException e) {
resultMessege.append(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__COULD_NOT_EXECUTE_FUNCTION_0_ON_MEMBER_1_ERROR_2, functionId, member.getId(), e.getMessage()));
toTabularResultData(resultTable, member.getId(), resultMessege.toString());
} catch (Exception e) {
resultMessege.append(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__COULD_NOT_EXECUTE_FUNCTION_0_ON_MEMBER_1_ERROR_2, functionId, member.getId(), e.getMessage()));
toTabularResultData(resultTable, member.getId(), resultMessege.toString());
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class QueryUsingFunctionContextDUnitTest method testQueriesWithFilterKeysOnPRWithRebalancing.
// GEODE-575: ignores lots of exceptions, non-thread-safe test hooks
@Category(FlakyTest.class)
@Test
public void testQueriesWithFilterKeysOnPRWithRebalancing() {
IgnoredException.addIgnoredException("QueryInvocationTargetException");
IgnoredException.addIgnoredException("java.net.SocketException");
IgnoredException.addIgnoredException("ServerConnectivityException");
IgnoredException.addIgnoredException("FunctionException");
IgnoredException.addIgnoredException("IOException");
// Close cache on server1
server1.invoke(new CacheSerializableRunnable("Set QueryObserver in cache on server1") {
@Override
public void run2() throws CacheException {
class MyQueryObserver extends IndexTrackingQueryObserver {
@Override
public void startQuery(Query query) {
Region pr = CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1);
Region KeyRegion = null;
for (int i = 6; i < 9; i++) {
KeyRegion = ((PartitionedRegion) pr).getBucketRegion(i);
if (KeyRegion != null)
KeyRegion.destroyRegion();
}
}
}
;
QueryObserverHolder.setInstance(new MyQueryObserver());
}
});
client.invoke(new CacheSerializableRunnable("Run function on PR") {
@Override
public void run2() throws CacheException {
Set filter = new HashSet();
ResultCollector rcollector = null;
filter.addAll(getFilter(6, 9));
for (int i = 0; i < queries.length; i++) {
try {
function = new TestQueryFunction("queryFunction");
rcollector = FunctionService.onRegion(CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1)).setArguments(queries[i]).withFilter(filter).execute(function);
// Should not come here, an exception is expected from above function call.
fail("Function call did not fail for query with function context");
} catch (FunctionException ex) {
if (!((ex.getCause() instanceof QueryInvocationTargetException) || (ex.getCause() instanceof ServerConnectivityException))) {
if (ex.getCause() instanceof FunctionException) {
FunctionException fe = (FunctionException) ex.getCause();
if (!fe.getMessage().startsWith("IOException")) {
fail("Should have received an QueryInvocationTargetException but recieved" + ex.getMessage());
}
} else {
fail("Should have received an QueryInvocationTargetException but recieved" + ex.getMessage());
}
}
}
}
// For loop ends here.
}
});
// Close cache on server1
server1.invoke(new CacheSerializableRunnable("Reset Query Observer on server1") {
@Override
public void run2() throws CacheException {
QueryObserverHolder.reset();
}
});
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class QueryUsingFunctionContextDUnitTest method testNonColocatedRegionQueries.
@Test
public void testNonColocatedRegionQueries() {
IgnoredException.addIgnoredException("UnsupportedOperationException");
client.invoke(new CacheSerializableRunnable("Test query on non-colocated regions on server") {
@Override
public void run2() throws CacheException {
Set filter = new HashSet();
filter.add(0);
for (int i = 0; i < nonColocatedQueries.length; i++) {
function = new TestQueryFunction("queryFunction-1");
QueryUsingFunctionContextDUnitTest test = new QueryUsingFunctionContextDUnitTest();
try {
ArrayList queryResults2 = test.runQueryOnClientUsingFunc(function, PartitionedRegionName1, filter, nonColocatedQueries[i]);
fail("Function call did not fail for query with function context");
} catch (FunctionException e) {
if (!(e.getCause() instanceof UnsupportedOperationException)) {
Assert.fail("Should have received an UnsupportedOperationException but received", e);
}
}
}
}
});
}
Aggregations