use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PRQueryDUnitTest method testQueryResultsFromMembers.
@Test
public void testQueryResultsFromMembers() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
final VM datastore1 = host.getVM(2);
final VM datastore2 = host.getVM(3);
final int totalBuckets = 10;
final int redCop = 0;
CacheSerializableRunnable createPR = new CacheSerializableRunnable("Create PR") {
public void run2() throws CacheException {
AttributesFactory attr = new AttributesFactory();
PartitionAttributes prAttr = new PartitionAttributesFactory().setRedundantCopies(redCop).setTotalNumBuckets(totalBuckets).create();
attr.setPartitionAttributes(prAttr);
getCache().createRegion(rName, attr.create());
}
};
datastore1.invoke(createPR);
datastore2.invoke(createPR);
AttributesFactory attr = new AttributesFactory();
PartitionAttributes prAttr = new PartitionAttributesFactory().setRedundantCopies(redCop).setTotalNumBuckets(totalBuckets).create();
attr.setPartitionAttributes(prAttr);
PartitionedRegion pr = (PartitionedRegion) getCache().createRegion(rName, attr.create());
// Create bucket zero, one and two
int numEntries = 100;
for (int i = 1; i <= numEntries; i++) {
pr.put(new Integer(i), new Portfolio(i));
}
int[] limit = new int[] { 10, 15, 30, 0, 1, 9 };
String[] queries = new String[] { "select * from " + pr.getFullPath() + " LIMIT " + limit[0], "select * from " + pr.getFullPath() + " LIMIT " + limit[1], "select * from " + pr.getFullPath() + " LIMIT " + limit[2], "select * from " + pr.getFullPath() + " LIMIT " + limit[3], "select * from " + pr.getFullPath() + " LIMIT " + limit[4], "select * from " + pr.getFullPath() + " where ID > 10 LIMIT " + limit[5] };
try {
for (int q = 0; q < queries.length; q++) {
Object[] params = new Object[0];
final DefaultQuery query = (DefaultQuery) getCache().getQueryService().newQuery(queries[q]);
final SelectResults results = query.getSimpleSelect().getEmptyResultSet(params, getCache(), query);
// TODO assert this is the correct set of bucket Ids,
final HashSet<Integer> buckets = new HashSet<Integer>();
for (int i = 0; i < totalBuckets; i++) {
buckets.add(new Integer(i));
}
final PartitionedRegionQueryEvaluator qe = new PartitionedRegionQueryEvaluator(pr.getSystem(), pr, query, params, results, buckets);
class MyTestHook implements PartitionedRegionQueryEvaluator.TestHook {
public HashMap resultsPerMember = new HashMap();
public void hook(int spot) throws RuntimeException {
int size = 0;
if (spot == 3) {
for (Object mr : qe.getResultsPerMember().entrySet()) {
Map.Entry e = (Map.Entry) mr;
Collection<Collection> results = (Collection<Collection>) e.getValue();
for (Collection<Object> r : results) {
if (this.resultsPerMember.containsKey(e.getKey())) {
this.resultsPerMember.put(e.getKey(), new Integer(r.size() + ((Integer) this.resultsPerMember.get(e.getKey())).intValue()));
} else {
this.resultsPerMember.put(e.getKey(), new Integer(r.size()));
}
}
}
}
}
}
;
final MyTestHook th = new MyTestHook();
qe.queryBuckets(th);
for (Object r : th.resultsPerMember.entrySet()) {
Map.Entry e = (Map.Entry) r;
Integer res = (Integer) e.getValue();
LogWriterUtils.getLogWriter().info("PRQueryDUnitTest#testQueryResultsFromMembers : \n" + "Query [" + queries[q] + "] Member : " + e.getKey() + " results size :" + res.intValue());
assertEquals("Query [" + queries[q] + "]: The results returned by the member does not match the query limit size : Member : " + e.getKey(), limit[q], res.intValue());
}
}
} finally {
getCache().close();
}
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForPersistentPRCreate.
public CacheSerializableRunnable getCacheSerializableRunnableForPersistentPRCreate(final String regionName, final int redundancy, final Class constraint) {
SerializableRunnable createPrRegion;
createPrRegion = new CacheSerializableRunnable(regionName) {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionedregion = null;
try {
cache.createDiskStoreFactory().setDiskDirs(JUnit4CacheTestCase.getDiskDirs()).create("diskstore");
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
attr.setDiskStoreName("diskstore");
PartitionAttributesFactory paf = new PartitionAttributesFactory();
PartitionAttributes prAttr = paf.setRedundantCopies(redundancy).create();
attr.setPartitionAttributes(prAttr);
partitionedregion = cache.createRegion(regionName, attr.create());
} catch (IllegalStateException ex) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().warning("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Creation caught IllegalStateException", ex);
}
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
assertNotNull("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Partitioned Region ref null", partitionedregion);
assertTrue("PRQueryDUnitHelper#getCacheSerializableRunnableForPRCreateWithRedundancy: Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
}
};
return (CacheSerializableRunnable) createPrRegion;
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PRQueryDUnitTest method testDataLossDuringQueryProcessor.
/**
* Test data loss (bucket 0) while the PRQueryEvaluator is processing the query loop
*
* @throws Exception
*/
@Test
public void testDataLossDuringQueryProcessor() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
final VM datastore1 = host.getVM(2);
final VM datastore2 = host.getVM(3);
final int totalBuckets = 11;
final int redCop = 0;
CacheSerializableRunnable createPR = new CacheSerializableRunnable("Create PR") {
@Override
public void run2() throws CacheException {
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(String.class);
PartitionAttributes prAttr = new PartitionAttributesFactory().setRedundantCopies(redCop).setTotalNumBuckets(totalBuckets).create();
attr.setPartitionAttributes(prAttr);
getCache().createRegion(rName, attr.create());
}
};
datastore1.invoke(createPR);
datastore2.invoke(createPR);
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(String.class);
PartitionAttributes prAttr = new PartitionAttributesFactory().setRedundantCopies(redCop).setTotalNumBuckets(totalBuckets).setLocalMaxMemory(0).create();
attr.setPartitionAttributes(prAttr);
PartitionedRegion pr = (PartitionedRegion) getCache().createRegion(rName, attr.create());
// Create bucket zero, one and two
pr.put(new Integer(0), "zero");
pr.put(new Integer(1), "one");
pr.put(new Integer(2), "two");
class MyTestHook implements PartitionedRegionQueryEvaluator.TestHook {
public boolean done = false;
public void hook(int spot) throws RuntimeException {
if (spot == 4) {
synchronized (this) {
if (done) {
return;
}
this.done = true;
}
datastore1.invoke(disconnectVM());
datastore2.invoke(disconnectVM());
}
}
}
;
final MyTestHook th = new MyTestHook();
// add expected exception strings
final IgnoredException ex = IgnoredException.addIgnoredException("Data loss detected");
try {
Object[] params = new Object[0];
final DefaultQuery query = (DefaultQuery) getCache().getQueryService().newQuery("select distinct * from " + pr.getFullPath());
final SelectResults results = query.getSimpleSelect().getEmptyResultSet(params, getCache(), query);
// TODO assert this is the correct set of bucket Ids,
final HashSet<Integer> buckets = new HashSet<Integer>();
for (int i = 0; i < 3; i++) {
buckets.add(new Integer(i));
}
PartitionedRegionQueryEvaluator qe = new PartitionedRegionQueryEvaluator(pr.getSystem(), pr, query, params, results, buckets);
qe.queryBuckets(th);
assertTrue(th.done);
assertTrue(false);
} catch (QueryException expected) {
assertTrue(th.done);
} finally {
ex.remove();
getCache().close();
}
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PdxOrderByJUnitTest method configurePR.
private Region configurePR() {
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
// factory.setDataPolicy(DataPolicy.PARTITION);
PartitionAttributes prAttr = paf.setTotalNumBuckets(20).setRedundantCopies(0).create();
factory.setPartitionAttributes(prAttr);
return createRegion(this.regionName, this.rootRegionName, factory.create());
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForMemLruWithMaxMem.
@Test
public void testPartitionedRegionAttributesForMemLruWithMaxMem() throws Exception {
final int redundantCopies = 1;
final int maxMem = 25;
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setStatisticsEnabled(true);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundantCopies);
paf.setTotalMaxMemory(500);
paf.setLocalMaxMemory(100);
AttributesFactory fac = new AttributesFactory(attrs);
fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(maxMem, null, EvictionAction.LOCAL_DESTROY));
fac.setPartitionAttributes(paf.create());
cache.createRegion("parRoot", fac.create());
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("parRoot");
assertNotNull(region);
RegionAttributes regionAttrs = region.getAttributes();
PartitionAttributes pa = regionAttrs.getPartitionAttributes();
EvictionAttributes ea = regionAttrs.getEvictionAttributes();
assertEquals(pa.getRedundantCopies(), 1);
assertEquals(pa.getLocalMaxMemory(), 100);
assertEquals(pa.getTotalMaxMemory(), 500);
assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
assertEquals(ea.getAction(), EvictionAction.LOCAL_DESTROY);
assertNotSame(ea.getMaximum(), maxMem);
assertEquals(ea.getMaximum(), pa.getLocalMaxMemory());
}
Aggregations