use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class DistTXDebugDUnitTest method performRR_removeAllTest.
/**
* @param dataNodeAsCoordinator TODO
*
*/
private void performRR_removeAllTest(boolean dataNodeAsCoordinator) {
createCacheInAllVms();
Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE };
createReplicatedRegion(rrAttrs);
SerializableCallable TxOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
// put some data
HashMap<Integer, String> rhm = new HashMap<Integer, String>();
for (int i = 1; i <= 3; i++) {
rhm.put(i, "2_entry__" + i);
}
rr1.putAll(rhm);
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
rr1.removeAll(rhm.keySet());
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
LogWriterUtils.getLogWriter().info(" calling rr.get " + rr1.get(new Integer(i)));
assertEquals(null, rr1.get(new Integer(i)));
}
return null;
}
};
if (dataNodeAsCoordinator) {
dataStore1.invoke(TxOps);
} else {
accessor.invoke(TxOps);
}
// verify data size on all replicas
SerializableCallable verifySize = new SerializableCallable("getOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
LogWriterUtils.getLogWriter().info(" calling rr.getLocalSize " + rr1.size());
assertEquals(0, rr1.size());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
// accessor.invoke(TxOps);
}
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;
}
});
}
Aggregations