use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class ClientServerRegisterInterestsDUnitTest method preTearDown.
@Override
public final void preTearDown() throws Exception {
serverPort.set(0);
entryEvents.clear();
gemfireServerVm.invoke(new SerializableRunnable() {
@Override
public void run() {
CacheFactory.getAnyInstance().close();
}
});
gemfireServerVm = null;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class ClientServerRegisterInterestsDUnitTest method setupGemFireCacheServer.
private void setupGemFireCacheServer() {
Host localhost = Host.getHost(0);
gemfireServerVm = localhost.getVM(0);
serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
gemfireServerVm.invoke(new SerializableRunnable() {
@Override
public void run() {
try {
Cache cache = new CacheFactory().set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0").set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config").create();
RegionFactory<String, String> regionFactory = cache.createRegionFactory();
regionFactory.setDataPolicy(DataPolicy.REPLICATE);
regionFactory.setKeyConstraint(String.class);
regionFactory.setValueConstraint(String.class);
Region<String, String> example = regionFactory.create("Example");
assertNotNull("The 'Example' Region was not properly configured and initialized!", example);
assertEquals("/Example", example.getFullPath());
assertEquals("Example", example.getName());
assertTrue(example.isEmpty());
example.put("1", "ONE");
assertFalse(example.isEmpty());
assertEquals(1, example.size());
CacheServer cacheServer = cache.addCacheServer();
cacheServer.setPort(serverPort.get());
cacheServer.setMaxConnections(10);
ClientSubscriptionConfig clientSubscriptionConfig = cacheServer.getClientSubscriptionConfig();
clientSubscriptionConfig.setCapacity(100);
clientSubscriptionConfig.setEvictionPolicy("entry");
cacheServer.start();
assertTrue("Cache Server is not running!", cacheServer.isRunning());
} catch (UnknownHostException ignore) {
throw new RuntimeException(ignore);
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", serverPort.get()), e);
}
}
});
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class RemoveAllCacheListenerClientServerRegressionTest method setupGemFireCacheServer.
// ================================================================================
private void setupGemFireCacheServer(RegionShortcut shortcut, boolean concChecks) {
serverVM = Host.getHost(0).getVM(0);
serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
String serverName = this.getClass().getSimpleName() + "_server";
serverVM.invoke(new SerializableRunnable() {
@Override
public void run() {
try {
Cache cache = new CacheFactory().set("name", serverName).set(MCAST_PORT, "0").set(LOG_FILE, serverName + ".log").set(LOG_LEVEL, "config").set("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]").create();
RegionFactory<String, String> regionFactory = cache.createRegionFactory(shortcut);
regionFactory.addCacheListener(new TestListener());
regionFactory.setConcurrencyChecksEnabled(concChecks);
regionFactory.create(REGION_NAME);
CacheServer cacheServer = cache.addCacheServer();
cacheServer.setPort(serverPort.get());
cacheServer.setMaxConnections(10);
cacheServer.start();
assertTrue("Cache Server is not running!", cacheServer.isRunning());
} catch (UnknownHostException ignore) {
throw new RuntimeException(ignore);
} catch (IOException e) {
throw new RuntimeException("Failed to start cache server " + serverName + " on port " + serverPort.get() + ": " + e.getStackTrace());
}
}
});
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForLocalRegionCreation.
public CacheSerializableRunnable getCacheSerializableRunnableForLocalRegionCreation(final String regionName, final Class constraint) {
SerializableRunnable createPrRegion;
createPrRegion = new CacheSerializableRunnable(regionName) {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region localRegion = null;
try {
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
attr.setScope(Scope.LOCAL);
localRegion = cache.createRegion(regionName, attr.create());
} catch (IllegalStateException ex) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().warning("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Creation caught IllegalStateException", ex);
}
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Partitioned Region ref null", localRegion);
assertTrue("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreate: Partitioned Region ref claims to be destroyed", !localRegion.isDestroyed());
}
};
return (CacheSerializableRunnable) createPrRegion;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPROrderByQueryWithLimit.
public CacheSerializableRunnable getCacheSerializableRunnableForPROrderByQueryWithLimit(final String regionName, final String localRegion) {
SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {
public void run2() throws CacheException {
Cache cache = getCache();
// Querying the localRegion and the PR region
String[] queries = new String[] { "status as st from /REGION_NAME order by status", "p.status from /REGION_NAME p order by p.status", "p.position1.secId, p.ID from /REGION_NAME p order by p.position1.secId, p.ID desc", "key from /REGION_NAME.keys key order by key.status, key.ID", "key.ID from /REGION_NAME.keys key order by key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status, key.ID asc", "key.ID, key.status from /REGION_NAME.keys key order by key.status desc, key.ID", "p.status, p.ID from /REGION_NAME p order by p.status asc, p.ID", "p.ID from /REGION_NAME p, p.positions.values order by p.ID", "* from /REGION_NAME p, p.positions.values val order by p.ID, val.secId", "p.iD, p.status from /REGION_NAME p order by p.iD", "iD, status from /REGION_NAME order by iD", "* from /REGION_NAME p order by p.getID()", "* from /REGION_NAME p order by p.getP1().secId, p.ID desc, p.ID", " p.position1.secId , p.ID as st from /REGION_NAME p order by p.position1.secId, p.ID", "e.key.ID, e.value.status from /REGION_NAME.entrySet e order by e.key.ID, e.value.status desc", "e.key from /REGION_NAME.entrySet e order by e.key.ID, e.key.pkid desc", "p, pos from /REGION_NAME p, p.positions.values pos order by p.ID, pos.secId desc", "p, pos from /REGION_NAME p, p.positions.values pos order by pos.secId, p.ID", "status , ID as ied from /REGION_NAME where ID > 0 order by status, ID desc", "p.status as st, p.ID as id from /REGION_NAME p where ID > 0 and status = 'inactive' order by p.status, p.ID desc", "p.position1.secId as st, p.ID as ied from /REGION_NAME p where p.ID > 0 and p.position1.secId != 'IBM' order by p.position1.secId, p.ID", " key.status as st, key.ID from /REGION_NAME.keys key where key.ID > 5 order by key.status, key.ID desc", " key.ID, key.status as st from /REGION_NAME.keys key where key.status = 'inactive' order by key.status desc, key.ID" };
Object[][] r = new Object[queries.length][2];
Region local = cache.getRegion(localRegion);
Region region = cache.getRegion(regionName);
assertNotNull(region);
final String[] expectedExceptions = new String[] { RegionDestroyedException.class.getName(), ReplyException.class.getName(), CacheClosedException.class.getName(), ForceReattemptException.class.getName(), QueryInvocationTargetException.class.getName() };
for (final String expectedException : expectedExceptions) {
getCache().getLogger().info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
}
String distinct = "<TRACE>SELECT DISTINCT ";
QueryService qs = getCache().getQueryService();
Object[] params;
try {
for (int l = 1; l <= 3; l++) {
String[] rq = new String[queries.length];
for (int j = 0; j < queries.length; j++) {
String qStr = null;
synchronized (region) {
// Execute on local region.
qStr = (distinct + queries[j].replace("REGION_NAME", localRegion));
qStr += (" LIMIT " + (l * l));
rq[j] = qStr;
SelectResults sr = (SelectResults) qs.newQuery(qStr).execute();
r[j][0] = sr;
if (sr.asList().size() > l * l) {
fail("The resultset size exceeds limit size. Limit size=" + l * l + ", result size =" + sr.asList().size());
}
// Execute on remote region.
qStr = (distinct + queries[j].replace("REGION_NAME", regionName));
qStr += (" LIMIT " + (l * l));
rq[j] = qStr;
SelectResults srr = (SelectResults) qs.newQuery(qStr).execute();
r[j][1] = srr;
if (srr.size() > l * l) {
fail("The resultset size exceeds limit size. Limit size=" + l * l + ", result size =" + srr.asList().size());
}
// assertIndexDetailsEquals("The resultset size is not same as limit size.", l*l,
// srr.asList().size());
// getCache().getLogger().info("Finished executing PR query: " + qStr);
}
}
StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
ssORrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, true, rq);
}
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
} catch (QueryInvocationTargetException e) {
// not it's okay
throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
} catch (QueryException e) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying" + e, e);
throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
} catch (RegionDestroyedException rde) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ", rde);
} catch (CancelException cce) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ", cce);
} finally {
for (final String expectedException : expectedExceptions) {
getCache().getLogger().info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
}
}
}
};
return (CacheSerializableRunnable) PrRegion;
}
Aggregations