use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class ConnectionPoolDUnitTest method verifyBalanced.
public void verifyBalanced(final PoolImpl pool, int expectedServer, final int expectedConsPerServer) {
verifyServerCount(pool, expectedServer);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return balanced(pool, expectedConsPerServer);
}
public String description() {
return "expected " + expectedConsPerServer + " but endpoints=" + outOfBalanceReport(pool);
}
};
Wait.waitForCriterion(ev, 2 * 60 * 1000, 200, true);
assertEquals("expected " + expectedConsPerServer + " but endpoints=" + outOfBalanceReport(pool), true, balanced(pool, expectedConsPerServer));
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.
@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
final String regionName1 = this.getName() + "-1";
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(2);
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setConcurrencyChecksEnabled(false);
createRegion(regionName1, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
// Create server1.
server1.invoke(createServer);
final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
Region region1 = null;
AttributesFactory regionFactory = new AttributesFactory();
regionFactory.setScope(Scope.LOCAL);
regionFactory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
region1 = createRegion(regionName1, regionFactory.create());
region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
}
};
// Create client.
client.invoke(createPool);
// Init values at server.
server1.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 20; i++) {
region1.put("key-string-" + i, "value-" + i);
}
}
});
// Put some values on the client.
client.invoke(new CacheSerializableRunnable("Put values client") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
for (int i = 0; i < 10; i++) {
region1.put("key-string-" + i, "client-value-" + i);
}
}
});
SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
String pName = region1.getAttributes().getPoolName();
region1.localDestroyRegion();
PoolImpl p = (PoolImpl) PoolManager.find(pName);
p.destroy();
}
};
client.invoke(closePool);
SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {
public void run2() throws CacheException {
for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
CacheServerImpl bsi = (CacheServerImpl) bi.next();
final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 62 * 1000, 200, true);
assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
}
}
};
server1.invoke(validateClientRegisterUnRegister);
server1.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class Bug35214DUnitTest method testNoEntryExpireDuringGII.
/**
* make sure entries do not expire during a GII
*/
@Test
public void testNoEntryExpireDuringGII() throws Exception {
initOtherVm();
AsyncInvocation updater = null;
try {
updater = updateOtherVm();
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable e1) {
Assert.fail("failed due to " + e1, e1);
}
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 30;
callbackFailure = false;
try {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setStatisticsEnabled(true);
af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE));
CacheListener cl1 = new CacheListenerAdapter() {
public void afterRegionCreate(RegionEvent re) {
afterRegionCreateSeen = true;
}
public void afterInvalidate(EntryEvent e) {
callbackAssertTrue("afterregionCreate not seen", afterRegionCreateSeen);
// make sure region is initialized
callbackAssertTrue("not initialized", ((LocalRegion) e.getRegion()).isInitialized());
expirationCount++;
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
}
};
af.addCacheListener(cl1);
final Region r1 = createRootRegion("r1", af.create());
ThreadUtils.join(updater, 60 * 1000);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return r1.values().size() == 0;
}
public String description() {
return "region never became empty";
}
};
Wait.waitForCriterion(ev, 2 * 1000, 200, true);
{
assertEquals(0, r1.values().size());
assertEquals(ENTRY_COUNT, r1.keySet().size());
}
} finally {
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
}
assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class CqQueryTestListener method waitForCqsConnectedEvents.
public boolean waitForCqsConnectedEvents(final int total) {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return (CqQueryTestListener.this.cqsConnectedCount == total);
}
public String description() {
return "Did not receive expected number of calls to cqsConnected() " + CqQueryTestListener.this.cqName + " expected: " + total + " receieved: " + CqQueryTestListener.this.cqsConnectedCount;
}
};
Wait.waitForCriterion(ev, MAX_TIME, 200, true);
return true;
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class CqQueryTestListener method waitForUpdated.
public boolean waitForUpdated(final Object key) {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return CqQueryTestListener.this.updates.contains(key);
}
public String description() {
return "never got update event for CQ " + CqQueryTestListener.this.cqName;
}
};
Wait.waitForCriterion(ev, MAX_TIME, 200, true);
return true;
}
Aggregations