use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class CacheScanPartitionQueryFallbackSelfTest method scanFallbackOnRebalancing.
/**
* @param cur If {@code true} tests query cursor.
* @throws Exception In case of error.
*/
private void scanFallbackOnRebalancing(final boolean cur) throws Exception {
cacheMode = CacheMode.PARTITIONED;
clientMode = false;
backups = 2;
commSpiFactory = new TestFallbackOnRebalancingCommunicationSpiFactory();
syncRebalance = true;
try {
Ignite ignite = startGrids(GRID_CNT);
fillCache(ignite);
final AtomicBoolean done = new AtomicBoolean(false);
final AtomicInteger idx = new AtomicInteger(GRID_CNT);
IgniteInternalFuture fut1 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int id = idx.getAndIncrement();
while (!done.get()) {
startGrid(id);
Thread.sleep(3000);
info("Will stop grid: " + getTestIgniteInstanceName(id));
stopGrid(id);
if (done.get())
return null;
Thread.sleep(3000);
}
return null;
}
}, 2);
final AtomicInteger nodeIdx = new AtomicInteger();
IgniteInternalFuture fut2 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int nodeId = nodeIdx.getAndIncrement();
IgniteCache<Integer, Integer> cache = grid(nodeId).cache(DEFAULT_CACHE_NAME);
int cntr = 0;
while (!done.get()) {
int part = ThreadLocalRandom.current().nextInt(ignite(nodeId).affinity(DEFAULT_CACHE_NAME).partitions());
if (cntr++ % 100 == 0)
info("Running query [node=" + nodeId + ", part=" + part + ']');
try (QueryCursor<Cache.Entry<Integer, Integer>> cur0 = cache.query(new ScanQuery<Integer, Integer>(part))) {
if (cur)
doTestScanQueryCursor(cur0, part);
else
doTestScanQuery(cur0, part);
}
}
return null;
}
}, GRID_CNT);
// Test for one minute
Thread.sleep(60 * 1000);
done.set(true);
fut2.get();
fut1.get();
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class CacheScanPartitionQueryFallbackSelfTest method testScanLocal.
/**
* Scan should perform on the local node.
*
* @throws Exception If failed.
*/
public void testScanLocal() throws Exception {
cacheMode = CacheMode.PARTITIONED;
backups = 0;
commSpiFactory = new TestLocalCommunicationSpiFactory();
try {
Ignite ignite = startGrids(GRID_CNT);
IgniteCacheProxy<Integer, Integer> cache = fillCache(ignite);
int part = anyLocalPartition(cache.context());
QueryCursor<Cache.Entry<Integer, Integer>> qry = cache.query(new ScanQuery<Integer, Integer>().setPartition(part));
doTestScanQuery(qry, part);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteCacheP2pUnmarshallingQueryErrorTest method testResponseMessageOnRequestUnmarshallingFailed.
/**
* @throws Exception If failed.
*/
public void testResponseMessageOnRequestUnmarshallingFailed() throws Exception {
readCnt.set(Integer.MAX_VALUE);
try {
jcache().query(new ScanQuery<>(new IgniteBiPredicate<TestKey, String>() {
@Override
public boolean apply(TestKey key, String val) {
return false;
}
private void readObject(ObjectInputStream is) throws IOException {
throw new IOException();
}
private void writeObject(ObjectOutputStream os) throws IOException {
// No-op.
}
})).getAll();
fail();
} catch (Exception ignored) {
// No-op.
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteCachePartitionedQuerySelfTest method testScanQueryPagination.
/**
* @throws Exception If failed.
*/
public void testScanQueryPagination() throws Exception {
final int pageSize = 5;
final AtomicInteger pages = new AtomicInteger(0);
IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
for (int i = 0; i < 50; i++) cache.put(i, i);
CommunicationSpi spi = ignite().configuration().getCommunicationSpi();
assert spi instanceof TestTcpCommunicationSpi;
TestTcpCommunicationSpi commSpi = (TestTcpCommunicationSpi) spi;
commSpi.filter = new IgniteInClosure<Message>() {
@Override
public void apply(Message msg) {
if (!(msg instanceof GridIoMessage))
return;
Message msg0 = ((GridIoMessage) msg).message();
if (msg0 instanceof GridCacheQueryRequest) {
assertEquals(pageSize, ((GridCacheQueryRequest) msg0).pageSize());
pages.incrementAndGet();
} else if (msg0 instanceof GridCacheQueryResponse)
assertTrue(((GridCacheQueryResponse) msg0).data().size() <= pageSize);
}
};
try {
ScanQuery<Integer, Integer> qry = new ScanQuery<Integer, Integer>();
qry.setPageSize(pageSize);
List<Cache.Entry<Integer, Integer>> all = cache.query(qry).getAll();
assertTrue(pages.get() > ignite().cluster().forDataNodes(DEFAULT_CACHE_NAME).nodes().size());
assertEquals(50, all.size());
} finally {
commSpi.filter = null;
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class CacheAbstractQueryDetailMetricsSelfTest method testQueryMetricsEviction.
/**
* Test metrics eviction.
*
* @throws Exception In case of error.
*/
public void testQueryMetricsEviction() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
// Execute several DIFFERENT queries with guaranteed DIFFERENT time of execution.
cache.query(new SqlFieldsQuery("select * from String")).getAll();
Thread.sleep(100);
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
Thread.sleep(100);
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
Thread.sleep(100);
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
Thread.sleep(100);
cache.query(new ScanQuery()).getAll();
Thread.sleep(100);
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
// Check that collected metrics contains correct items: metrics for last 3 queries.
Collection<? extends QueryDetailMetrics> metrics = cache.queryDetailMetrics();
String lastMetrics = "";
for (QueryDetailMetrics m : metrics) lastMetrics += m.queryType() + " " + m.query() + ";";
assertTrue(lastMetrics.contains("SQL_FIELDS select * from String limit 2;"));
assertTrue(lastMetrics.contains("SCAN A;"));
assertTrue(lastMetrics.contains("SQL from String;"));
cache = grid(0).context().cache().jcache("B");
cache.query(new SqlFieldsQuery("select * from String")).getAll();
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
cache.query(new ScanQuery()).getAll();
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
if (gridCnt > 1) {
cache = grid(1).context().cache().jcache("A");
cache.query(new SqlFieldsQuery("select * from String")).getAll();
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
cache.query(new ScanQuery()).getAll();
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
cache = grid(1).context().cache().jcache("B");
cache.query(new SqlFieldsQuery("select * from String")).getAll();
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
cache.query(new ScanQuery()).getAll();
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
}
}
Aggregations