use of org.apache.geode.test.dunit.WaitCriterion 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.WaitCriterion in project geode by apache.
the class FixedPRSinglehopDUnitTest method verifyMetadata.
private void verifyMetadata(final int totalBuckets, int currentRedundancy) {
ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return (regionMetaData.size() == 1);
}
public String description() {
return "expected no metadata to be refreshed";
}
};
Wait.waitForCriterion(wc, 60000, 1000, true);
assertTrue(regionMetaData.containsKey(region.getFullPath()));
final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
wc = new WaitCriterion() {
public boolean done() {
return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == totalBuckets);
}
public String description() {
return "expected no metadata to be refreshed. Expected " + totalBuckets + " entries but found " + prMetaData.getBucketServerLocationsMap_TEST_ONLY();
}
};
Wait.waitForCriterion(wc, 60000, 1000, true);
System.out.println("metadata is " + prMetaData);
System.out.println("metadata bucket locations map is " + prMetaData.getBucketServerLocationsMap_TEST_ONLY());
for (Map.Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
assertEquals("list has wrong contents: " + entry.getValue(), currentRedundancy, ((List) entry.getValue()).size());
}
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class SingleHopGetAllPutAllDUnitTest method verifyMetadata.
private static void verifyMetadata() {
Region region = cache.getRegion(PartitionedRegionName);
ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
cms.getClientPRMetadata((LocalRegion) region);
final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return (regionMetaData.size() == 1);
}
public String description() {
return "Region metadat size is not 1. Exisitng size of regionMetaData is " + regionMetaData.size();
}
};
Wait.waitForCriterion(wc, 5000, 200, true);
assertTrue(regionMetaData.containsKey(region.getFullPath()));
final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
wc = new WaitCriterion() {
public boolean done() {
return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 13);
}
public String description() {
return "Bucket server location map size is not 13. Exisitng size is :" + prMetaData.getBucketServerLocationsMap_TEST_ONLY().size();
}
};
Wait.waitForCriterion(wc, 5000, 200, true);
for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
assertEquals(2, ((List) entry.getValue()).size());
}
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class TestFunction method executeHA.
public void executeHA(FunctionContext context) {
RegionFunctionContext rcontext = (RegionFunctionContext) context;
Region region = rcontext.getDataSet();
region.getCache().getLogger().fine("executeHA#execute( " + rcontext + " )");
WaitCriterion wc = new WaitCriterion() {
String excuse;
public boolean done() {
return false;
}
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 10000, 500, false);
rcontext.getResultSender().lastResult((Serializable) rcontext.getArguments());
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class HASlowReceiverDUnitTest method checkRedundancyLevel.
public static void checkRedundancyLevel(final Integer redundantServers) {
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return pool.getRedundantNames().size() == redundantServers.intValue();
}
public String description() {
return "Expected redundant count (" + pool.getRedundantNames().size() + ") to become " + redundantServers.intValue();
}
};
Wait.waitForCriterion(wc, 200 * 1000, 1000, true);
}
Aggregations