Search in sources :

Example 61 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class MemberFunctionExecutionDUnitTest method testOnMembersWithoutCache.

@Test
public void testOnMembersWithoutCache() throws Exception {
    DistributedMember member1Id = (DistributedMember) member1.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            disconnectFromDS();
            return getSystem().getDistributedMember();
        }
    });
    member2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            getSystem();
            ResultCollector<?, ?> rc = FunctionService.onMember(member1Id).execute(new FunctionAdapter() {

                @Override
                public String getId() {
                    return getClass().getName();
                }

                @Override
                public void execute(FunctionContext context) {
                    // This will throw an exception because the cache is not yet created.
                    CacheFactory.getAnyInstance();
                }
            });
            try {
                rc.getResult(30, TimeUnit.SECONDS);
                fail("Should have seen an exception");
            } catch (Exception e) {
                if (!(e.getCause() instanceof FunctionInvocationTargetException)) {
                    Assert.fail("failed", e);
                }
            }
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionContext(org.apache.geode.cache.execute.FunctionContext) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 62 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testOnServer.

@Test
public void testOnServer() {
    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 ex = IgnoredException.addIgnoredException("No member found");
            try {
                InternalFunctionService.onServer(c, "no such group").execute(new OnGroupsFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException e) {
            } finally {
                ex.remove();
            }
            InternalFunctionService.onServer(c, "g1").execute(new OnGroupsFunction()).getResult();
            return null;
        }
    });
    int c0 = getAndResetInvocationCount(server0);
    int c1 = getAndResetInvocationCount(server1);
    int c2 = getAndResetInvocationCount(server2);
    assertEquals(1, c0 + c1 + c2);
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache c = ClientCacheFactory.getAnyInstance();
            InternalFunctionService.onServer(c, "g0").execute(new OnGroupsFunction()).getResult();
            return null;
        }
    });
    verifyAndResetInvocationCount(server0, 1);
    verifyAndResetInvocationCount(server1, 0);
    verifyAndResetInvocationCount(server2, 0);
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache c = ClientCacheFactory.getAnyInstance();
            InternalFunctionService.onServer(c, "mg", "g1").execute(new OnGroupsFunction()).getResult();
            return null;
        }
    });
    c0 = getAndResetInvocationCount(server0);
    c1 = getAndResetInvocationCount(server1);
    c2 = getAndResetInvocationCount(server2);
    assertEquals(2, c0 + c1 + c2);
}
Also used : 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) 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 63 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2PMemberFailure.

@Test
public void testP2PMemberFailure() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String regionName = getName();
    initVM(vm0, "g0,mg", regionName, false);
    initVM(vm1, "g1", regionName, false);
    initVM(vm2, "g0,g1,g2", regionName, false);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            Execution e1 = FunctionService.onMembers("g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("shutdown");
            e1 = e1.setArguments(args);
            try {
                e1.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) 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) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 64 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2PException.

@Test
public void testP2PException() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String regionName = getName();
    // The test function deliberately throws a null pointer exception.
    // which is logged.
    IgnoredException.addIgnoredException(NullPointerException.class.getSimpleName());
    initVM(vm0, "g0,mg", regionName, false);
    initVM(vm1, "g1", regionName, false);
    initVM(vm2, "g0,g1,g2", regionName, false);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            Execution e = FunctionService.onMembers("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 = FunctionService.onMembers("g1");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            // fail on only one member
            Execution e2 = FunctionService.onMembers("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 : ArrayList(java.util.ArrayList) 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) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 65 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2POneMemberFailure.

@Test
public void testP2POneMemberFailure() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String regionName = getName();
    initVM(vm0, "g0,mg", regionName, false);
    initVM(vm1, "g1", regionName, false);
    initVM(vm2, "g0,g1,g2", regionName, false);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            Execution e1 = FunctionService.onMembers("g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("shutdown");
            args.add("g2");
            e1 = e1.setArguments(args);
            try {
                e1.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) 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) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)502 VM (org.apache.geode.test.dunit.VM)326 Test (org.junit.Test)314 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)311 Host (org.apache.geode.test.dunit.Host)306 Region (org.apache.geode.cache.Region)224 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)157 IgnoredException (org.apache.geode.test.dunit.IgnoredException)155 AttributesFactory (org.apache.geode.cache.AttributesFactory)139 Cache (org.apache.geode.cache.Cache)109 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)95 FunctionException (org.apache.geode.cache.execute.FunctionException)88 ArrayList (java.util.ArrayList)83 HashSet (java.util.HashSet)83 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)77 Execution (org.apache.geode.cache.execute.Execution)74 CommitConflictException (org.apache.geode.cache.CommitConflictException)70 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)66 Function (org.apache.geode.cache.execute.Function)63 IOException (java.io.IOException)62