Search in sources :

Example 76 with FunctionException

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

the class OnGroupsFunctionExecutionDUnitTest method testClientServerMemberFailure.

@Test
public void testClientServerMemberFailure() {
    Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    VM locator = Host.getLocator();
    final String regionName = getName();
    initVM(server0, "mg,g0", regionName, true);
    initVM(server1, "g1", regionName, true);
    initVM(server2, "g0,g1,g2", regionName, true);
    final int locatorPort = getLocatorPort(locator);
    final String hostName = host.getHostName();
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            try {
                Cache c = CacheFactory.getAnyInstance();
                c.close();
            } catch (CacheClosedException cce) {
            }
            disconnectFromDS();
            LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolLocator(hostName, locatorPort);
            ccf.setPoolServerGroup("mg");
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache c = ccf.create();
            Execution e = InternalFunctionService.onServers(c, "g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("disconnect");
            e = e.setArguments(args);
            IgnoredException.addIgnoredException("FunctionInvocationTargetException");
            try {
                e.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof FunctionInvocationTargetException);
            }
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCache(org.apache.geode.cache.client.ClientCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 77 with FunctionException

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

the class OnGroupsFunctionExecutionDUnitTest method doBasicP2PFunctionNoCache.

private void doBasicP2PFunctionNoCache(final boolean registerFunction) {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    initVM(vm0, "g0,gm", null, false);
    initVM(vm1, "g1", null, false);
    initVM(vm2, "g0,g1", null, false);
    if (registerFunction) {
        registerFunction(vm0);
        registerFunction(vm1);
        registerFunction(vm2);
    }
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            LogWriterUtils.getLogWriter().fine("SWAP:invoking on gm");
            DistributedSystem ds = getSystem();
            try {
                FunctionService.onMember("no such group");
                fail("expected exception not thrown");
            } catch (FunctionException e) {
            }
            Execution e = FunctionService.onMembers("gm");
            ArrayList<String> args = new ArrayList<String>();
            args.add("gm");
            e = e.setArguments(args);
            if (registerFunction) {
                e.execute(OnGroupsFunction.Id).getResult();
            } else {
                e.execute(new OnGroupsFunction()).getResult();
            }
            return null;
        }
    });
    verifyAndResetInvocationCount(vm0, 1);
    verifyAndResetInvocationCount(vm1, 0);
    verifyAndResetInvocationCount(vm2, 0);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            LogWriterUtils.getLogWriter().fine("SWAP:invoking on g0");
            Execution e = FunctionService.onMembers("g0");
            ArrayList<String> args = new ArrayList<String>();
            args.add("g0");
            e = e.setArguments(args);
            if (registerFunction) {
                e.execute(OnGroupsFunction.Id).getResult();
            } else {
                e.execute(new OnGroupsFunction()).getResult();
            }
            return null;
        }
    });
    verifyAndResetInvocationCount(vm0, 1);
    verifyAndResetInvocationCount(vm1, 0);
    verifyAndResetInvocationCount(vm2, 1);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            Execution e = FunctionService.onMembers("g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("g1");
            e = e.setArguments(args);
            if (registerFunction) {
                e.execute(OnGroupsFunction.Id).getResult();
            } else {
                e.execute(new OnGroupsFunction()).getResult();
            }
            return null;
        }
    });
    verifyAndResetInvocationCount(vm0, 0);
    verifyAndResetInvocationCount(vm1, 1);
    verifyAndResetInvocationCount(vm2, 1);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            LogWriterUtils.getLogWriter().fine("SWAP:invoking on g0 g1");
            InternalDistributedSystem ds = InternalDistributedSystem.getConnectedInstance();
            Execution e = FunctionService.onMembers("g0", "g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("g0");
            args.add("g1");
            e = e.setArguments(args);
            if (registerFunction) {
                e.execute(OnGroupsFunction.Id).getResult();
            } else {
                e.execute(new OnGroupsFunction()).getResult();
            }
            return null;
        }
    });
    verifyAndResetInvocationCount(vm0, 1);
    verifyAndResetInvocationCount(vm1, 1);
    verifyAndResetInvocationCount(vm2, 1);
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 78 with FunctionException

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

the class OnGroupsFunctionExecutionDUnitTest method testClientServerException.

