use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method checkSqlQueryEvents.
/**
* @throws Exception If failed.
*/
private void checkSqlQueryEvents() throws Exception {
final IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
final boolean evtsDisabled = cache.getConfiguration(CacheConfiguration.class).isEventsDisabled();
final CountDownLatch execLatch = new CountDownLatch(evtsDisabled ? 0 : cacheMode() == REPLICATED ? 1 : gridCount());
IgnitePredicate[] lsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
if (evtsDisabled)
fail("Cache events are disabled");
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(cache.getName(), qe.cacheName());
assertNotNull(qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertArrayEquals(new Integer[] { 10 }, qe.arguments());
execLatch.countDown();
return true;
}
};
grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED);
lsnrs[i] = pred;
}
try {
for (int i = 0; i < 20; i++) cache.put(i, i);
QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= ?").setArgs(10));
q.getAll();
assert execLatch.await(1000, MILLISECONDS);
} finally {
for (int i = 0; i < gridCount(); i++) grid(i).events().stopLocalListen(lsnrs[i], EVT_CACHE_QUERY_EXECUTED);
}
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteClientReconnectQueriesTest method testQueryReconnect.
/**
* @throws Exception If failed.
*/
public void testQueryReconnect() throws Exception {
Ignite cln = grid(serverCount());
assertTrue(cln.cluster().localNode().isClient());
final Ignite srv = clientRouter(cln);
final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE);
final IgniteCache<Integer, Person> srvCache = srv.getOrCreateCache(QUERY_CACHE);
clnCache.put(1, new Person(1, "name1", "surname1"));
clnCache.put(2, new Person(2, "name2", "surname2"));
clnCache.put(3, new Person(3, "name3", "surname3"));
final SqlQuery<Integer, Person> qry = new SqlQuery<>(Person.class, "_key <> 0");
qry.setPageSize(1);
QueryCursor<Cache.Entry<Integer, Person>> cur = clnCache.query(qry);
reconnectClientNode(cln, srv, new Runnable() {
@Override
public void run() {
srvCache.put(4, new Person(4, "name4", "surname4"));
try {
clnCache.query(qry);
fail();
} catch (CacheException e) {
check(e);
}
}
});
List<Cache.Entry<Integer, Person>> res = cur.getAll();
assertNotNull(res);
assertEquals(4, res.size());
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCrossCachesJoinsQueryTest method checkOrganizationPersonsJoin.
/**
* @param cache Cache.
*/
private void checkOrganizationPersonsJoin(IgniteCache cache) {
if (skipQuery(cache, PERSON_CACHE_NAME, ORG_CACHE_NAME))
return;
qry = "checkOrganizationPersonsJoin";
SqlFieldsQuery qry = new SqlFieldsQuery("select o.name, p.name " + "from \"" + ORG_CACHE_NAME + "\".Organization o, \"" + PERSON_CACHE_NAME + "\".Person p " + "where p.orgId = o._key and o._key=?");
qry.setDistributedJoins(distributedJoins());
SqlQuery qry2 = null;
if (PERSON_CACHE_NAME.equals(cache.getName())) {
qry2 = new SqlQuery(Person.class, "from \"" + ORG_CACHE_NAME + "\".Organization, \"" + PERSON_CACHE_NAME + "\".Person " + "where Person.orgId = Organization._key and Organization._key=?");
qry2.setDistributedJoins(distributedJoins());
}
long total = 0;
for (int i = 0; i < data.personsPerOrg.size(); i++) {
qry.setArgs(i);
if (qry2 != null)
qry2.setArgs(i);
List<List<Object>> res = cache.query(qry).getAll();
assertEquals((int) data.personsPerOrg.get(i), res.size());
if (qry2 != null) {
List<List<Object>> res2 = cache.query(qry2).getAll();
assertEquals((int) data.personsPerOrg.get(i), res2.size());
}
total += res.size();
}
SqlFieldsQuery qry3 = new SqlFieldsQuery("select count(*) " + "from \"" + ORG_CACHE_NAME + "\".Organization o, \"" + PERSON_CACHE_NAME + "\".Person p where p.orgId = o._key");
qry3.setDistributedJoins(distributedJoins());
List<List<Object>> res = cache.query(qry3).getAll();
assertEquals(1, res.size());
assertEquals(total, res.get(0).get(0));
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryH2IndexingLeakTest method testLeaksInIgniteH2IndexingOnUnusedThread.
/**
* @throws Exception If failed.
*/
public void testLeaksInIgniteH2IndexingOnUnusedThread() throws Exception {
final IgniteCache<Integer, Integer> c = grid(0).cache(DEFAULT_CACHE_NAME);
final CountDownLatch latch = new CountDownLatch(1);
for (int i = 0; i < ITERATIONS; ++i) {
info("Iteration #" + i);
// Open iterator on the created cursor: add entries to the cache
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
U.await(latch);
}
}, THREAD_COUNT);
Thread.sleep(STMT_CACHE_CLEANUP_TIMEOUT);
// Wait for stmtCache is cleaned up because all user threads don't perform queries a lot of time.
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return getStatementCacheSize(grid(0).context().query()) == 0;
}
}, STMT_CACHE_CLEANUP_TIMEOUT * 2));
latch.countDown();
fut.get();
}
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryIndexSelfTest method checkQuery.
/**
* @param cache Cache.
* @throws Exception If failed.
*/
private void checkQuery(IgniteCache<Integer, CacheValue> cache) throws Exception {
QueryCursor<Cache.Entry<Integer, CacheValue>> qry = cache.query(new SqlQuery(CacheValue.class, "val >= 5"));
Collection<Cache.Entry<Integer, CacheValue>> queried = qry.getAll();
assertEquals("Unexpected query result: " + queried, 5, queried.size());
}
Aggregations