Search in sources :

Example 1 with GridCacheQueryResponse

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse 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;
    }
}
Also used : GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ScanQuery(org.apache.ignite.cache.query.ScanQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryResponse(org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryRequest(org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)1 GridCacheQueryRequest (org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest)1 GridCacheQueryResponse (org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1 CommunicationSpi (org.apache.ignite.spi.communication.CommunicationSpi)1 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)1