use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ClientServerInvalidAndDestroyedEntryDUnitTest method getCreateServerCallable.
/* this method creates a server cache and is used by all of the tests in this class */
private SerializableCallableIF getCreateServerCallable(final String regionName, final boolean usePR) {
return new SerializableCallable("create server and entries") {
public Object call() {
Cache cache = getCache();
List<CacheServer> servers = cache.getCacheServers();
CacheServer server;
if (servers.size() > 0) {
server = servers.get(0);
} else {
server = cache.addCacheServer();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.setHostnameForClients("localhost");
try {
server.start();
} catch (IOException e) {
Assert.fail("Failed to start server ", e);
}
}
if (usePR) {
RegionFactory factory = cache.createRegionFactory(RegionShortcut.PARTITION);
PartitionAttributesFactory pf = new PartitionAttributesFactory();
pf.setTotalNumBuckets(2);
factory.setPartitionAttributes(pf.create());
factory.create(regionName);
} else {
cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
}
return server.getPort();
}
};
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method doReplacePutsKeyInLocalClientCacheWork.
private void doReplacePutsKeyInLocalClientCacheWork(final String regionName) {
Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(2);
int port1 = createRegionsAndStartServer(server);
createClientRegion(client, port1, false, -1);
server.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(regionName);
assertNull(r.putIfAbsent("key0", "value"));
assertTrue(r.containsKey("key0"));
assertNull(r.putIfAbsent("key2", "value2"));
assertTrue(r.containsKey("key2"));
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(regionName);
assertEquals("value", r.replace("key0", "newValue"));
assertTrue(r.containsKeyOnServer("key0"));
assertTrue(r.containsKey("key0"));
assertTrue(r.containsValueForKey("key0"));
assertFalse(r.replace("key2", "DontReplace", "newValue"));
assertTrue(r.replace("key2", "value2", "newValu2"));
assertTrue(r.containsKeyOnServer("key2"));
assertTrue(r.containsKey("key2"));
assertTrue(r.containsValueForKey("key2"));
return null;
}
});
// bug #42221 - replace does not put entry on client when server has invalid value
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
final String key = "bug42221";
r.putIfAbsent(key, null);
assertTrue(r.containsKey(key));
Object result = r.replace(key, "not null");
assertEquals(null, result);
assertTrue(r.containsKey(key));
assertEquals(r.get(key), "not null");
// cleanup
r.remove(key);
return null;
}
});
// bug #42242 - remove(K,null) doesn't work
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
final String key = "bug42242";
r.putIfAbsent(key, null);
assertTrue(r.containsKey(key));
assertTrue(r.containsKeyOnServer(key));
boolean result = r.remove(key, null);
assertTrue(result);
assertFalse(r.containsKey(key));
assertFalse(r.containsKeyOnServer(key));
return null;
}
});
// bug #42242b - second scenario with a replace(K,V,V) that didn't work
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
final String key = "bug42242b";
r.putIfAbsent(key, null);
assertTrue(r.containsKey(key));
assertTrue(r.containsKeyOnServer(key));
boolean result = r.replace(key, null, "new value");
assertTrue(result);
result = r.remove(key, "new value");
assertTrue(result);
assertFalse(r.containsKey(key));
assertFalse(r.containsKeyOnServer(key));
return null;
}
});
// bug #42242c - remove does not work for entry that's on the server but not on the client
final String key = "bug42242c";
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
r.registerInterest("ALL_KEYS");
return null;
}
});
server.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
r.putIfAbsent(key, null);
assertTrue(r.containsKey(key));
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(regionName);
WaitCriterion w = new WaitCriterion() {
public String description() {
return "waiting for server operation to reach client";
}
public boolean done() {
return r.containsKey(key);
}
};
Wait.waitForCriterion(w, 10000, 200, true);
assertTrue(r.containsKeyOnServer(key));
boolean result = r.remove(key, null);
// if (!result) {
// ((LocalRegion)r).dumpBackingMap();
// }
assertTrue(result);
assertFalse(r.containsKey(key));
assertFalse(r.containsKeyOnServer(key));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method doRemoveWork.
private void doRemoveWork(final boolean cs) {
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(2);
if (cs) {
int port1 = createRegionsAndStartServer(vm1);
createClientRegion(vm2, port1, true, -1);
} else {
createRegions(vm1);
createRegions(vm2);
}
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
assertNull(r.putIfAbsent("key0", "value"));
assertNull(pr.putIfAbsent("key0", "value"));
assertNull(r.putIfAbsent("keyForClient", "value"));
assertNull(pr.putIfAbsent("keyForClient", "value"));
assertFalse(r.remove("nonExistentkey", "value"));
assertFalse(pr.remove("nonExistentkey", "value"));
assertFalse(r.remove("key0", "newValue"));
assertFalse(pr.remove("key0", "newValue"));
assertTrue(r.remove("key0", "value"));
assertTrue(pr.remove("key0", "value"));
assertFalse(r.containsKey("key0"));
assertFalse(pr.containsKey("key0"));
return null;
}
});
vm2.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
assertFalse(r.remove("nonExistentkey", "value"));
assertFalse(pr.remove("nonExistentkey", "value"));
assertFalse(r.remove("keyForClient", "newValue"));
assertFalse(pr.remove("keyForClient", "newValue"));
assertTrue(r.remove("keyForClient", "value"));
assertTrue(pr.remove("keyForClient", "value"));
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
assertFalse(r.containsKey("keyForClient"));
assertFalse(pr.containsKey("keyForClient"));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method testNullValueFromNonEmptyClients.
@Test
public void testNullValueFromNonEmptyClients() {
Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(2);
int port1 = createRegionsAndStartServer(server);
createClientRegion(client, port1, true, -1);
server.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
r.create("createKey", null);
pr.create("createKey", null);
assertNull(r.putIfAbsent("putAbsentKey", null));
assertNull(pr.putIfAbsent("putAbsentKey", null));
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
assertEquals(r.get("createKey"), r.get("putAbsentKey"));
assertEquals(pr.get("createKey"), pr.get("putAbsentKey"));
assertFalse(r.containsKey("createKey"));
assertFalse(pr.containsKey("createKey"));
assertEquals(r.containsKey("createKey"), r.containsKey("putAbsentKey"));
assertEquals(pr.containsKey("createKey"), pr.containsKey("putAbsentKey"));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method createRegionsAndStartServer.
private Integer createRegionsAndStartServer(VM vm, final boolean withRedundancy) {
return (Integer) vm.invoke(new SerializableCallable() {
public Object call() throws Exception {
getCache().createRegionFactory(RegionShortcut.REPLICATE).create(REP_REG_NAME);
if (withRedundancy) {
getCache().createRegionFactory(RegionShortcut.PARTITION_REDUNDANT).create(PR_REG_NAME);
} else {
getCache().createRegionFactory(RegionShortcut.PARTITION).create(PR_REG_NAME);
}
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
CacheServer s = getCache().addCacheServer();
s.setPort(port);
s.start();
return port;
}
});
}
Aggregations