use of util.TestException in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRAndRRQueryAndCompareResults.
public SerializableRunnableIF getCacheSerializableRunnableForPRAndRRQueryAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Querying the PR region
String[] queries = new String[] { "r1.ID = r2.id", "r1.ID = r2.id AND r1.ID > 5", "r1.ID = r2.id AND r1.status = 'active'", // "r1.ID = r2.id LIMIT 10",
"r1.ID = r2.id ORDER BY r1.ID", "r1.ID = r2.id ORDER BY r2.id", "r1.ID = r2.id ORDER BY r2.status", "r1.ID = r2.id AND r1.status != r2.status", "r1.ID = r2.id AND r1.status = r2.status", "r1.ID = r2.id AND r1.positions.size = r2.positions.size", "r1.ID = r2.id AND r1.positions.size > r2.positions.size", "r1.ID = r2.id AND r1.positions.size < r2.positions.size", "r1.ID = r2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = r2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = r2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
Object[][] r = new Object[queries.length][2];
Region region = null;
region = cache.getRegion(name);
assertNotNull(region);
region = cache.getRegion(coloName);
assertNotNull(region);
region = cache.getRegion(localName);
assertNotNull(region);
region = cache.getRegion(coloLocalName);
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>");
}
QueryService qs = getCache().getQueryService();
Object[] params;
try {
for (int j = 0; j < queries.length; j++) {
getCache().getLogger().info("About to execute local query: " + queries[j]);
Function func = new TestQueryFunction("testfunction");
Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, /" + coloName + " r2, r2.positions.values pos2 where " + queries[j]).execute(func).getResult();
r[j][0] = ((ArrayList) funcResult).get(0);
getCache().getLogger().info("About to execute local query: " + queries[j]);
SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, /" + coloLocalName + " r2, r2.positions.values pos2 where " + queries[j]).execute();
r[j][1] = r2.asList();
}
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
// compareTwoQueryResults(r, queries.length);
StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
} catch (QueryInvocationTargetException e) {
// cause and see whether or 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;
}
use of util.TestException in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRQueryAndCompareResults.
public CacheSerializableRunnable getCacheSerializableRunnableForPRQueryAndCompareResults(final String regionName, final String localRegion, final boolean fullQueryOnPortfolioPositions) {
SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Querying the localRegion and the PR region
String[] queries;
if (fullQueryOnPortfolioPositions) {
queries = new String[] { "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct r.ID, status, mktValue " + "from $1 r, r.positions.values pVal TYPE Position " + "where r.status = 'active' AND pVal.mktValue >= 25.00", "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct * " + "from $1 r, r.positions.values pVal TYPE Position " + "where r.status = 'active' AND pVal.mktValue >= 25.00", "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct ID " + "from $1 r, r.positions.values pVal TYPE Position " + "where r.status = 'active' AND pVal.mktValue >= 25.00", "select distinct * " + "from $1 " + "where status = 'active'", "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct r from $1 r, " + "r.positions.values pVal TYPE Position where pVal.mktValue < $2", "select p.positions.get('acc') from $1 p" };
} else {
queries = new String[] { "ID = 0 OR ID = 1", "ID > 4 AND ID < 9", "ID = 5", "ID < 5 ", "ID <= 5" };
}
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 (int i = 0; i < expectedExceptions.length; i++) {
getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions[i] + "</ExpectedException>");
}
QueryService qs = getCache().getQueryService();
Object[] params;
try {
for (int j = 0; j < queries.length; j++) {
synchronized (region) {
if (fullQueryOnPortfolioPositions) {
params = new Object[] { local, new Double((j % 25) * 1.0 + 1) };
r[j][0] = qs.newQuery(queries[j]).execute(params);
} else {
r[j][0] = local.query(queries[j]);
}
if (fullQueryOnPortfolioPositions) {
params = new Object[] { region, new Double((j % 25) * 1.0 + 1) };
r[j][1] = qs.newQuery(queries[j]).execute(params);
} else {
r[j][1] = region.query(queries[j]);
}
}
}
compareTwoQueryResults(r, queries.length);
} catch (QueryInvocationTargetException e) {
// If cause is RegionDestroyedException then its ok
Throwable cause = e.getCause();
if (!(cause instanceof RegionDestroyedException)) {
// or 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;
}
use of util.TestException in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPROrderByQueryAndVerifyOrder.
public CacheSerializableRunnable getCacheSerializableRunnableForPROrderByQueryAndVerifyOrder(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[] { "p.status from /REGION_NAME p order by p.status", "status, ID from /REGION_NAME order by status, ID", "p.status, p.ID from /REGION_NAME p order by p.status, p.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", "key.ID, key.status from /REGION_NAME.keys key order by key.status desc, key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status, key.ID desc", "p.status, p.ID from /REGION_NAME p order by p.status asc, p.ID", "p.ID, p.status from /REGION_NAME p order by p.ID desc, p.status asc", "p.ID from /REGION_NAME p, p.positions.values order by p.ID", "p.ID, p.status from /REGION_NAME p, p.positions.values order by p.status, p.ID", "pos.secId from /REGION_NAME p, p.positions.values pos order by pos.secId", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by pos.secId, p.ID", "p.iD from /REGION_NAME p order by p.iD", "p.iD, p.status from /REGION_NAME p order by p.iD", "iD, status from /REGION_NAME order by iD", "p.getID() from /REGION_NAME p order by p.getID()", "p.names[1] from /REGION_NAME p order by p.names[1]", "p.position1.secId, p.ID from /REGION_NAME p order by p.position1.secId desc, p.ID", "p.ID, p.position1.secId from /REGION_NAME p order by p.position1.secId, p.ID", "e.key.ID from /REGION_NAME.entries e order by e.key.ID", "e.key.ID, e.value.status from /REGION_NAME.entries e order by e.key.ID", "e.key.ID, e.value.status from /REGION_NAME.entrySet e order by e.key.ID desc , e.value.status desc", "e.key, e.value 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 desc, e.key.pkid desc", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by p.ID, pos.secId", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by p.ID desc, pos.secId desc", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by p.ID desc, pos.secId" };
Object[][] r = new Object[1][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 = "SELECT DISTINCT ";
QueryService qs = getCache().getQueryService();
Object[] params;
StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
try {
for (final String query : queries) {
String qStr = null;
synchronized (region) {
// Execute on local region.
qStr = (distinct + query.replace("REGION_NAME", localRegion));
r[0][0] = qs.newQuery(qStr).execute();
// Execute on remote region.
qStr = (distinct + query.replace("REGION_NAME", regionName));
r[0][1] = qs.newQuery(qStr).execute();
ssORrs.CompareQueryResultsWithoutAndWithIndexes(r, 1, true, queries);
}
}
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;
}
use of util.TestException in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForRRAndPRQueryAndCompareResults.
public SerializableRunnableIF getCacheSerializableRunnableForRRAndPRQueryAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Querying the PR region
String[] queries = new String[] { "r1.ID = r2.id", "r1.ID = r2.id AND r1.ID > 5", "r1.ID = r2.id AND r1.status = 'active'", // "r1.ID = r2.id LIMIT 10",
"r1.ID = r2.id ORDER BY r1.ID", "r1.ID = r2.id ORDER BY r2.id", "r1.ID = r2.id ORDER BY r2.status", "r1.ID = r2.id AND r1.status != r2.status", "r1.ID = r2.id AND r1.status = r2.status", "r1.ID = r2.id AND r1.positions.size = r2.positions.size", "r1.ID = r2.id AND r1.positions.size > r2.positions.size", "r1.ID = r2.id AND r1.positions.size < r2.positions.size", "r1.ID = r2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = r2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = r2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
Object[][] r = new Object[queries.length][2];
Region region = null;
region = cache.getRegion(name);
assertNotNull(region);
region = cache.getRegion(coloName);
assertNotNull(region);
region = cache.getRegion(localName);
assertNotNull(region);
region = cache.getRegion(coloLocalName);
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>");
}
QueryService qs = getCache().getQueryService();
Object[] params;
try {
for (int j = 0; j < queries.length; j++) {
getCache().getLogger().info("About to execute local query: " + queries[j]);
Function func = new TestQueryFunction("testfunction");
Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, r1.positions.values pos1, /" + coloName + " r2 where " + queries[j]).execute(func).getResult();
r[j][0] = ((ArrayList) funcResult).get(0);
getCache().getLogger().info("About to execute local query: " + queries[j]);
SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, r1.positions.values pos1, /" + coloLocalName + " r2 where " + queries[j]).execute();
r[j][1] = r2.asList();
}
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
} catch (QueryInvocationTargetException e) {
// cause and see whether or 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