Search in sources :

Example 86 with Portfolio

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

the class HashIndexSetJUnitTest method testHashIndexContainsAllShouldReturnFalse.

@Test
public void testHashIndexContainsAllShouldReturnFalse() throws Exception {
    int numEntries = 100;
    setupHashIndexSet(numEntries);
    assertEquals(numEntries, his.size());
    portfolioSet.add(new Portfolio(numEntries + 1));
    assertFalse(his.containsAll(portfolioSet));
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 87 with Portfolio

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

the class HashIndexSetJUnitTest method testGetByKeyMultipleCollisions.

@Test
public void testGetByKeyMultipleCollisions() throws Exception {
    int numEntries = 20;
    int keyToLookup = 1;
    his = createHashIndexSet();
    Map<Integer, Portfolio> collectionOfPorts1 = this.createPortfolioObjects(numEntries, 0);
    Map<Integer, Portfolio> collectionOfPorts2 = this.createPortfolioObjects(numEntries, numEntries);
    addPortfoliosToHashIndexSet(collectionOfPorts1, his);
    addPortfoliosToHashIndexSet(collectionOfPorts2, his);
    assertEquals(numEntries * 2, his.size());
    Iterator iterator = his.get(keyToLookup);
    int numIterated = 0;
    while (iterator.hasNext()) {
        numIterated++;
        // verify that the returned values match what we lookedup
        assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
    }
    assertEquals(2, numIterated);
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 88 with Portfolio

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

the class HashIndexSetJUnitTest method testHashIndexSetAddWithNullKey.

@Test
public void testHashIndexSetAddWithNullKey() throws Exception {
    int numEntries = 100;
    setupHashIndexSet(numEntries);
    assertEquals(numEntries, his.size());
    his.add(null, new Portfolio(numEntries + 1));
    assertEquals(numEntries + 1, his.size());
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 89 with Portfolio

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

the class HashIndexSetJUnitTest method createPortfolioObjects.

/**
   * we are "indexed" on indexKey. Equality of portfolios is based on ID indexKeys are based on 0 ->
   * numEntries IDs are startID -> startID + numEntries
   * 
   * @param numToCreate how many portfolios to create
   * @param startID the ID value to start incrementing from
   */
private Map<Integer, Portfolio> createPortfolioObjects(int numToCreate, int startID) {
    Map<Integer, Portfolio> portfoliosMap = new HashMap<>();
    IntStream.range(0, numToCreate).forEach(e -> {
        Portfolio p = new Portfolio(e + startID);
        p.indexKey = e;
        portfoliosMap.put(p.indexKey, p);
    });
    return portfoliosMap;
}
Also used : HashMap(java.util.HashMap) Portfolio(org.apache.geode.cache.query.data.Portfolio)

Example 90 with Portfolio

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

the class HashIndexQueryIntegrationTest method testHashIndexWithAndQueryForLocalRegion.

/**
   * Tests that hash index with comparison between float and integer
   * 
   * @throws Exception
   */
// @Test
// public void testHashIndexQueryWithFloatVsIntegerCompareForLocalRegion() throws Exception {
// createLocalRegion("portfolios");
// int numEntries = 1000;
// 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.0f", "p.ID", "/portfolios
// p");
// }
/**
   * Tests that hash index with comparison between float and integer
   * 
   * @throws Exception
   */
// @Test
// public void testHashIndexNotEqualsWithFloatVsIntegerLocalRegion() throws Exception {
// createLocalRegion("portfolios");
// int numEntries = 1000;
// int numIds = 100;
// for (int i = 0; i < numEntries; i++) {
// Portfolio p = new Portfolio(i % (numIds));
// p.shortID = (short)i;
// region.put("" + i, p);
// }
// helpTestCRIndexForQuery("SELECT * FROM /portfolios p WHERE p.ID != 1.0f", "p.ID", "/portfolios
// p");
// }
/**
   * Tests that hash index with And query for local region
   * 
   * @throws Exception
   */
@Test
public void testHashIndexWithAndQueryForLocalRegion() 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 AND p.shortID > 0", "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)

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