Search in sources :

Example 96 with FunctionException

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);
                    }
                }
            }
        }
    });
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) HashSet(java.util.HashSet) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) HashSet(java.util.HashSet) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 97 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerToClientFunctionResultSender65 method lastResult.

@Override
public synchronized void lastResult(Object oneResult, DistributedMember memberID) {
    this.lastResultReceived = true;
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 not sending lastResult {} as the server has shutdown", oneResult);
        }
        return;
    }
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("ServerToClientFunctionResultSender sending last result2 {} " + oneResult);
        }
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 sending lastResult {}", oneResult);
        }
        List<Object> result = new ArrayList<Object>();
        result.add(oneResult);
        result.add(memberID);
        this.setBuffer();
        this.msg.setServerConnection(this.sc);
        if (oneResult instanceof InternalFunctionException) {
            this.msg.setNumberOfParts(2);
            this.msg.setLastChunkAndNumParts(true, 2);
        } else {
            this.msg.setNumberOfParts(1);
            this.msg.setLastChunkAndNumParts(true, 1);
        }
        this.msg.addObjPart(result);
        if (oneResult instanceof InternalFunctionException) {
            List<Object> result2 = new ArrayList<Object>();
            result2.add(BaseCommand.getExceptionTrace((Throwable) oneResult));
            result2.add(memberID);
            this.msg.addObjPart(result2);
        }
        this.msg.sendChunk(this.sc);
        this.sc.setAsTrue(Command.RESPONDED);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_LAST_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 98 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerToClientFunctionResultSender65 method sendResult.

@Override
public synchronized void sendResult(Object oneResult, DistributedMember memberID) {
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 not sending result {}  as the server has shutdown", oneResult);
        }
        return;
    }
    try {
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 sending result {}", oneResult);
        }
        List<Object> result = new ArrayList<Object>();
        result.add(oneResult);
        result.add(memberID);
        this.setBuffer();
        this.msg.setNumberOfParts(1);
        this.msg.addObjPart(result);
        this.msg.sendChunk(this.sc);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_RESULT_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 99 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerToClientFunctionResultSender65 method sendResult.

@Override
public synchronized void sendResult(Object oneResult) {
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 not sending result {}  as the server has shutdown", oneResult);
        }
        return;
    }
    try {
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 sending result {}", oneResult);
        }
        DistributedMember memberID = InternalDistributedSystem.getAnyInstance().getDistributionManager().getId();
        List<Object> result = new ArrayList<Object>();
        result.add(oneResult);
        result.add(memberID);
        this.setBuffer();
        this.msg.setNumberOfParts(1);
        this.msg.addObjPart(result);
        this.msg.sendChunk(this.sc);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_RESULT_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 100 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerRegionFunctionExecutor method executeOnServer.

private ResultCollector executeOnServer(String functionId, ResultCollector collector, byte hasResult, boolean isHA, boolean optimizeForWrite) throws FunctionException {
    ServerRegionProxy srp = getServerRegionProxy();
    FunctionStats stats = FunctionStats.getFunctionStats(functionId, this.region.getSystem());
    try {
        validateExecution(null, null);
        long start = stats.startTime();
        stats.startFunctionExecution(true);
        srp.executeFunction(this.region.getFullPath(), functionId, this, collector, hasResult, isHA, optimizeForWrite, false);
        stats.endFunctionExecution(start, true);
        return collector;
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(true);
        throw functionException;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(true);
        throw new FunctionException(exception);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Aggregations

FunctionException (org.apache.geode.cache.execute.FunctionException)140 Function (org.apache.geode.cache.execute.Function)45 Execution (org.apache.geode.cache.execute.Execution)39 ResultCollector (org.apache.geode.cache.execute.ResultCollector)39 ArrayList (java.util.ArrayList)38 Test (org.junit.Test)38 HashSet (java.util.HashSet)36 CacheClosedException (org.apache.geode.cache.CacheClosedException)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 IOException (java.io.IOException)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)30 List (java.util.List)26 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)26 Host (org.apache.geode.test.dunit.Host)25 VM (org.apache.geode.test.dunit.VM)25 Region (org.apache.geode.cache.Region)24 IgnoredException (org.apache.geode.test.dunit.IgnoredException)24 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)24 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)22 Set (java.util.Set)21