use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method dotestConcOps.
private void dotestConcOps(final boolean emptyClient) {
Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(2);
int port1 = createRegionsAndStartServer(server);
createClientRegion(client, port1, emptyClient, -1);
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);
r.registerInterestRegex(".*");
pr.registerInterestRegex(".*");
return null;
}
});
server.invoke(new SerializableCallable() {
public Object call() {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
r.put("key0", "value");
pr.put("key0", "value");
assertNull(r.putIfAbsent("keyForNull", null));
assertNull(pr.putIfAbsent("keyForNull", null));
assertEquals("value", r.putIfAbsent("key0", null));
assertEquals("value", pr.putIfAbsent("key0", null));
assertTrue(r.containsKey("keyForNull"));
assertTrue(pr.containsKey("keyForNull"));
assertFalse(r.containsValueForKey("keyForNull"));
assertFalse(pr.containsValueForKey("keyForNull"));
r.put("key0", "value");
pr.put("key0", "value");
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
WaitCriterion wc = new WaitCriterion() {
AssertionError e = null;
public boolean done() {
try {
if (!emptyClient) {
assertTrue(r.containsKey("key0"));
assertTrue(pr.containsKey("key0"));
assertTrue(r.containsKey("keyForNull"));
assertTrue(pr.containsKey("keyForNull"));
assertFalse(r.containsValueForKey("keyForNull"));
assertFalse(pr.containsValueForKey("keyForNull"));
}
assertEquals("value", r.putIfAbsent("key0", null));
assertEquals("value", pr.putIfAbsent("key0", null));
assertNull(r.putIfAbsent("keyForNull", null));
assertNull(pr.putIfAbsent("keyForNull", null));
assertNull(r.putIfAbsent("clientNullKey", null));
assertNull(pr.putIfAbsent("clientNullKey", null));
} catch (AssertionError ex) {
r.getCache().getLoggerI18n().fine("SWAP:caught ", ex);
e = ex;
return false;
}
return true;
}
public String description() {
return "timeout " + e;
}
};
Wait.waitForCriterion(wc, 30000, 1000, true);
return null;
}
});
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);
assertTrue(r.containsKey("clientNullKey"));
assertTrue(pr.containsKey("clientNullKey"));
assertFalse(r.containsValueForKey("clientNullKey"));
assertFalse(pr.containsValueForKey("clientNullKey"));
assertNotNull(r.replace("key0", "value2"));
assertNotNull(pr.replace("key0", "value2"));
assertTrue(r.replace("keyForNull", null, "newValue"));
assertTrue(pr.replace("keyForNull", null, "newValue"));
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() {
final Region r = getCache().getRegion(REP_REG_NAME);
final Region pr = getCache().getRegion(PR_REG_NAME);
WaitCriterion wc = new WaitCriterion() {
AssertionError e = null;
public boolean done() {
try {
assertEquals("value2", r.putIfAbsent("key0", null));
assertEquals("value2", pr.putIfAbsent("key0", null));
assertEquals("newValue", r.putIfAbsent("keyForNull", null));
assertEquals("newValue", pr.putIfAbsent("keyForNull", null));
// replace from client
assertEquals("value2", r.replace("key0", "value"));
assertEquals("value2", pr.replace("key0", "value"));
assertNull(r.replace("NoKeyOnServer", "value"));
assertNull(r.replace("NoKeyOnServer", "value"));
assertTrue(r.replace("clientNullKey", null, "newValue"));
assertTrue(pr.replace("clientNullKey", null, "newValue"));
} catch (AssertionError ex) {
e = ex;
return false;
}
return true;
}
public String description() {
return "timeout " + e.getMessage();
}
};
Wait.waitForCriterion(wc, 30000, 1000, true);
return null;
}
});
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);
assertEquals("newValue", r.get("clientNullKey"));
assertEquals("newValue", pr.get("clientNullKey"));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method do42167Work.
private void do42167Work(final boolean emptyClient, 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, emptyClient, -1);
server.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
r.put("key0", "value");
r.put("key2", "value2");
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
assertEquals("value", r.get("key0"));
if (!emptyClient) {
r.localDestroy("key0");
assertFalse(r.containsKey("key0"));
}
getCache().getLogger().fine("SWAP:doingRemove");
assertTrue(r.remove("key0", "value"));
getCache().getLogger().fine("Bruce:doingExtraRemoves. Bug #47010");
DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND = false;
assertTrue(r.remove("key0") == null);
assertTrue(DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND);
DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND = false;
assertFalse(r.remove("key0", "value"));
assertTrue(DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND);
DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND = false;
assertTrue(r.destroy("key0") == null);
assertTrue(DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND);
DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND = false;
assertTrue(r.remove("nonExistentKey1") == null);
assertTrue(DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND);
DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND = false;
assertFalse(r.remove("nonExistentKey2", "value"));
assertTrue(DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND);
DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND = false;
assertTrue(r.destroy("nonExistentKey3") == null);
assertTrue(DestroyOp.TEST_HOOK_ENTRY_NOT_FOUND);
getCache().getLogger().fine("SWAP:doingReplace");
assertEquals("value2", r.replace("key2", "newValue2"));
getCache().getLogger().fine("SWAP:doingReplace2");
assertEquals(null, r.replace("key0", "newValue"));
assertNull(r.putIfAbsent("key4", "value4"));
return null;
}
});
server.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
assertFalse(r.containsKey("key0"));
assertFalse(r.containsValueForKey("key0"));
assertTrue(r.containsKey("key2"));
assertEquals("newValue2", r.get("key2"));
r.getCache().getLogger().fine("SWAP:doingGet");
assertEquals("value4", r.get("key4"));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method doPutIfAbsentPutsKeyInLocalClientCacheWork.
private void doPutIfAbsentPutsKeyInLocalClientCacheWork(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"));
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
final Region r = getCache().getRegion(regionName);
assertEquals("value", r.putIfAbsent("key0", "newValue"));
assertTrue(r.containsKeyOnServer("key0"));
assertTrue(r.containsKey("key0"));
assertTrue(r.containsValueForKey("key0"));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConcurrentMapOpsDUnitTest method doPutIfAbsentWork.
private void doPutIfAbsentWork(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, false, -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"));
assertEquals("value", r.putIfAbsent("key0", "value2"));
assertEquals("value", pr.putIfAbsent("key0", "value2"));
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);
assertEquals("value", r.putIfAbsent("key0", "value2"));
assertEquals("value", pr.putIfAbsent("key0", "value2"));
if (cs) {
r.get("key0");
pr.get("key0");
}
assertTrue(r.containsKey("key0"));
assertTrue(pr.containsKey("key0"));
assertTrue(r.containsValueForKey("key0"));
assertTrue(pr.containsValueForKey("key0"));
return null;
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class DeltaFaultInDUnitTest method test.
@Test
public void test() throws Exception {
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final boolean copyOnRead = false;
final boolean clone = true;
SerializableCallable createDataRegion = new SerializableCallable("createDataRegion") {
public Object call() throws Exception {
Cache cache = getCache();
cache.setCopyOnRead(copyOnRead);
cache.createDiskStoreFactory().create("DeltaFaultInDUnitTestData");
AttributesFactory attr = new AttributesFactory();
attr.setDiskStoreName("DeltaFaultInDUnitTestData");
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
attr.setCloningEnabled(clone);
attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
Region region = cache.createRegion("region1", attr.create());
return null;
}
};
vm0.invoke(createDataRegion);
SerializableRunnable createEmptyRegion = new SerializableRunnable("createEmptyRegion") {
public void run() {
Cache cache = getCache();
cache.setCopyOnRead(copyOnRead);
AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
attr.setCloningEnabled(clone);
PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<Integer, TestDelta>();
paf.setRedundantCopies(1);
paf.setLocalMaxMemory(0);
PartitionAttributes<Integer, TestDelta> prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
attr.setDataPolicy(DataPolicy.PARTITION);
attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
// Put an entry
region.put(new Integer(0), new TestDelta(false, "initial"));
// Put a delta object that is larger
region.put(new Integer(0), new TestDelta(true, "initial_plus_some_more_data"));
}
};
vm1.invoke(createEmptyRegion);
vm0.invoke(new SerializableRunnable("doPut") {
public void run() {
Cache cache = getCache();
Region<Integer, TestDelta> region = cache.getRegion("region1");
// Evict the other object
region.put(new Integer(113), new TestDelta(false, "bogus"));
// Something was going weird with the LRU list. It was evicting this object.
// I want to make sure the other object is the one evicted.
region.get(new Integer(113));
long entriesEvicted = ((AbstractLRURegionMap) ((PartitionedRegion) region).entries)._getLruList().stats().getEvictions();
// assertIndexDetailsEquals(1, entriesEvicted);
TestDelta result = region.get(new Integer(0));
assertEquals("initial_plus_some_more_data", result.info);
}
});
}
Aggregations