Search in sources :

Example 96 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverSingleKeyExecutionSocketTimeOut.

public static void serverSingleKeyExecutionSocketTimeOut(Boolean isByName) {
    Region region = cache.getRegion(PartitionedRegionName);
    assertNotNull(region);
    final String testKey = "execKey";
    final Set testKeysSet = new HashSet();
    testKeysSet.add(testKey);
    DistributedSystem.setThreadsSocketPolicy(false);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    region.put(testKey, new Integer(1));
    try {
        ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
        assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
        ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName);
        assertEquals(testKey, ((List) rs2.getResult()).get(0));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        Assert.fail("Test failed after the put operation", ex);
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashSet(java.util.HashSet) Set(java.util.Set) Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) HashSet(java.util.HashSet)

Example 97 with ResultCollector

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

the class PRFunctionExecutionDUnitTest method testRemoteMultiKeyExecutionNoResult_byName.

/**
   * Test multi-key remote execution by a pure accessor which doesn't have the function factory
   * present. ResultCollector = DefaultResultCollector haveResults = false;
   */
@Test
public void testRemoteMultiKeyExecutionNoResult_byName() throws Exception {
    final String rName = getUniqueName();
    Host host = Host.getHost(0);
    final VM accessor = host.getVM(3);
    final VM datastore0 = host.getVM(0);
    final VM datastore1 = host.getVM(1);
    final VM datastore2 = host.getVM(2);
    accessor.invoke(new SerializableCallable("Create PR") {

        public Object call() throws Exception {
            RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 0);
            getCache().createRegion(rName, ra);
            return Boolean.TRUE;
        }
    });
    SerializableCallable dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {

        public Object call() throws Exception {
            RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
            AttributesFactory raf = new AttributesFactory(ra);
            PartitionAttributesImpl pa = new PartitionAttributesImpl();
            pa.setAll(ra.getPartitionAttributes());
            raf.setPartitionAttributes(pa);
            getCache().createRegion(rName, raf.create());
            Function function = new TestFunction(false, TEST_FUNCTION7);
            FunctionService.registerFunction(function);
            return Boolean.TRUE;
        }
    };
    datastore0.invoke(dataStoreCreate);
    datastore1.invoke(dataStoreCreate);
    datastore2.invoke(dataStoreCreate);
    Object o = accessor.invoke(new SerializableCallable("Create data, invoke exectuable") {

        public Object call() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
            final HashSet testKeysSet = new HashSet();
            for (int i = (pr.getTotalNumberOfBuckets() * 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(pr);
            int j = 0;
            HashSet origVals = new HashSet();
            for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
                Integer val = new Integer(j++);
                origVals.add(val);
                pr.put(i.next(), val);
            }
            ResultCollector rs;
            try {
                rs = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
                rs.getResult();
            } catch (Exception expected) {
                expected.printStackTrace();
                assertTrue(expected.getMessage().startsWith(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any")));
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }
    });
    assertEquals(Boolean.TRUE, o);
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) RegionAttributes(org.apache.geode.cache.RegionAttributes) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) Execution(org.apache.geode.cache.execute.Execution) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Iterator(java.util.Iterator) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 98 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverMultiKeyExecutionOnASingleBucket.

public static void serverMultiKeyExecutionOnASingleBucket(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);
    }
    int j = 0;
    for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
        Integer val = new Integer(j++);
        region.put(i.next(), val);
    }
    DistributedSystem.setThreadsSocketPolicy(false);
    for (Iterator kiter = testKeysSet.iterator(); kiter.hasNext(); ) {
        try {
            Set singleKeySet = Collections.singleton(kiter.next());
            Function function = new TestFunction(true, TEST_FUNCTION2);
            FunctionService.registerFunction(function);
            Execution dataSet = FunctionService.onRegion(region);
            ResultCollector rc1 = execute(dataSet, singleKeySet, Boolean.TRUE, function, isByName);
            List l = null;
            l = ((List) rc1.getResult());
            assertEquals(1, l.size());
            ResultCollector rc2 = execute(dataSet, singleKeySet, new HashSet(singleKeySet), function, isByName);
            List l2 = null;
            l2 = ((List) rc2.getResult());
            assertEquals(1, l2.size());
            List subList = (List) l2.iterator().next();
            assertEquals(1, subList.size());
            assertEquals(region.get(singleKeySet.iterator().next()), subList.iterator().next());
        } catch (Exception expected) {
            LogWriterUtils.getLogWriter().info("Exception : " + expected.getMessage());
            expected.printStackTrace();
            fail("Test failed after the put operation");
        }
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashSet(java.util.HashSet) Set(java.util.Set) Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) HashSet(java.util.HashSet)

Example 99 with ResultCollector

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

the class PartitionedRegionEquiJoinIntegrationTest method executeQueries.

@Override
protected Object[] executeQueries(String[] queries) {
    ResultCollector collector = FunctionService.onRegion(region1).setArguments(queries).execute(equijoinTestFunction.getId());
    Object result = collector.getResult();
    return (Object[]) ((ArrayList) result).get(0);
}
Also used : ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 100 with ResultCollector

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

the class MBeanProxyInvocationHandler method delegateToFucntionService.

/**
   * It will call the Generic function to execute the method on the remote VM
   * 
   * @param objectName ObjectName of the MBean
   * @param methodName method name
   * @param args arguments to the methods
   * @param signature signature of the method
   * @return result Object
   */
protected Object delegateToFucntionService(ObjectName objectName, String methodName, Object[] args, String[] signature) throws Throwable {
    Object[] functionArgs = new Object[5];
    functionArgs[0] = objectName;
    functionArgs[1] = methodName;
    functionArgs[2] = signature;
    functionArgs[3] = args;
    functionArgs[4] = member.getName();
    List<Object> result = null;
    try {
        ResultCollector rc = FunctionService.onMember(member).setArguments(functionArgs).execute(ManagementConstants.MGMT_FUNCTION_ID);
        result = (List<Object>) rc.getResult();
    // Exceptions of ManagementFunctions
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug(" Exception while Executing Funtion {}", e.getMessage(), e);
        }
        // Only in case of Exception caused for Function framework.
        return null;
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        if (logger.isDebugEnabled()) {
            logger.debug(" Exception while Executing Funtion {}", th.getMessage(), th);
        }
        return null;
    }
    return checkErrors(result.get(ManagementConstants.RESULT_INDEX));
}
Also used : ResultCollector(org.apache.geode.cache.execute.ResultCollector) IntrospectionException(java.beans.IntrospectionException) MBeanException(javax.management.MBeanException)

Aggregations

ResultCollector (org.apache.geode.cache.execute.ResultCollector)235 Execution (org.apache.geode.cache.execute.Execution)164 HashSet (java.util.HashSet)148 ArrayList (java.util.ArrayList)144 FunctionException (org.apache.geode.cache.execute.FunctionException)126 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)122 List (java.util.List)112 Function (org.apache.geode.cache.execute.Function)111 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)106 Test (org.junit.Test)101 IgnoredException (org.apache.geode.test.dunit.IgnoredException)94 Iterator (java.util.Iterator)81 Region (org.apache.geode.cache.Region)77 Set (java.util.Set)69 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)65 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)63 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)56 AttributesFactory (org.apache.geode.cache.AttributesFactory)53 Host (org.apache.geode.test.dunit.Host)53 VM (org.apache.geode.test.dunit.VM)53