use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class CopyOnReadIndexJUnitTest method helpTestCopyOnReadFalse.
private void helpTestCopyOnReadFalse(String queryString, int expectedResultsSize, int numObjects, int objectsAndResultsMultiplier, boolean hasIndex, boolean isPR, boolean containsInnerQuery) throws Exception {
int numInstances = numObjects * objectsAndResultsMultiplier;
if (hasIndex && isPR) {
numInstances += numObjects * objectsAndResultsMultiplier;
}
assertEquals("Unexpected number of Portfolio instances" + queryString, numInstances, Portfolio.instanceCount.get());
// execute query
QueryService qs = utils.getCache().getQueryService();
Query query = qs.newQuery(queryString);
SelectResults results = (SelectResults) query.execute();
assertEquals("No results were found", expectedResultsSize * objectsAndResultsMultiplier, results.size());
for (Object o : results) {
if (o instanceof Portfolio) {
Portfolio p = (Portfolio) o;
p.status = "discardStatus";
} else {
Struct struct = (Struct) o;
Portfolio p = (Portfolio) struct.getFieldValues()[0];
p.status = "discardStatus";
}
}
if (!hasIndex && isPR) {
// Copy on read is false, due to logic in local region
// when we deserialize, we end up caching the deserialized value
// This is why we don't have to worry about inner queries increasing the count
numInstances += numObjects * objectsAndResultsMultiplier;
}
assertEquals("Unexpected number of Portfolio instances" + queryString, numInstances, Portfolio.instanceCount.get());
results = (SelectResults) query.execute();
assertEquals("No results were found", expectedResultsSize * objectsAndResultsMultiplier, results.size());
for (Object o : results) {
if (o instanceof Portfolio) {
Portfolio p = (Portfolio) o;
assertEquals("status should have been changed", "discardStatus", p.status);
} else {
Struct struct = (Struct) o;
Portfolio p = (Portfolio) struct.getFieldValues()[0];
assertEquals("status should have been changed", "discardStatus", p.status);
}
}
// Unlike the copy on read case, we do not need to increase the instance count
// This is because of logic in LocalRegion where if copy on read is false, we cache the
// deserialized value
assertEquals("Unexpected number of Portfolio instances" + queryString, numInstances, Portfolio.instanceCount.get());
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class CopyOnReadIndexJUnitTest method helpTestCopyOnRead.
private void helpTestCopyOnRead(String queryString, int expectedResultsSize, int numObjects, int objectsAndResultsMultiplier, boolean hasIndex, boolean isPR, boolean containsInnerQuery) throws Exception {
int expectedResultsSizeMultiplied = expectedResultsSize * objectsAndResultsMultiplier;
int numInstances = numObjects * objectsAndResultsMultiplier;
// We are a 1 VM test, replicated regions would put the actual domain object into the cache
if (hasIndex && isPR) {
// If we are PR we serialize the values
// BUT if we have an index, we deserialize the values, so our instance count is double of our
// put amount so far
numInstances += numObjects * objectsAndResultsMultiplier;
}
assertEquals("Unexpected number of Portfolio instances", numInstances, Portfolio.instanceCount.get());
// execute query
QueryService qs = utils.getCache().getQueryService();
Query query = qs.newQuery(queryString);
SelectResults results = (SelectResults) query.execute();
assertEquals("Results did not match expected count for query" + queryString, expectedResultsSizeMultiplied, results.size());
for (Object o : results) {
if (o instanceof Portfolio) {
Portfolio p = (Portfolio) o;
p.status = "discardStatus";
} else {
Struct struct = (Struct) o;
Portfolio p = (Portfolio) struct.getFieldValues()[0];
p.status = "discardStatus";
}
}
if (!hasIndex && isPR) {
// We are PR and we do not have an index, so we must deserialize all the values in the cache
// at this point
numInstances += (numObjects * objectsAndResultsMultiplier);
if (containsInnerQuery) {
// if we have an inner query, it would deserialize all objects for the inner query as well
numInstances += numObjects * objectsAndResultsMultiplier;
}
}
// So with all the deserialized objects we must also combine the query results of the query due
// to copy on read
assertEquals("Unexpected number of Portfolio instances for query " + query, numInstances + expectedResultsSizeMultiplied, Portfolio.instanceCount.get());
results = (SelectResults) query.execute();
assertEquals("No results were found", expectedResultsSizeMultiplied, results.size());
for (Object o : results) {
if (o instanceof Portfolio) {
Portfolio p = (Portfolio) o;
assertEquals("status should not have been changed", "testStatus", p.status);
} else {
Struct struct = (Struct) o;
Portfolio p = (Portfolio) struct.getFieldValues()[0];
assertEquals("status should not have been changed", "testStatus", p.status);
}
}
if (!hasIndex && isPR) {
// Again, because we have no index, we must deserialize the values in the region
numInstances += (numObjects * objectsAndResultsMultiplier);
if (containsInnerQuery) {
// If we have an inner query, we must also deserialize the values in the region for this
// query
// We have some interesting logic in LocalRegion when deserializing. Based on these flags
// we do not store the deserialized instance back in the cache
numInstances += numObjects * objectsAndResultsMultiplier;
}
}
// So with all the deserialized objects we must also combine the query results of two queries at
// this point. These results themselves would have been copied
assertEquals("Unexpected number of Portfolio instances", numInstances + expectedResultsSizeMultiplied * 2, Portfolio.instanceCount.get());
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class StructSetJUnitTest method testIntersectionAndRetainAll.
@Test
public void testIntersectionAndRetainAll() {
String[] names = { "p", "pos" };
ObjectType[] types = { TypeUtils.OBJECT_TYPE, TypeUtils.OBJECT_TYPE };
StructTypeImpl sType = new StructTypeImpl(names, types);
StructSet set1 = new StructSet(sType);
Portfolio ptf = new Portfolio(0);
Iterator pIter = ptf.positions.values().iterator();
while (pIter.hasNext()) {
Object[] arr = { ptf, pIter.next() };
set1.addFieldValues(arr);
}
StructSet set2 = new StructSet(sType);
pIter = ptf.positions.values().iterator();
while (pIter.hasNext()) {
Object[] arr = { ptf, pIter.next() };
set2.addFieldValues(arr);
}
assertEquals(2, set1.size());
assertEquals(2, set2.size());
// tests that retainAll does not modify set1
assertTrue(!set1.retainAll(set2));
assertEquals(2, set1.size());
assertEquals(2, set2.size());
SelectResults sr = QueryUtils.intersection(set1, set2, null);
assertEquals(2, sr.size());
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class AsynchIndexMaintenanceJUnitTest method init.
private void init() throws Exception {
idSet = new HashSet();
CacheUtils.startCache();
Cache cache = CacheUtils.getCache();
region = CacheUtils.createRegion("portfolio", Portfolio.class, false);
qs = cache.getQueryService();
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class AsynchIndexMaintenanceJUnitTest method testIndexMaintenanceBasedOnThreshhold.
@Test
public void testIndexMaintenanceBasedOnThreshhold() throws Exception {
System.getProperties().put(DistributionConfig.GEMFIRE_PREFIX + "AsynchIndexMaintenanceThreshold", "50");
System.getProperties().put(DistributionConfig.GEMFIRE_PREFIX + "AsynchIndexMaintenanceInterval", "0");
final Index ri = qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "p.getID", "/portfolio p");
for (int i = 0; i < 49; ++i) {
region.put("" + (i + 1), new Portfolio(i + 1));
idSet.add((i + 1) + "");
}
// assertIndexDetailsEquals(0, getIndexSize(ri));
region.put("50", new Portfolio(50));
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return (getIndexSize(ri) == 50);
}
public String description() {
return "valueToEntriesMap never became 50";
}
};
Wait.waitForCriterion(ev, 3000, 200, true);
}
Aggregations