use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRColocatedDataSetQueryAndCompareResults.
public SerializableRunnableIF getCacheSerializableRunnableForPRColocatedDataSetQueryAndCompareResults(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 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 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 org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRIndexCreate.
/**
* This function creates a appropriate index on a PR given the name and other parameters.
*/
public CacheSerializableRunnable getCacheSerializableRunnableForPRIndexCreate(final String prRegionName, final String indexName, final String indexedExpression, final String fromClause, final String alias) {
SerializableRunnable prIndexCreator = new CacheSerializableRunnable("PartitionedIndexCreator") {
@Override
public void run2() {
try {
Cache cache = getCache();
QueryService qs = cache.getQueryService();
Region region = cache.getRegion(prRegionName);
LogWriter logger = cache.getLogger();
if (null != fromClause) {
logger.info("Test Creating index with Name : [ " + indexName + " ] " + "IndexedExpression : [ " + indexedExpression + " ] Alias : [ " + alias + " ] FromClause : [ " + fromClause + " " + alias + " ] ");
Index parIndex = qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause);
logger.info("Index creted on partitioned region : " + parIndex);
} else {
logger.info("Test Creating index with Name : [ " + indexName + " ] " + "IndexedExpression : [ " + indexedExpression + " ] Alias : [ " + alias + " ] FromClause : [ " + region.getFullPath() + " " + alias + " ] ");
Index parIndex = qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, region.getFullPath() + " " + alias);
logger.info("Index creted on partitioned region : " + parIndex);
logger.info("Number of buckets indexed in the partitioned region locally : " + "" + ((PartitionedIndex) parIndex).getNumberOfIndexedBuckets() + " and remote buckets indexed : " + ((PartitionedIndex) parIndex).getNumRemoteBucketsIndexed());
}
/*
* assertIndexDetailsEquals("Max num of buckets in the partiotion regions and the
* " + "buckets indexed should be equal",
* ((PartitionedRegion)region).getTotalNumberOfBuckets(),
* (((PartionedIndex)parIndex).getNumberOfIndexedBucket()+((PartionedIndex)parIndex).
* getNumRemtoeBucketsIndexed())); should put all the assetion in a seperate function.
*/
} catch (Exception ex) {
Assert.fail("Creating Index in this vm failed : ", ex);
}
}
};
return (CacheSerializableRunnable) prIndexCreator;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRPuts.
/**
* This function puts portfolio objects into the created Region (PR or Local) *
*
* @param regionName
* @param portfolio
* @param to
* @param from
* @return cacheSerializable object
*/
public CacheSerializableRunnable getCacheSerializableRunnableForPRPuts(final String regionName, final Object[] portfolio, final int from, final int to) {
SerializableRunnable prPuts = new CacheSerializableRunnable("PRPuts") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
for (int j = from; j < to; j++) region.put(new Integer(j), portfolio[j]);
}
};
return (CacheSerializableRunnable) prPuts;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults.
/**
* This function <br>
* 1. Creates & executes a query with Constants on the given PR Region <br>
* 2. Executes the same query on the local region <br>
* 3. Compares the appropriate resultSet <br>
*/
public CacheSerializableRunnable getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults(final String regionName, final String localRegion) {
SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Querying the localRegion and the PR region
String[] query = { "TRUE", "FALSE", "UNDEFINED", "NULL" };
Object[][] r = new Object[query.length][2];
Region local = cache.getRegion(localRegion);
Region region = cache.getRegion(regionName);
try {
for (int j = 0; j < query.length; j++) {
r[j][0] = local.query(query[j]);
r[j][1] = region.query(query[j]);
}
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Queries Executed successfully on Local region & PR Region");
compareTwoQueryResults(r, query.length);
} catch (QueryException e) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught an Exception while querying Constants" + e, e);
fail("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryWithConstantsAndComparingResults: Caught Exception while querying Constants. Exception is " + e);
}
}
};
return (CacheSerializableRunnable) PrRegion;
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForColocatedChildCreate.
/**
* This function creates the parent region of colocated pair of PR's given the scope & the
* redundancy parameters for the parent *
*
* @param regionName
* @param redundancy
* @param constraint
* @param isPersistent
* @return cacheSerializable object
*/
public CacheSerializableRunnable getCacheSerializableRunnableForColocatedChildCreate(final String regionName, final int redundancy, final Class constraint, boolean isPersistent) {
final String childRegionName = regionName + "Child";
final String diskName = "disk";
SerializableRunnable createPrRegion;
createPrRegion = new CacheSerializableRunnable(regionName + "-ChildRegion") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionedregion = null;
Region childRegion = null;
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
if (isPersistent) {
DiskStore ds = cache.findDiskStore(diskName);
if (ds == null) {
// ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs())
ds = cache.createDiskStoreFactory().setDiskDirs(org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase.getDiskDirs()).create(diskName);
}
attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
attr.setDiskStoreName(diskName);
} else {
attr.setDataPolicy(DataPolicy.PARTITION);
attr.setDiskStoreName(null);
}
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundancy);
attr.setPartitionAttributes(paf.create());
// skip parent region creation
// partitionedregion = cache.createRegion(regionName, attr.create());
// child region
attr.setValueConstraint(constraint);
paf.setColocatedWith(regionName);
attr.setPartitionAttributes(paf.create());
childRegion = cache.createRegion(childRegionName, attr.create());
}
};
return (CacheSerializableRunnable) createPrRegion;
}
Aggregations