use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryLoadSelfTest method testReloadAll.
/**
* @throws Exception If failed.
*/
public void testReloadAll() throws Exception {
for (int i = 0; i < PUT_CNT; i++) STORE_MAP.put(i, new ValueObject(i));
IgniteCache<Integer, ValueObject> cache = jcache();
Integer[] keys = new Integer[PUT_CNT - 5];
for (int i = 0; i < PUT_CNT - 5; i++) keys[i] = i + 5;
CompletionListenerFuture fut = new CompletionListenerFuture();
grid().<Integer, Integer>cache(DEFAULT_CACHE_NAME).loadAll(F.asSet(keys), true, fut);
fut.get();
assert cache.size() == PUT_CNT - 5;
Collection<Cache.Entry<Integer, ValueObject>> res = cache.query(new SqlQuery(ValueObject.class, "val >= 0")).getAll();
assert res != null;
assert res.size() == PUT_CNT - 5;
assert size(ValueObject.class) == PUT_CNT - 5;
cache.clear();
assert cache.size() == 0;
assertEquals(0, cache.size());
fut = new CompletionListenerFuture();
grid().<Integer, Integer>cache(DEFAULT_CACHE_NAME).loadAll(F.asSet(keys), true, fut);
fut.get();
assertEquals(PUT_CNT - 5, cache.size());
res = cache.query(new SqlQuery(ValueObject.class, "val >= 0")).getAll();
assert res != null;
assert res.size() == PUT_CNT - 5;
assert size(ValueObject.class) == PUT_CNT - 5;
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryH2IndexingLeakTest method testLeaksInIgniteH2IndexingOnTerminatedThread.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testLeaksInIgniteH2IndexingOnTerminatedThread() throws Exception {
final IgniteCache<Integer, Integer> c = grid(0).cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < ITERATIONS; ++i) {
info("Iteration #" + i);
final AtomicBoolean stop = new AtomicBoolean();
// Open iterator on the created cursor: add entries to the cache.
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
while (!stop.get()) {
c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
c.query(new SqlQuery(Integer.class, "_val >= 1")).getAll();
}
}
}, THREAD_COUNT);
final GridQueryProcessor qryProc = grid(0).context().query();
try {
// Wait for stmt cache entry is created for each thread.
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return getStatementCacheSize(qryProc) == THREAD_COUNT;
}
}, STMT_CACHE_CLEANUP_TIMEOUT));
} finally {
stop.set(true);
}
fut.get();
// Wait for stmtCache is cleaned up because all user threads are terminated.
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return getStatementCacheSize(qryProc) == 0;
}
}, STMT_CACHE_CLEANUP_TIMEOUT * 2));
}
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteDbPutGetAbstractTest method testPutGetLarge.
/**
* @throws Exception if failed.
*/
public void testPutGetLarge() throws Exception {
IgniteEx ig = grid(0);
IgniteCache<Integer, byte[]> cache = ig.cache(DEFAULT_CACHE_NAME);
final byte[] val = new byte[2048];
ThreadLocalRandom.current().nextBytes(val);
cache.put(0, val);
Assert.assertArrayEquals(val, cache.get(0));
final IgniteCache<Integer, LargeDbValue> cache1 = ig.cache("large");
final LargeDbValue large = new LargeDbValue("str1", "str2", randomInts(1024));
cache1.put(1, large);
assertEquals(large, cache1.get(1));
if (indexingEnabled()) {
final List<Cache.Entry<Integer, LargeDbValue>> all = cache1.query(new SqlQuery<Integer, LargeDbValue>(LargeDbValue.class, "str1='str1'")).getAll();
assertEquals(1, all.size());
final Cache.Entry<Integer, LargeDbValue> entry = all.get(0);
assertEquals(1, entry.getKey().intValue());
assertEquals(large, entry.getValue());
}
cache.remove(0);
cache1.remove(1);
assertNull(cache.get(0));
assertNull(cache1.get(1));
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheLocalQuerySelfTest method testQueryLocal.
/**
* @throws Exception If test failed.
*/
public void testQueryLocal() throws Exception {
IgniteCache<Integer, String> cache = jcache(Integer.class, String.class);
cache.put(1, "value1");
cache.put(2, "value2");
cache.put(3, "value3");
cache.put(4, "value4");
cache.put(5, "value5");
// Tests equals query.
QueryCursor<Cache.Entry<Integer, String>> qry = cache.query(new SqlQuery<Integer, String>(String.class, "_val='value1'").setLocal(true));
Iterator<Cache.Entry<Integer, String>> iter = qry.iterator();
Cache.Entry<Integer, String> entry = iter.next();
assert !iter.hasNext();
assert entry != null;
assert entry.getKey() == 1;
assert "value1".equals(entry.getValue());
// Tests like query.
qry = cache.query(new SqlQuery<Integer, String>(String.class, "_val like 'value%'").setLocal(true));
iter = qry.iterator();
assert iter.next() != null;
assert iter.next() != null;
assert iter.next() != null;
assert iter.next() != null;
assert iter.next() != null;
assert !iter.hasNext();
// Test explain for primitive index.
List<List<?>> res = cache.query(new SqlFieldsQuery("explain select _key from String where _val > 'value1'").setLocal(true)).getAll();
assertTrue("__ explain: \n" + res, ((String) res.get(0).get(0)).toLowerCase().contains("_val_idx"));
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteBinaryObjectQueryArgumentsTest method testKeyQuery.
/**
* Test simple query by key.
*
* @param cacheName Cache name.
* @param key1 Key 1.
* @param key2 Key 2.
* @param <T> Key type.
*/
private <T> void testKeyQuery(final String cacheName, final T key1, final T key2) {
final IgniteCache<T, Person> cache = ignite(0).cache(cacheName);
final Person p1 = new Person("p1");
final Person p2 = new Person("p2");
cache.put(key1, p1);
cache.put(key2, p2);
final SqlQuery<T, Person> qry = new SqlQuery<>(Person.class, "where _key=?");
final SqlFieldsQuery fieldsQry = new SqlFieldsQuery("select _key, _val, * from Person where _key=?");
qry.setLocal(isLocal());
fieldsQry.setLocal(isLocal());
qry.setArgs(key1);
fieldsQry.setArgs(key1);
final List<Cache.Entry<T, Person>> res = cache.query(qry).getAll();
final List<List<?>> fieldsRes = cache.query(fieldsQry).getAll();
assertEquals(1, res.size());
assertEquals(1, fieldsRes.size());
assertEquals(p1, res.get(0).getValue());
assertEquals(key1, res.get(0).getKey());
assertTrue(fieldsRes.get(0).size() >= 2);
assertEquals(key1, fieldsRes.get(0).get(0));
assertEquals(p1, fieldsRes.get(0).get(1));
}
Aggregations