Search in sources :

Example 91 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class HashIndexQueryIntegrationTest method createData.

private void createData(Region region, int numEntries) {
    for (int i = 0; i < numEntries; i++) {
        Portfolio p = new Portfolio(i);
        region.put("" + i, p);
    }
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio)

Example 92 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class HashIndexQueryIntegrationTest method testHashIndexOnNonSequentialHashForReplicatedRegion.

/**
   * Tests that hash index on non sequential hashes for replicated region
   * 
   * @throws Exception
   */
@Test
public void testHashIndexOnNonSequentialHashForReplicatedRegion() throws Exception {
    createReplicatedRegion("portfolios");
    for (int i = 0; i < 100; i++) {
        Portfolio p = new Portfolio(i);
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    for (int i = 200; i < 300; i++) {
        Portfolio p = new Portfolio(i);
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    for (int i = 500; i < 600; i++) {
        Portfolio p = new Portfolio(i);
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    helpTestHashIndexForQuery("Select * FROM /portfolios p where p.ID != 1");
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 93 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class HashIndexQueryIntegrationTest method testHashIndexWithORQueryForLocalRegion.

/**
   * Tests that hash index with And query for local region
   * 
   * @throws Exception
   */
@Test
public void testHashIndexWithORQueryForLocalRegion() throws Exception {
    createLocalRegion("portfolios");
    int numEntries = 200;
    int numIds = 100;
    for (int i = 0; i < numEntries; i++) {
        Portfolio p = new Portfolio(i % (numIds));
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    helpTestHashIndexForQuery("SELECT * FROM /portfolios p WHERE p.ID = 1 OR p.ID = 2", "p.ID", "/portfolios p");
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 94 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class HashIndexQueryIntegrationTest method helpTestHashIndexRemoveFromCommonKeyQuery.

private void helpTestHashIndexRemoveFromCommonKeyQuery() throws Exception {
    int numEntries = 200;
    int numIds = 100;
    for (int i = 0; i < numEntries; i++) {
        Portfolio p = new Portfolio(i % (numIds));
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    Portfolio p2 = new Portfolio(10000);
    region.put("2", p2);
    p2.ID = 1000;
    region.put("2", p2);
    SelectResults noIndexResult = (SelectResults) qs.newQuery("Select * FROM /portfolios p where p.ID = 2").execute();
    region.clear();
    index = (HashIndex) qs.createHashIndex("idHash", "p.ID", "/portfolios p");
    for (int i = 0; i < numEntries; i++) {
        Portfolio p = new Portfolio(i % (numIds));
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    p2 = new Portfolio(10000);
    region.put("2", p2);
    p2.ID = 1000;
    region.put("2", p2);
    SelectResults results = (SelectResults) qs.newQuery("Select * FROM /portfolios p where p.ID = 2").execute();
    assertEquals(numEntries / numIds - 1, results.size());
    assertEquals(noIndexResult.size(), results.size());
    assertTrue(observer.indexUsed);
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Portfolio(org.apache.geode.cache.query.data.Portfolio)

Example 95 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class HashIndexQueryIntegrationTest method testHashIndexEqualsForMultipleResultQueryOnReplicatedRegion.

/**
   * Tests that hash index is used and that it returns the correct number of results on replicated
   * region
   * 
   * @throws Exception
   */
@Test
public void testHashIndexEqualsForMultipleResultQueryOnReplicatedRegion() throws Exception {
    createReplicatedRegion("portfolios");
    // Create the data
    int numEntries = 200;
    int numIds = 100;
    for (int i = 0; i < numEntries; i++) {
        Portfolio p = new Portfolio(i % (numIds));
        p.shortID = (short) i;
        region.put("" + i, p);
    }
    helpTestHashIndexForQuery("Select * FROM /portfolios p where p.ID = 1");
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) 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