use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest 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;
}
}
Aggregations