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;
}
});
}
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"));
}
}
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);
}
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");
}
}
}
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;
}
}
}
Aggregations