@Test
public void testClientServerException() {
    Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    VM locator = Host.getLocator();
    final String regionName = getName();
    initVM(server0, "mg,g0", regionName, true);
    initVM(server1, "g1", regionName, true);
    initVM(server2, "g0,g1,g2", regionName, true);
    final int locatorPort = getLocatorPort(locator);
    final String hostName = host.getHostName();
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            try {
                Cache c = CacheFactory.getAnyInstance();
                c.close();
            } catch (CacheClosedException cce) {
            }
            disconnectFromDS();
            LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolLocator(hostName, locatorPort);
            ccf.setPoolServerGroup("mg");
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache c = ccf.create();
            IgnoredException expected = IgnoredException.addIgnoredException("No member found");
            try {
                InternalFunctionService.onServers(c, "no such group").execute(new OnGroupsFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException e) {
            } finally {
                expected.remove();
            }
            IgnoredException.addIgnoredException("NullPointerException");
            Execution e = InternalFunctionService.onServers(c, "mg");
            ArrayList<String> args = new ArrayList<String>();
            args.add("runtime");
            e = e.setArguments(args);
            try {
                e.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            Execution e1 = InternalFunctionService.onServers(c, "g1");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            // only one member
            Execution e2 = InternalFunctionService.onServers(c, "g1");
            args.add("g2");
            e2 = e2.setArguments(args);
            try {
                e2.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            return null;
        }
    });
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCache(org.apache.geode.cache.client.ClientCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 79 with FunctionException

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

the class OnGroupsFunctionExecutionDUnitTest method testonMember.

@Test
public void testonMember() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    initVM(vm0, "g0,gm", null, false);
    initVM(vm1, "g1", null, false);
    initVM(vm2, "g0,g1", null, false);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            try {
                FunctionService.onMember("no such group");
                fail("expected exception not thrown");
            } catch (FunctionException e) {
            }
            try {
                FunctionService.onMember();
                fail("expected exception not thrown");
            } catch (FunctionException e) {
            }
            FunctionService.onMember("g1").execute(new OnGroupsFunction()).getResult();
            return null;
        }
    });
    int c0 = getAndResetInvocationCount(vm0);
    int c1 = getAndResetInvocationCount(vm1);
    int c2 = getAndResetInvocationCount(vm2);
    assertEquals(1, c0 + c1 + c2);
    // test that function is invoked locally when this member belongs to group
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            FunctionService.onMember("g0").execute(new OnGroupsFunction()).getResult();
            return null;
        }
    });
    verifyAndResetInvocationCount(vm0, 1);
    verifyAndResetInvocationCount(vm1, 0);
    verifyAndResetInvocationCount(vm2, 0);
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) FunctionException(org.apache.geode.cache.execute.FunctionException) Host(org.apache.geode.test.dunit.Host) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 80 with FunctionException

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

the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecutionWith2Regions.

public static void serverSingleKeyExecutionWith2Regions(Boolean isByName, Boolean toRegister) {
    Region region1 = cache.getRegion(PartitionedRegionName + "1");
    assertNotNull(region1);
    final String testKey = "execKey";
    final Set testKeysSet = new HashSet();
    testKeysSet.add(testKey);
    DistributedSystem.setThreadsSocketPolicy(false);
    Function function = new TestFunction(true, TEST_FUNCTION2);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    } else {
        FunctionService.unregisterFunction(function.getId());
        assertNull(FunctionService.getFunction(function.getId()));
    }
    Execution dataSet1 = FunctionService.onRegion(region1);
    region1.put(testKey, new Integer(1));
    ResultCollector rs = dataSet1.execute(function.getId());
    assertEquals(Boolean.FALSE, ((List) rs.getResult()).get(0));
    Region region2 = cache.getRegion(PartitionedRegionName + "2");
    assertNotNull(region2);
    Execution dataSet2 = FunctionService.onRegion(region2);
    region2.put(testKey, new Integer(1));
    try {
        rs = dataSet2.execute(function.getId());
        assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
        fail("Expected FunctionException");
    } catch (Exception ex) {
        if (!ex.getMessage().startsWith("No Replicated Region found for executing function")) {
            throw ex;
        }
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Set(java.util.Set) HashSet(java.util.HashSet) Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerException(java.rmi.ServerException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) HashSet(java.util.HashSet)

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