use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class QRegionInterfaceJUnitTest method setUp.
@Before
public void setUp() throws java.lang.Exception {
CacheUtils.startCache();
Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
region.put("0", new Portfolio(0));
region.put("1", new Portfolio(1));
region.put("2", new Portfolio(2));
region.put("3", new Portfolio(3));
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class QRegionInterfaceJUnitTest method testUnsupportedExceptionInSubregionsMethod.
@Test
public void testUnsupportedExceptionInSubregionsMethod() {
Region region1 = null;
Region region2 = null;
try {
region1 = CacheUtils.getRegion("/Portfolios").createSubregion("region1", CacheUtils.getRegion("/Portfolios").getAttributes());
region2 = CacheUtils.getRegion("/Portfolios").createSubregion("region2", CacheUtils.getRegion("/Portfolios").getAttributes());
} catch (RegionExistsException ree) {
fail("Test failed because of Exception= " + ree);
}
region1.put("5", new Portfolio(0));
region1.put("5", new Portfolio(1));
region2.put("6", new Portfolio(2));
region2.put("6", new Portfolio(3));
Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.subregions(false) where remove('5')!= null");
try {
query.execute();
assertTrue(!region1.containsKey("5"));
assertTrue(!region2.containsKey("5"));
fail("The test should have thrown TypeMismatchException exception");
} catch (TypeMismatchException tme) {
// Test has passed successfuly as this exception is expected
} catch (Exception e) {
fail("Test failed because of Exception= " + e);
}
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class QRegionInterfaceJUnitTest method testGetEntries.
@Test
public void testGetEntries() throws Exception {
Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.entries where value.ID = 1 and key = '1'");
Collection result = (Collection) query.execute();
Region.Entry entry = (Region.Entry) result.iterator().next();
if (!entry.getKey().equals("1") || ((Portfolio) entry.getValue()).getID() != 1)
fail(query.getQueryString());
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class TestNewFunctionSSorRSIntegrationTest method testNewFunc.
@Test
public void testNewFunc() throws Exception {
Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
for (int i = 0; i < 4; i++) {
region.put("" + i, new Portfolio(i));
// CacheUtils.log(new Portfolio(i));
}
Object[][] r = new Object[2][2];
QueryService qs;
qs = CacheUtils.getQueryService();
String[] queries = { "SELECT DISTINCT * from /portfolios pf , pf.positions.values pos where status = 'inactive'", "select distinct * from /portfolios where ID > 1 " };
for (int i = 0; i < queries.length; i++) {
Query q = null;
q = CacheUtils.getQueryService().newQuery(queries[i]);
QueryObserverImpl observer1 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer1);
r[i][0] = q.execute();
}
qs.createIndex("sIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
qs.createIndex("iIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
for (int i = 0; i < queries.length; i++) {
Query q = null;
q = CacheUtils.getQueryService().newQuery(queries[i]);
QueryObserverImpl observer2 = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer2);
r[i][1] = q.execute();
if (!observer2.isIndexesUsed) {
fail("Index NOT Used");
}
}
StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
ssORrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class OrderByTestImplementation method testMultiColOrderByWithMultiIndexResultDefaultProjection.
@Test
public void testMultiColOrderByWithMultiIndexResultDefaultProjection() throws Exception {
String[] queries = { // Test case No. IUMR021
"SELECT distinct * FROM /portfolio1 pf1 where pkid = '12' and ID > 10 order by ID desc, pkid asc ", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '1' and ID > 10 order by ID asc, pkid desc ", "SELECT distinct * FROM /portfolio1 pf1 where pkid = '13'and ID > 10 and ID < 20 order by ID asc, pkid asc ", "SELECT distinct * FROM /portfolio1 pf1 where pkid <'9' and ID > 10 and ID < 20 order by ID desc , pkid desc", "SELECT distinct * FROM /portfolio1 pf1 where pkid = '15' and ID >= 10 and ID <= 20 order by ID desc, pkid desc ", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '1' and pkid <='9' and ID >= 10 and ID <= 20 order by ID asc, pkid asc", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '1' and ID != 10 order by ID asc, pkid asc ", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '1' and ID != 10 order by ID desc, pkid desc ", "SELECT distinct * FROM /portfolio1 pf1 where pkid = '17' and ID > 10 order by ID desc, pkid asc limit 5", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '17' and ID > 10 order by ID asc, pkid desc limit 5", "SELECT distinct * FROM /portfolio1 pf1 where pkid < '7' and ID > 10 and ID < 20 order by ID asc, pkid asc limit 5 ", "SELECT distinct * FROM /portfolio1 pf1 where pkid = '18' and ID > 10 and ID < 20 order by ID desc, pkid desc limit 5", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '1' and ID >= 10 and ID <= 20 order by ID desc, pkid asc limit 5", "SELECT distinct * FROM /portfolio1 pf1 where pkid != '17' and ID >= 10 and ID <= 20 order by ID asc, pkid desc limit 5", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '0' and ID != 10 order by ID asc, pkid asc limit 10", "SELECT distinct * FROM /portfolio1 pf1 where pkid > '1' and ID != 10 order by ID desc, pkid desc limit 10" };
Object[][] r = new Object[queries.length][2];
QueryService qs;
qs = CacheUtils.getQueryService();
Position.resetCounter();
// Create Regions
Region r1 = createRegion("portfolio1", Portfolio.class);
for (int i = 0; i < 50; i++) {
r1.put(i + "", new Portfolio(i));
}
// Execute Queries without Indexes
for (int i = 0; i < queries.length; i++) {
Query q = null;
try {
q = CacheUtils.getQueryService().newQuery(queries[i]);
CacheUtils.getLogger().info("Executing query: " + queries[i]);
r[i][0] = q.execute();
} catch (Exception e) {
e.printStackTrace();
fail(q.getQueryString());
}
}
// Create Indexes
this.createIndex("IDIndexPf1", IndexType.FUNCTIONAL, "ID", "/portfolio1");
this.createIndex("PKIDIndexPf1", IndexType.FUNCTIONAL, "pkid", "/portfolio1");
// Execute Queries with Indexes
for (int i = 0; i < queries.length; i++) {
Query q = null;
try {
q = CacheUtils.getQueryService().newQuery(queries[i]);
CacheUtils.getLogger().info("Executing query: " + queries[i]);
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
r[i][1] = q.execute();
SelectResults rcw = (SelectResults) r[i][1];
int indexLimit = queries[i].indexOf("limit");
int limit = -1;
boolean limitQuery = indexLimit != -1;
if (limitQuery) {
limit = Integer.parseInt(queries[i].substring(indexLimit + 5).trim());
}
assertTrue(!limitQuery || rcw.size() <= limit);
assertEquals("Ordered", rcw.getCollectionType().getSimpleClassName());
if (assertIndexUsedOnQueryNode() && !observer.isIndexesUsed) {
fail("Index is NOT uesd");
}
Iterator itr = observer.indexesUsed.iterator();
while (itr.hasNext()) {
String indexUsed = itr.next().toString();
if (!(indexUsed).equals("IDIndexPf1")) {
fail("<IDIndexPf1> was expected but found " + indexUsed);
}
// assertIndexDetailsEquals("statusIndexPf1",itr.next().toString());
}
int indxs = observer.indexesUsed.size();
System.out.println("**************************************************Indexes Used :::::: " + indxs + " Index Name: " + observer.indexName);
} catch (Exception e) {
e.printStackTrace();
fail(q.getQueryString());
}
}
StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, true, queries);
ssOrrs.compareExternallySortedQueriesWithOrderBy(queries, r);
}
Aggregations