use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class QueryUsingFunctionContextDUnitTest method testQueriesWithFilterKeysOnPRWithBucketDestroy.
/**
*
*/
@Test
public void testQueriesWithFilterKeysOnPRWithBucketDestroy() {
IgnoredException.addIgnoredException("QueryInvocationTargetException");
Object[][] r = new Object[queries.length][2];
Set filter = new HashSet();
// 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 = 0; i < 7; 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(0, 19));
for (int i = 0; i < queries.length; i++) {
try {
function = new TestQueryFunction("queryFunctionBucketDestroy");
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) {
// ex.printStackTrace();
if (!(ex.getCause() instanceof QueryInvocationTargetException)) {
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 testInvalidQueries.
@Test
public void testInvalidQueries() {
IgnoredException.addIgnoredException("Syntax error");
client.invoke(new CacheSerializableRunnable("Test query on client and server") {
@Override
public void run2() throws CacheException {
Set filter = new HashSet();
filter.add(0);
String query = "select * from / " + repRegionName + " where ID>=0";
TestServerQueryFunction func = new TestServerQueryFunction("LDS Server function-1");
function = new TestQueryFunction("queryFunction-1");
QueryUsingFunctionContextDUnitTest test = new QueryUsingFunctionContextDUnitTest();
try {
test.runQueryOnClientUsingFunc(function, repRegionName, filter, query);
fail("Query execution should have failed.");
} catch (FunctionException ex) {
assertTrue("The exception message should mention QueryInvalidException. ", ex.getLocalizedMessage().contains("QueryInvalidException"));
}
query = "select * from / " + PartitionedRegionName1 + " where ID>=0";
func = new TestServerQueryFunction("LDS Server function-1");
function = new TestQueryFunction("queryFunction-1");
test = new QueryUsingFunctionContextDUnitTest();
try {
test.runQueryOnClientUsingFunc(function, PartitionedRegionName1, filter, query);
fail("Query execution should have failed.");
} catch (FunctionException ex) {
assertTrue("The exception message should mention QueryInvalidException. ", ex.getLocalizedMessage().contains("QueryInvalidException"));
}
}
});
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class MemberFunctionStreamingMessage method process.
@Override
protected void process(final DistributionManager dm) {
Throwable thr = null;
ReplyException rex = null;
if (this.functionObject == null) {
rex = new ReplyException(new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(this.functionName)));
replyWithException(dm, rex);
return;
}
FunctionStats stats = FunctionStats.getFunctionStats(this.functionObject.getId(), dm.getSystem());
TXStateProxy tx = null;
try {
tx = prepForTransaction();
ResultSender resultSender = new MemberFunctionResultSender(dm, this, this.functionObject);
Set<Region> regions = new HashSet<Region>();
if (this.regionPathSet != null) {
InternalCache cache = GemFireCacheImpl.getInstance();
for (String regionPath : this.regionPathSet) {
if (checkCacheClosing(dm) || checkDSClosing(dm)) {
thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
return;
}
regions.add(cache.getRegion(regionPath));
}
}
FunctionContextImpl context = new MultiRegionFunctionContextImpl(this.functionObject.getId(), this.args, resultSender, regions, isReExecute);
long start = stats.startTime();
stats.startFunctionExecution(this.functionObject.hasResult());
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on remote member with context: {}", this.functionObject.getId(), context.toString());
}
this.functionObject.execute(context);
if (!this.replyLastMsg && this.functionObject.hasResult()) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(functionObject.getId()));
}
stats.endFunctionExecution(start, this.functionObject.hasResult());
} catch (FunctionException functionException) {
if (logger.isDebugEnabled()) {
logger.debug("FunctionException occurred on remote member while executing Function: {}", this.functionObject.getId(), functionException);
}
stats.endFunctionExecutionWithException(this.functionObject.hasResult());
rex = new ReplyException(functionException);
replyWithException(dm, rex);
// thr = functionException.getCause();
} catch (CancelException exception) {
// bug 37026: this is too noisy...
// throw new CacheClosedException("remote system shutting down");
// thr = se; cache is closed, no point trying to send a reply
thr = new FunctionInvocationTargetException(exception);
stats.endFunctionExecutionWithException(this.functionObject.hasResult());
rex = new ReplyException(thr);
replyWithException(dm, rex);
} catch (Exception exception) {
if (logger.isDebugEnabled()) {
logger.debug("Exception occurred on remote member while executing Function: {}", this.functionObject.getId(), exception);
}
stats.endFunctionExecutionWithException(this.functionObject.hasResult());
rex = new ReplyException(exception);
replyWithException(dm, rex);
// thr = e.getCause();
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
thr = t;
} finally {
cleanupTransaction(tx);
if (thr != null) {
rex = new ReplyException(thr);
replyWithException(dm, rex);
}
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class PartitionedRegionFunctionResultSender method sendResult.
public void sendResult(Object oneResult) {
if (!this.function.hasResult()) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
}
if (this.serverSender != null) {
logger.debug("PartitionedRegionFunctionResultSender sending result from local node to client {}", oneResult);
clientSend(oneResult, dm.getDistributionManagerId());
} else {
// P2P
if (this.msg != null) {
try {
logger.debug("PartitionedRegionFunctionResultSender sending result from remote node {}", oneResult);
this.msg.sendReplyForOneResult(dm, pr, time, oneResult, false, enableOrderedResultStreming);
} catch (ForceReattemptException e) {
throw new FunctionException(e);
} catch (InterruptedException e) {
throw new FunctionException(e);
}
} else {
logger.debug("PartitionedRegionFunctionResultSender adding result to ResultCollector on local node {}", oneResult);
this.rc.addResult(dm.getDistributionManagerId(), oneResult);
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
}
// incrementing result sent stats.
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class PartitionedRegionFunctionResultSender method lastResult.
// this must be getting called directly from function
public void lastResult(Object oneResult) {
if (!this.function.hasResult()) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
}
if (this.serverSender != null) {
// Client-Server
if (this.localLastResultRecieved) {
return;
}
if (onlyLocal) {
checkForBucketMovement(oneResult);
if (bme != null) {
clientSend(oneResult, dm.getDistributionManagerId());
lastClientSend(dm.getDistributionManagerId(), bme);
} else {
lastClientSend(dm.getDistributionManagerId(), oneResult);
}
this.rc.endResults();
this.localLastResultRecieved = true;
} else {
// call a synchronized method as local node is also waiting to send lastResult
lastResult(oneResult, rc, false, true, dm.getDistributionManagerId());
}
} else {
if (this.msg != null) {
checkForBucketMovement(oneResult);
try {
if (this.bme != null) {
this.msg.sendReplyForOneResult(dm, pr, time, oneResult, false, enableOrderedResultStreming);
throw bme;
} else {
this.msg.sendReplyForOneResult(dm, pr, time, oneResult, true, enableOrderedResultStreming);
}
} catch (ForceReattemptException e) {
throw new FunctionException(e);
} catch (InterruptedException e) {
throw new FunctionException(e);
}
} else {
if (this.localLastResultRecieved) {
return;
}
if (onlyLocal) {
checkForBucketMovement(oneResult);
if (bme != null) {
this.rc.addResult(dm.getDistributionManagerId(), oneResult);
this.rc.addResult(dm.getDistributionManagerId(), bme);
} else {
this.rc.addResult(dm.getDistributionManagerId(), oneResult);
}
// exception thrown will do end result
this.rc.endResults();
this.localLastResultRecieved = true;
} else {
// call a synchronized method as local node is also waiting to send lastResult
lastResult(oneResult, rc, false, true, dm.getDistributionManagerId());
}
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
}
// incrementing result sent stats.
// Bug : remote node as well as local node calls this method to send
// the result When the remote nodes are added to the local result collector at that
// time the stats for the result sent is again incremented : Once the PR team comes with the
// concept of the Streaming FunctionOperation
// for the partitioned Region then it will be simple to fix this problem.
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
}
}
Aggregations