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