Search in sources :

Example 41 with Portfolio

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());
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio)

Example 42 with Portfolio

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());
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio)

Example 43 with Portfolio

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());
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) Portfolio(org.apache.geode.cache.query.data.Portfolio) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) Iterator(java.util.Iterator) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 44 with Portfolio

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();
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache)

Example 45 with Portfolio

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);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Portfolio(org.apache.geode.cache.query.data.Portfolio) Index(org.apache.geode.cache.query.Index) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Portfolio (org.apache.geode.cache.query.data.Portfolio)520 Test (org.junit.Test)415 Region (org.apache.geode.cache.Region)302 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)298 SelectResults (org.apache.geode.cache.query.SelectResults)247 Query (org.apache.geode.cache.query.Query)235 QueryService (org.apache.geode.cache.query.QueryService)195 Index (org.apache.geode.cache.query.Index)121 AttributesFactory (org.apache.geode.cache.AttributesFactory)85 Iterator (java.util.Iterator)81 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)72 LocalRegion (org.apache.geode.internal.cache.LocalRegion)69 VM (org.apache.geode.test.dunit.VM)65 Host (org.apache.geode.test.dunit.Host)64 Cache (org.apache.geode.cache.Cache)62 CacheException (org.apache.geode.cache.CacheException)49 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)47 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)47 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)47 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)46