use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class ClientFunctionTimeoutRegressionTest method createClientCache.
private void createClientCache(String hostName, Integer port, Integer timeout) {
if (timeout > 0) {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "CLIENT_FUNCTION_TIMEOUT", String.valueOf(timeout));
}
Properties props = new Properties();
props.setProperty(LOCATORS, "");
props.setProperty(MCAST_PORT, "0");
ClientCacheFactory ccf = new ClientCacheFactory(props);
ccf.addPoolServer(hostName, port);
clientCache = (InternalClientCache) ccf.create();
ClientRegionFactory<String, String> crf = clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
crf.create(REGION_NAME);
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class CacheServerTestUtil method createCacheClientFromXmlN.
public static void createCacheClientFromXmlN(URL url, String poolName, String durableClientId, int timeout, Boolean addControlListener) {
ClientCacheFactory ccf = new ClientCacheFactory();
try {
File cacheXmlFile = new File(url.toURI().getPath());
ccf.set(CACHE_XML_FILE, cacheXmlFile.toURI().getPath());
} catch (URISyntaxException e) {
throw new ExceptionInInitializerError(e);
}
ccf.set(MCAST_PORT, "0");
ccf.set(DURABLE_CLIENT_ID, durableClientId);
ccf.set(DURABLE_CLIENT_TIMEOUT, String.valueOf(timeout));
ccf.set(LOG_FILE, "abs_client_system.log");
ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
cache = (Cache) ccf.create();
expected = IgnoredException.addIgnoredException("java.net.ConnectionException||java.net.SocketException");
pool = (PoolImpl) PoolManager.find(poolName);
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class ClientServerInvalidAndDestroyedEntryDUnitTest method doTestClientGetsInvalidEntry.
/**
* Bug #43407 - when a client does a get(k) and the entry is invalid in the server we want the
* client to end up with an entry that is invalid.
*/
private void doTestClientGetsInvalidEntry(final String regionName, final boolean usePR, boolean useTX) throws Exception {
VM vm1 = Host.getHost(0).getVM(1);
VM vm2 = Host.getHost(0).getVM(2);
// here are the keys that will be used to validate behavior. Keys must be
// colocated if using both a partitioned region in the server and transactions
// in the client. All of these keys hash to bucket 0 in a two-bucket PR
// except Object11 and IDoNotExist1
final String notAffectedKey = "Object1";
final String nonexistantKey = (usePR && useTX) ? "IDoNotExist2" : "IDoNotExist1";
final String key1 = "Object10";
final String key2 = (usePR && useTX) ? "Object12" : "Object11";
SerializableCallableIF createServer = getCreateServerCallable(regionName, usePR);
int serverPort = (Integer) vm1.invoke(createServer);
vm2.invoke(createServer);
vm1.invoke(new SerializableRunnable("populate server and create invalid entry") {
public void run() {
Region myRegion = getCache().getRegion(regionName);
for (int i = 1; i <= 20; i++) {
myRegion.put("Object" + i, "Value" + i);
}
myRegion.invalidate(key1);
myRegion.invalidate(key2);
}
});
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("creating client cache");
ClientCache c = new ClientCacheFactory().addPoolServer("localhost", serverPort).set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()).create();
Region myRegion = c.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName);
;
if (useTX) {
c.getCacheTransactionManager().begin();
}
// get of a valid entry should work
assertNotNull(myRegion.get(notAffectedKey));
// get of an invalid entry should return null and create the entry in an invalid state
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("getting " + key1 + " - should reach this cache and be INVALID");
assertNull(myRegion.get(key1));
assertTrue(myRegion.containsKey(key1));
// since this might be a PR we also check the next key to force PR Get messaging
assertNull(myRegion.get(key2));
assertTrue(myRegion.containsKey(key2));
// now try a key that doesn't exist anywhere
assertNull(myRegion.get(nonexistantKey));
assertFalse(myRegion.containsKey(nonexistantKey));
if (useTX) {
c.getCacheTransactionManager().commit();
// test that the commit correctly created the entries in the region
assertNotNull(myRegion.get(notAffectedKey));
assertNull(myRegion.get(key1));
assertTrue(myRegion.containsKey(key1));
assertNull(myRegion.get(key2));
assertTrue(myRegion.containsKey(key2));
}
myRegion.localDestroy(notAffectedKey);
myRegion.localDestroy(key1);
myRegion.localDestroy(key2);
if (useTX) {
c.getCacheTransactionManager().begin();
}
// check that getAll returns invalidated entries
List keys = new LinkedList();
keys.add(notAffectedKey);
keys.add(key1);
keys.add(key2);
Map result = myRegion.getAll(keys);
assertNotNull(result.get(notAffectedKey));
assertNull(result.get(key1));
assertNull(result.get(key2));
assertTrue(result.containsKey(key1));
assertTrue(result.containsKey(key2));
assertTrue(myRegion.containsKey(key1));
assertTrue(myRegion.containsKey(key2));
if (useTX) {
c.getCacheTransactionManager().commit();
// test that the commit correctly created the entries in the region
assertNotNull(myRegion.get(notAffectedKey));
assertNull(myRegion.get(key1));
assertTrue(myRegion.containsKey(key1));
assertNull(myRegion.get(key2));
assertTrue(myRegion.containsKey(key2));
}
// test that a listener is not invoked when there is already an invalidated
// entry in the client cache
UpdateListener listener = new UpdateListener();
listener.log = org.apache.geode.test.dunit.LogWriterUtils.getLogWriter();
myRegion.getAttributesMutator().addCacheListener(listener);
myRegion.get(key1);
assertEquals("expected no cache listener invocations", 0, listener.updateCount, listener.updateCount);
myRegion.localDestroy(notAffectedKey);
myRegion.getAll(keys);
assertTrue("expected to find " + notAffectedKey, myRegion.containsKey(notAffectedKey));
assertEquals("expected only one listener invocation for " + notAffectedKey, 1, listener.updateCount);
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class ClientServerInvalidAndDestroyedEntryDUnitTest method doTestClientGetsTombstone.
/**
* Similar to bug #43407 but not reported in a ticket, we want a client that does a get() on a
* destroyed entry to end up with a tombstone for that entry. This was already the case but there
* were no unit tests covering this for different server configurations and with/without
* transactions.
*/
private void doTestClientGetsTombstone(final String regionName, final boolean usePR, boolean useTX) throws Exception {
VM vm1 = Host.getHost(0).getVM(1);
VM vm2 = Host.getHost(0).getVM(2);
// here are the keys that will be used to validate behavior. Keys must be
// colocated if using both a partitioned region in the server and transactions
// in the client. All of these keys hash to bucket 0 in a two-bucket PR
// except Object11 and IDoNotExist1
final String notAffectedKey = "Object1";
final String nonexistantKey = (usePR && useTX) ? "IDoNotExist2" : "IDoNotExist1";
final String key1 = "Object10";
final String key2 = (usePR && useTX) ? "Object12" : "Object11";
SerializableCallableIF createServer = getCreateServerCallable(regionName, usePR);
int serverPort = (Integer) vm1.invoke(createServer);
vm2.invoke(createServer);
vm1.invoke(new SerializableRunnable("populate server and create invalid entry") {
public void run() {
Region myRegion = getCache().getRegion(regionName);
for (int i = 1; i <= 20; i++) {
myRegion.put("Object" + i, "Value" + i);
}
myRegion.destroy(key1);
myRegion.destroy(key2);
}
});
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("creating client cache");
ClientCache c = new ClientCacheFactory().addPoolServer("localhost", serverPort).set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()).create();
Region myRegion = c.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName);
;
if (useTX) {
c.getCacheTransactionManager().begin();
}
// get of a valid entry should work
assertNotNull(myRegion.get(notAffectedKey));
// get of an invalid entry should return null and create the entry in an invalid state
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("getting " + key1 + " - should reach this cache and be a TOMBSTONE");
assertNull(myRegion.get(key1));
assertFalse(myRegion.containsKey(key1));
RegionEntry entry;
if (!useTX) {
entry = ((LocalRegion) myRegion).getRegionEntry(key1);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
}
// since this might be a PR we also check the next key to force PR Get messaging
assertNull(myRegion.get(key2));
assertFalse(myRegion.containsKey(key2));
if (!useTX) {
entry = ((LocalRegion) myRegion).getRegionEntry(key2);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
}
// now try a key that doesn't exist anywhere
assertNull(myRegion.get(nonexistantKey));
assertFalse(myRegion.containsKey(nonexistantKey));
if (useTX) {
c.getCacheTransactionManager().commit();
// test that the commit correctly created the entries in the region
assertNotNull(myRegion.get(notAffectedKey));
assertNull(myRegion.get(key1));
assertFalse(myRegion.containsKey(key1));
entry = ((LocalRegion) myRegion).getRegionEntry(key1);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
assertNull(myRegion.get(key2));
assertFalse(myRegion.containsKey(key2));
entry = ((LocalRegion) myRegion).getRegionEntry(key2);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
}
myRegion.localDestroy(notAffectedKey);
if (useTX) {
c.getCacheTransactionManager().begin();
}
// check that getAll returns invalidated entries
List keys = new LinkedList();
keys.add(notAffectedKey);
keys.add(key1);
keys.add(key2);
Map result = myRegion.getAll(keys);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("result of getAll = " + result);
assertNotNull(result.get(notAffectedKey));
assertNull(result.get(key1));
assertNull(result.get(key2));
assertFalse(myRegion.containsKey(key1));
assertFalse(myRegion.containsKey(key2));
if (!useTX) {
entry = ((LocalRegion) myRegion).getRegionEntry(key1);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
entry = ((LocalRegion) myRegion).getRegionEntry(key2);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
} else {
// useTX
c.getCacheTransactionManager().commit();
// test that the commit correctly created the entries in the region
assertNotNull(myRegion.get(notAffectedKey));
assertNull(myRegion.get(key1));
assertFalse(myRegion.containsKey(key1));
entry = ((LocalRegion) myRegion).getRegionEntry(key1);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
assertNull(myRegion.get(key2));
assertFalse(myRegion.containsKey(key2));
entry = ((LocalRegion) myRegion).getRegionEntry(key2);
// it should be there
assertNotNull(entry);
// it should be a destroyed entry with Token.TOMBSTONE
assertTrue(entry.isTombstone());
}
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testStreamingClientServerFunction.
@Test
public void testStreamingClientServerFunction() {
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);
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");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(10, sum);
return null;
}
});
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");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(5, sum);
return null;
}
});
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");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(15, sum);
return null;
}
});
}
Aggregations