use of org.apache.geode.cache.query.data.Position in project geode by apache.
the class QueryDataInconsistencyDUnitTest method testRangeIndexWithIndexAndQueryFromCluaseMisMatch.
// GEODE-925: time sensitive, async actions, short timeouts
@Category(FlakyTest.class)
@Test
public void testRangeIndexWithIndexAndQueryFromCluaseMisMatch() {
// TODO: fix misspelling
// Create caches
Properties props = new Properties();
server.invoke(() -> PRClientServerTestBase.createCacheInVm(props));
server.invoke(new CacheSerializableRunnable("create indexes") {
@Override
public void run2() throws CacheException {
cache = CacheFactory.getAnyInstance();
Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(repRegionName);
IndexManager.testHook = null;
// Create common Portfolios and NewPortfolios
Position.cnt = 0;
for (int j = cnt; j < cntDest; j++) {
region.put(new Integer(j), new Portfolio(j));
}
QueryService qs = CacheFactory.getAnyInstance().getQueryService();
try {
Index index = qs.createIndex("posIndex", "pos.secId", "/" + repRegionName + " p, p.collectionHolderMap.values coll, p.positions.values pos");
assertEquals(12, index.getStatistics().getNumberOfKeys());
} catch (Exception e) {
fail("Index creation failed");
}
}
});
// Invoke update from client and stop in updateIndex
// first before updating the RegionEntry and second after updating
// the RegionEntry.
AsyncInvocation putThread = server.invokeAsync(new CacheSerializableRunnable("update a Region Entry") {
@Override
public void run2() throws CacheException {
Region repRegion = CacheFactory.getAnyInstance().getRegion(repRegionName);
IndexManager.testHook = new IndexManagerTestHook();
// This portfolio with same ID must have different positions.
repRegion.put(new Integer("1"), new Portfolio(1));
// above call must be hooked in BEFORE_UPDATE_OP call.
}
});
server.invoke(new CacheSerializableRunnable("query on server") {
@Override
public void run2() throws CacheException {
QueryService qs = CacheFactory.getAnyInstance().getQueryService();
Position pos1 = null;
while (!hooked) {
Wait.pause(100);
}
try {
Object rs = qs.newQuery("<trace> select pos from /" + repRegionName + " p, p.positions.values pos where pos.secId = 'APPL' AND p.ID = 1").execute();
CacheFactory.getAnyInstance().getLogger().fine("Shobhit: " + rs);
assertTrue(rs instanceof SelectResults);
pos1 = (Position) ((SelectResults) rs).iterator().next();
if (!pos1.secId.equals("APPL")) {
fail("Query thread did not verify index results even when RE is under update");
IndexManager.testHook = null;
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Query execution failed on server.", e);
IndexManager.testHook = null;
} finally {
// Let client put go further.
hooked = false;
}
while (!hooked) {
Wait.pause(100);
}
try {
Object rs = qs.newQuery("select pos from /" + repRegionName + " p, p.positions.values pos where pos.secId = 'APPL' AND p.ID = 1").execute();
assertTrue(rs instanceof SelectResults);
if (((SelectResults) rs).size() > 0) {
Position pos2 = (Position) ((SelectResults) rs).iterator().next();
if (pos2.equals(pos1)) {
fail("Query thread did not verify index results even when RE is under update and " + "RegionEntry value has been modified before releasing the lock");
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Query execution failed on server.");
} finally {
// Let client put go further.
hooked = false;
IndexManager.testHook = null;
}
}
});
// GEODE-925 occurs here and this is very short join 200
ThreadUtils.join(putThread, 200);
// millis
}
use of org.apache.geode.cache.query.data.Position in project geode by apache.
the class LimitClauseJUnitTest method testLimitOnJunctionWithCompactRangeIndexedFieldWithAndClauseJunctionNonIndexedField.
@Test
public void testLimitOnJunctionWithCompactRangeIndexedFieldWithAndClauseJunctionNonIndexedField() throws Exception {
Query query;
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 0; i <= 15; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 1;
p.positions.clear();
p.positions.put("IBM", new Position("IBM", i));
region.put("KEY" + i, p);
}
for (int i = 16; i < 21; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 2;
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
// Create Index on ID
Index idIndex = qs.createIndex("idIndex", "P.ID", "/portfolios1 P");
String queryString = "SELECT * FROM /portfolios1 P WHERE P.ID > 9 AND P.ID < 20 AND P.shortID > 1 AND P.shortID < 3 LIMIT 5";
query = qs.newQuery(queryString);
assertNotNull(idIndex);
SelectResults resultsWithIndex = (SelectResults) query.execute();
assertFalse(observer.limitAppliedAtIndex);
assertEquals(5, resultsWithIndex.size());
}
use of org.apache.geode.cache.query.data.Position in project geode by apache.
the class LimitClauseJUnitTest method testLimitOnCompactRangeIndexedFieldWithAndClauseJunctionNonIndexedField.
@Test
public void testLimitOnCompactRangeIndexedFieldWithAndClauseJunctionNonIndexedField() throws Exception {
Query query;
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 0; i <= 15; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 1;
p.positions.clear();
p.positions.put("IBM", new Position("IBM", i));
region.put("KEY" + i, p);
}
for (int i = 16; i < 21; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 2;
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
// Create Index on ID
Index idIndex = qs.createIndex("idIndex", "P.ID", "/portfolios1 P");
String queryString = "SELECT * FROM /portfolios1 P WHERE P.ID = 10 AND P.shortID > 1 AND P.shortID < 3 LIMIT 5";
query = qs.newQuery(queryString);
assertNotNull(idIndex);
SelectResults resultsWithIndex = (SelectResults) query.execute();
assertTrue(observer.limitAppliedAtIndex);
assertEquals(5, resultsWithIndex.size());
}
use of org.apache.geode.cache.query.data.Position in project geode by apache.
the class IndexWithSngleFrmAndMultCondQryJUnitTest method testNonDistinctOrCondResults.
@Test
public void testNonDistinctOrCondResults() throws Exception {
Region region = CacheUtils.createRegion("pos", Portfolio.class);
for (int i = 0; i < 10; i++) {
region.put("" + i, new Portfolio(i));
}
for (int i = 10; i < 20; i++) {
Portfolio p = new Portfolio(i);
if (i % 2 == 0) {
p.status = null;
}
region.put("" + i, p);
}
QueryService qs;
qs = CacheUtils.getQueryService();
String[] queries = { "SELECT * FROM /pos pf, positions.values pos where pf.ID > 0 OR pf.status='active' OR pos.secId != 'IBM'", "SELECT * FROM /pos pf where pf.ID > 0 OR pf.status='active'", "SELECT * FROM /pos pf where pf.ID > 0 OR pf.status LIKE 'act%'", "SELECT * FROM /pos pf where pf.ID > 0 OR pf.status IN SET('active', 'inactive')" };
SelectResults[] sr = new SelectResults[queries.length];
for (int i = 0; i < queries.length; i++) {
Query q = null;
try {
q = CacheUtils.getQueryService().newQuery(queries[i]);
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
sr[i] = (SelectResults) q.execute();
if (observer.isIndexesUsed) {
fail("How could index be present when not created!?");
}
} catch (Exception e) {
e.printStackTrace();
fail(q.getQueryString());
}
}
// Verify Results
for (int i = 0; i < sr.length; i++) {
Set resultSet = sr[i].asSet();
// Check Element Type
if (queries[i].contains("values")) {
assertTrue("Checking Element type for Query: [" + queries[i] + "] results", sr[i].getCollectionType().getElementType().toString().equals("struct<pf:org.apache.geode.cache.query.data.Portfolio,pos:java.lang.Object>"));
// Check Size of results
assertEquals("Checking Element type for Query: [" + queries[i] + "] results", 40, resultSet.size());
} else {
assertTrue("Checking Element type for Query: [" + queries[i] + "] results", sr[i].getCollectionType().getElementType().toString().equals("org.apache.geode.cache.query.data.Portfolio"));
// Check Size of results
assertEquals("Checking Element type for Query: [" + queries[i] + "] results", 20, resultSet.size());
}
Iterator itr = resultSet.iterator();
while (itr.hasNext()) {
Object obj = itr.next();
if (sr[i].getCollectionType().getElementType().toString().equals("struct<pf:org.apache.geode.cache.query.data.Portfolio,pos:java.lang.Object>")) {
Object[] values = ((Struct) obj).getFieldValues();
Portfolio port = (Portfolio) values[0];
Position pos = (Position) values[1];
if (!(port.getID() > 0 || port.status.equals("active") || pos.secId.equals("IBM"))) {
fail("Result object" + obj + " failed to satisfy all OR conditions of where clause of query " + queries[i]);
}
} else {
Portfolio port = (Portfolio) obj;
if (!(port.getID() > 0 || port.status.equals("active"))) {
fail("Result object" + port + " failed to satisfy all OR conditions of where clause of query " + queries[i]);
}
}
}
}
}
use of org.apache.geode.cache.query.data.Position in project geode by apache.
the class LimitClauseJUnitTest method testLimitJunctionOnRangeIndexedFieldWithAndClauseOnNonIndexedField.
@Test
public void testLimitJunctionOnRangeIndexedFieldWithAndClauseOnNonIndexedField() throws Exception {
Query query;
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 0; i <= 15; i++) {
Portfolio p = new Portfolio(i);
p.positions.clear();
p.positions.put("IBM", new Position("IBM", i));
region.put("KEY" + i, p);
}
for (int i = 16; i < 21; i++) {
Portfolio p = new Portfolio(i);
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
// Create Index on ID
Index idIndex = qs.createIndex("idIndex", IndexType.FUNCTIONAL, "P.ID", "/portfolios1 P, P.positions.values POS");
String queryString = "SELECT * FROM /portfolios1 P, P.positions.values POS WHERE P.ID > 9 AND P.ID < 21 AND POS.secId = 'VMW' LIMIT 5";
query = qs.newQuery(queryString);
assertNotNull(idIndex);
SelectResults resultsWithIndex = (SelectResults) query.execute();
assertFalse(observer.limitAppliedAtIndex);
assertEquals(5, resultsWithIndex.size());
}
Aggregations