use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheBinaryKeyConcurrentQueryTest method startUpdate.
/**
* @param cacheName Cache name.
* @return Future.
*/
private IgniteInternalFuture<?> startUpdate(final String cacheName) {
final long stopTime = System.currentTimeMillis() + 30_000;
final AtomicInteger idx = new AtomicInteger();
return GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Void call() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
IgniteCache cache = ignite(idx.getAndIncrement() % NODES).cache(cacheName).withKeepBinary();
while (System.currentTimeMillis() < stopTime) {
switch(rnd.nextInt(5)) {
case 0:
{
TestKey key = new TestKey(rnd.nextInt(KEYS));
CacheEntry e = cache.getEntry(key);
assertNotNull(e);
assertTrue(e.getKey() instanceof BinaryObject);
cache.put(e.getKey(), new TestValue(rnd.nextInt(KEYS)));
break;
}
case 1:
{
Iterator<Cache.Entry> it = cache.iterator();
for (int i = 0; i < 100 && it.hasNext(); i++) {
Cache.Entry e = it.next();
assertTrue(e.getKey() instanceof BinaryObject);
cache.put(e.getKey(), new TestValue(rnd.nextInt(KEYS)));
}
break;
}
case 2:
{
SqlFieldsQuery qry = new SqlFieldsQuery("select _key " + "from \"" + cache.getName() + "\".TestValue where id=?");
qry.setArgs(rnd.nextInt(KEYS));
List<List> res = cache.query(qry).getAll();
assertEquals(1, res.size());
BinaryObject key = (BinaryObject) res.get(0).get(0);
cache.put(key, new TestValue(rnd.nextInt(KEYS)));
break;
}
case 3:
{
SqlQuery qry = new SqlQuery("TestValue", "id=?");
qry.setArgs(rnd.nextInt(KEYS));
List<Cache.Entry> res = cache.query(qry).getAll();
assertEquals(1, res.size());
break;
}
case 4:
{
SqlQuery qry = new SqlQuery("TestValue", "order by id");
int cnt = 0;
for (Cache.Entry e : (Iterable<Cache.Entry>) cache.query(qry)) {
assertNotNull(cache.get(e.getKey()));
cnt++;
}
assertTrue(cnt > 0);
break;
}
default:
fail();
}
}
return null;
}
}, NODES * 2, "test-thread");
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheOffheapBatchIndexingSingleTypeTest method testBatchRemove.
/**
* Tests removal using EntryProcessor.
*
* @throws Exception If failed.
*/
public void testBatchRemove() throws Exception {
Ignite ignite = grid(0);
CacheConfiguration<Object, Object> ccfg = cacheConfiguration(new Class<?>[] { Integer.class, CacheOffheapBatchIndexingBaseTest.Organization.class });
final IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
try {
int iterations = 50;
while (iterations-- >= 0) {
int total = 1000;
for (int id = 0; id < total; id++) cache.put(id, new CacheOffheapBatchIndexingBaseTest.Organization(id, "Organization " + id));
cache.invoke(0, new CacheEntryProcessor<Object, Object, Object>() {
@Override
public Object process(MutableEntry<Object, Object> entry, Object... args) {
entry.remove();
return null;
}
});
QueryCursor<List<?>> q = cache.query(new SqlFieldsQuery("select _key,_val from Organization where id=0"));
assertEquals(0, q.getAll().size());
q = cache.query(new SqlFieldsQuery("select _key,_val from Organization where id=1"));
assertEquals(1, q.getAll().size());
assertEquals(total - 1, cache.size());
cache.removeAll();
}
} finally {
cache.destroy();
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheAbstractQueryMetricsSelfTest method testSqlFieldsCrossCacheQueryMetrics.
/**
* Test metrics for SQL cross cache queries.
*
* @throws Exception In case of error.
*/
public void testSqlFieldsCrossCacheQueryMetrics() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
SqlFieldsQuery qry = new SqlFieldsQuery("select * from \"B\".String");
checkQueryMetrics(cache, qry);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheAbstractQueryDetailMetricsSelfTest method testSqlFieldsQueryMetrics.
/**
* Test metrics for SQL fields queries.
*
* @throws Exception In case of error.
*/
public void testSqlFieldsQueryMetrics() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
checkQueryMetrics(cache, qry);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheAbstractQueryDetailMetricsSelfTest method testQueryMetricsMultithreaded.
/**
* Test metrics if queries executed from several threads.
*
* @throws Exception In case of error.
*/
public void testQueryMetricsMultithreaded() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
Collection<Worker> workers = new ArrayList<>();
int repeat = 10;
for (int k = 0; k < repeat; k++) {
// Execute as match queries as history size to avoid eviction.
for (int i = 1; i <= QRY_DETAIL_METRICS_SIZE; i++) workers.add(new Worker(cache, new SqlFieldsQuery("select * from String limit " + i)));
}
for (Worker worker : workers) worker.start();
for (Worker worker : workers) worker.join();
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, repeat, repeat, 0, false);
}
Aggregations