use of org.apache.geode.cache.client.ClientCache 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);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method dotestBasicClientServerFunction.
private void dotestBasicClientServerFunction(final boolean register, final boolean withArgs) {
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", regionName, true);
if (register) {
registerFunction(server0);
registerFunction(server1);
registerFunction(server2);
}
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();
c.getLogger().info("SWAP:invoking function from client on g0");
Execution e = InternalFunctionService.onServers(c, "g0");
if (withArgs) {
ArrayList<String> args = new ArrayList<String>();
args.add("g0");
e = e.setArguments(args);
}
if (register) {
e.execute(OnGroupsFunction.Id).getResult();
} else {
e.execute(new OnGroupsFunction()).getResult();
}
return null;
}
});
verifyAndResetInvocationCount(server0, 1);
verifyAndResetInvocationCount(server1, 0);
verifyAndResetInvocationCount(server2, 1);
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on mg");
Execution e = InternalFunctionService.onServers(c, "mg");
if (withArgs) {
ArrayList<String> args = new ArrayList<String>();
args.add("mg");
e = e.setArguments(args);
}
if (register) {
e.execute(OnGroupsFunction.Id).getResult();
} else {
e.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();
c.getLogger().fine("SWAP:invoking function from client on g0 g1");
Execution e = InternalFunctionService.onServers(c, "g0", "g1");
if (withArgs) {
ArrayList<String> args = new ArrayList<String>();
args.add("g0");
args.add("g1");
e = e.setArguments(args);
}
if (register) {
e.execute(OnGroupsFunction.Id).getResult();
} else {
e.execute(new OnGroupsFunction()).getResult();
}
return null;
}
});
verifyAndResetInvocationCount(server0, 1);
verifyAndResetInvocationCount(server1, 1);
verifyAndResetInvocationCount(server2, 1);
}
use of org.apache.geode.cache.client.ClientCache 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.client.ClientCache in project geode by apache.
the class Bug47667DUnitTest method testbug47667.
@Test
public void testbug47667() {
Host host = Host.getHost(0);
VM locator = host.getVM(0);
VM server1 = host.getVM(1);
VM server2 = host.getVM(2);
VM client = host.getVM(3);
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final String locatorHost = NetworkUtils.getServerHostName(host);
locator.invoke("Start Locator", () -> startLocator(locatorHost, locatorPort, ""));
String locString = getLocatorString(host, locatorPort);
server1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "R1" }, locString, new String[] { "R1" }));
server2.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "R2" }, locString, new String[] { "R2" }));
client.invoke("create region and insert data in transaction", () -> {
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolLocator(locatorHost, locatorPort);
ClientCache cache = ccf.create();
PoolManager.createFactory().addLocator(locatorHost, locatorPort).setServerGroup("R1").create("R1");
PoolManager.createFactory().addLocator(locatorHost, locatorPort).setServerGroup("R2").create("R2");
Region region1 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).setPoolName("R1").create("R1");
Region region2 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).setPoolName("R2").create("R2");
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
region1.put(1, "value1");
transactionManager.commit();
transactionManager.begin();
region2.put(2, "value2");
transactionManager.commit();
return null;
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class FunctionServiceClientOnServerBase method createServers.
@Before
public void createServers() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
ClientCache cache = createServersAndClient(numberOfExecutions());
}
Aggregations