Search in sources :

Example 16 with FunctionInvocationTargetException

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

the class OnGroupsFunctionExecutionDUnitTest method testClientServerOneMemberFailure.

@Test
public void testClientServerOneMemberFailure() {
    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");
            args.add("g2");
            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 17 with FunctionInvocationTargetException

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

the class TestFunction method executeFunctionReexecuteException.

private synchronized void executeFunctionReexecuteException(FunctionContext context) {
    retryCountForExecuteFunctionReexecuteException++;
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (retryCountForExecuteFunctionReexecuteException >= 5) {
        logger.fine("Tried Function Execution 5 times. Now Returning after 5 attempts");
        context.getResultSender().lastResult(new Integer(retryCountForExecuteFunctionReexecuteException));
        retryCountForExecuteFunctionReexecuteException = 0;
        return;
    }
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException is intentionally thrown");
        throw new FunctionInvocationTargetException(new MyFunctionExecutionException("I have been thrown from TestFunction"));
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 18 with FunctionInvocationTargetException

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

the class DiskStoreCommandsJUnitTest method testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults.

@Test
public void testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
    final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
    final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
    final DiskStoreDetails diskStoreDetails = createDiskStoreDetails("memberOne", "cacheServerDiskStore");
    final List<DiskStoreDetails> expectedDiskStores = Arrays.asList(diskStoreDetails);
    final List<Object> results = new ArrayList<Object>();
    results.add(CollectionUtils.asSet(diskStoreDetails));
    results.add(new FunctionInvocationTargetException("expected"));
    mockContext.checking(new Expectations() {

        {
            oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
            oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
            will(returnValue(mockResultCollector));
            oneOf(mockResultCollector).getResult();
            will(returnValue(results));
        }
    });
    final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
    final List<DiskStoreDetails> actualDiskStores = commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
    Assert.assertNotNull(actualDiskStores);
    assertEquals(expectedDiskStores, actualDiskStores);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ListDiskStoresFunction(org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 19 with FunctionInvocationTargetException

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

the class MyFunctionException method executeFunctionFunctionInvocationTargetExceptionWithoutHA.

public static void executeFunctionFunctionInvocationTargetExceptionWithoutHA() {
    try {
        ResultCollector rc1 = FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute("DistribuedRegionFunctionFunctionInvocationException", true, false);
        rc1.getResult();
        fail("Function Invocation Target Exception should be thrown");
    } catch (Exception e) {
        e.printStackTrace();
        if (!(e.getCause() instanceof FunctionInvocationTargetException)) {
            fail("FunctionInvocationTargetException should be thrown");
        }
    }
}
Also used : FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) IOException(java.io.IOException) DistribuedRegionFunctionFunctionInvocationException(org.apache.geode.internal.cache.functions.DistribuedRegionFunctionFunctionInvocationException)

Example 20 with FunctionInvocationTargetException

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

the class PRClientServerRegionFunctionExecutionDUnitTest method regionSingleKeyExecutionNonHA.

public static void regionSingleKeyExecutionNonHA(Boolean isByName, Function function, Boolean toRegister) throws Exception {
    Region region = cache.getRegion(PartitionedRegionName);
    assertNotNull(region);
    final String testKey = "execKey";
    final Set testKeysSet = new HashSet();
    testKeysSet.add(testKey);
    DistributedSystem.setThreadsSocketPolicy(false);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    } else {
        FunctionService.unregisterFunction(function.getId());
        assertNull(FunctionService.getFunction(function.getId()));
    }
    Execution dataSet = FunctionService.onRegion(region);
    region.put(testKey, new Integer(1));
    try {
        ArrayList<String> args = new ArrayList<String>();
        args.add(retryRegionName);
        args.add("regionSingleKeyExecutionNonHA");
        ResultCollector rs = execute(dataSet, testKeysSet, args, function, isByName);
        fail("Expected ServerConnectivityException not thrown!");
    } catch (Exception ex) {
        if (!(ex.getCause() instanceof ServerConnectivityException) && !(ex.getCause() instanceof FunctionInvocationTargetException)) {
            throw ex;
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Set(java.util.Set) HashSet(java.util.HashSet) Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) 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

FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)36 ArrayList (java.util.ArrayList)20 FunctionException (org.apache.geode.cache.execute.FunctionException)19 CacheClosedException (org.apache.geode.cache.CacheClosedException)16 ResultCollector (org.apache.geode.cache.execute.ResultCollector)13 Execution (org.apache.geode.cache.execute.Execution)11 Region (org.apache.geode.cache.Region)10 List (java.util.List)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)9 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)9 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 DistributedMember (org.apache.geode.distributed.DistributedMember)8 CliMetaData (org.apache.geode.management.cli.CliMetaData)8 Result (org.apache.geode.management.cli.Result)7 IgnoredException (org.apache.geode.test.dunit.IgnoredException)7 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)6 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)6 Test (org.junit.Test)6 CliCommand (org.springframework.shell.core.annotation.CliCommand)6