Search in sources :

Example 1 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class CacheContinuousQueryConcurrentPartitionUpdateTest method concurrentUpdatesAndQueryStart.

/**
     * @param atomicityMode Cache atomicity mode.
     * @throws Exception If failed.
     */
private void concurrentUpdatesAndQueryStart(CacheAtomicityMode atomicityMode) throws Exception {
    Ignite srv = startGrid(0);
    client = true;
    Ignite client = startGrid(1);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    IgniteCache clientCache = client.createCache(ccfg);
    Affinity<Integer> aff = srv.affinity(DEFAULT_CACHE_NAME);
    final List<Integer> keys = new ArrayList<>();
    final int KEYS = 10;
    for (int i = 0; i < 100_000; i++) {
        if (aff.partition(i) == 0) {
            keys.add(i);
            if (keys.size() == KEYS)
                break;
        }
    }
    assertEquals(KEYS, keys.size());
    final int THREADS = 10;
    final int UPDATES = 1000;
    for (int i = 0; i < 5; i++) {
        log.info("Iteration: " + i);
        ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
        final AtomicInteger evtCnt = new AtomicInteger();
        qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

            @Override
            public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
                for (CacheEntryEvent evt : evts) {
                    assertNotNull(evt.getKey());
                    assertNotNull(evt.getValue());
                    if ((Integer) evt.getValue() >= 0)
                        evtCnt.incrementAndGet();
                }
            }
        });
        QueryCursor cur;
        final IgniteCache<Object, Object> srvCache = srv.cache(DEFAULT_CACHE_NAME);
        final AtomicBoolean stop = new AtomicBoolean();
        try {
            IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
                    while (!stop.get()) srvCache.put(keys.get(rnd.nextInt(KEYS)), rnd.nextInt(100) - 200);
                    return null;
                }
            }, THREADS, "update");
            U.sleep(1000);
            cur = clientCache.query(qry);
            U.sleep(1000);
            stop.set(true);
            fut.get();
        } finally {
            stop.set(true);
        }
        GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                for (int i = 0; i < UPDATES; i++) srvCache.put(keys.get(rnd.nextInt(KEYS)), i);
                return null;
            }
        }, THREADS, "update");
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                log.info("Events: " + evtCnt.get());
                return evtCnt.get() >= THREADS * UPDATES;
            }
        }, 5000);
        assertEquals(THREADS * UPDATES, evtCnt.get());
        cur.close();
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class IgniteRepositoryQuery method execute.

/**
 * {@inheritDoc}
 */
@Override
public Object execute(Object[] prmtrs) {
    Query qry = prepareQuery(prmtrs);
    QueryCursor qryCursor = cache.query(qry);
    return transformQueryCursor(prmtrs, qryCursor);
}
Also used : Query(org.apache.ignite.cache.query.Query) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlQuery(org.apache.ignite.cache.query.SqlQuery) RepositoryQuery(org.springframework.data.repository.query.RepositoryQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Example 3 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class JmxExporterSpiTest method testContinuousQuery.

/**
 */
@Test
public void testContinuousQuery() throws Exception {
    try (IgniteEx remoteNode = startGrid(1)) {
        IgniteCache<Integer, Integer> cache = ignite.createCache("cache-1");
        assertEquals(0, systemView(CQ_SYS_VIEW).size());
        assertEquals(0, systemView(remoteNode, CQ_SYS_VIEW).size());
        try (QueryCursor qry = cache.query(new ContinuousQuery<>().setInitialQuery(new ScanQuery<>()).setPageSize(100).setTimeInterval(1000).setLocalListener(evts -> {
        // No-op.
        }).setRemoteFilterFactory(() -> evt -> true))) {
            for (int i = 0; i < 100; i++) cache.put(i, i);
            checkContinuousQueryView(ignite, ignite);
            checkContinuousQueryView(ignite, remoteNode);
        }
        assertEquals(0, systemView(CQ_SYS_VIEW).size());
        assertTrue(waitForCondition(() -> systemView(remoteNode, CQ_SYS_VIEW).isEmpty(), getTestTimeout()));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) TestObjectEnum(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum) Map(java.util.Map) FILTER_OPERATION(org.apache.ignite.internal.managers.systemview.SystemViewMBean.FILTER_OPERATION) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) CACHE_METRICS(org.apache.ignite.internal.processors.cache.CacheMetricsImpl.CACHE_METRICS) GC_CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD_DESCRIPTION) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) MBeanOperationInfo(javax.management.MBeanOperationInfo) Set(java.util.Set) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TEST_TRANSFORMER(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER) MBeanFeatureInfo(javax.management.MBeanFeatureInfo) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) DynamicMBean(javax.management.DynamicMBean) VIEWS(org.apache.ignite.internal.managers.systemview.SystemViewMBean.VIEWS) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD_DESCRIPTION) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) BINARY_METADATA_VIEW(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW) DISTRIBUTED_METASTORE_VIEW(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW) IgniteClient(org.apache.ignite.client.IgniteClient) TEST_PREDICATE(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE) TestTransformer(org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer) STREAM_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.STREAM_POOL_QUEUE_VIEW) TASKS_VIEW(org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW) Properties(java.util.Properties) CompositeData(javax.management.openmbean.CompositeData) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Field(java.lang.reflect.Field) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) SCAN_QRY_SYS_VIEW(org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW) CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CachePagesListViewWalker(org.apache.ignite.internal.managers.systemview.walker.CachePagesListViewWalker) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) Connection(java.sql.Connection) ProtocolVersion(org.apache.ignite.internal.client.thin.ProtocolVersion) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) Transaction(org.apache.ignite.transactions.Transaction) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CACHE_GRP_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW) IgniteEx(org.apache.ignite.internal.IgniteEx) METASTORE_VIEW(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalTime(java.time.LocalTime) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) DateFormat(java.text.DateFormat) Collectors.toSet(java.util.stream.Collectors.toSet) CyclicBarrier(java.util.concurrent.CyclicBarrier) SVCS_VIEW(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.SVCS_VIEW) CLI_CONN_VIEW(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) IGNITE_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.IGNITE_METRICS) MetricRegistryMBean.searchHistogram(org.apache.ignite.spi.metric.jmx.MetricRegistryMBean.searchHistogram) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Optional(java.util.Optional) ACTIVE(org.apache.ignite.transactions.TransactionState.ACTIVE) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) SYS_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.SYS_METRICS) DummyService(org.apache.ignite.internal.processors.service.DummyService) Arrays.stream(java.util.Arrays.stream) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) MBeanParameterInfo(javax.management.MBeanParameterInfo) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) CACHES_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) SYS_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.SYS_POOL_QUEUE_VIEW) TestRunnable(org.apache.ignite.internal.metric.SystemViewSelfTest.TestRunnable) GC_CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) TestPredicate(org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate) F(org.apache.ignite.internal.util.typedef.F) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) JdbcConnectionContext(org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext) CACHE_GRPS_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW) TestObjectAllTypes(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes) Consumer(java.util.function.Consumer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Ignition(org.apache.ignite.Ignition) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) ScanQuery(org.apache.ignite.cache.query.ScanQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Test(org.junit.Test)

Example 4 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class SystemViewSelfTest method testContinuousQuery.

/**
 */
@Test
public void testContinuousQuery() throws Exception {
    try (IgniteEx originNode = startGrid(0);
        IgniteEx remoteNode = startGrid(1)) {
        IgniteCache<Integer, Integer> cache = originNode.createCache("cache-1");
        SystemView<ContinuousQueryView> origQrys = originNode.context().systemView().view(CQ_SYS_VIEW);
        SystemView<ContinuousQueryView> remoteQrys = remoteNode.context().systemView().view(CQ_SYS_VIEW);
        assertEquals(0, origQrys.size());
        assertEquals(0, remoteQrys.size());
        try (QueryCursor qry = cache.query(new ContinuousQuery<>().setInitialQuery(new ScanQuery<>()).setPageSize(100).setTimeInterval(1000).setLocalListener(evts -> {
        // No-op.
        }).setRemoteFilterFactory(() -> evt -> true))) {
            for (int i = 0; i < 100; i++) cache.put(i, i);
            checkContinuousQueryView(originNode, origQrys, true);
            checkContinuousQueryView(originNode, remoteQrys, false);
        }
        assertEquals(0, origQrys.size());
        assertTrue(waitForCondition(() -> remoteQrys.size() == 0, getTestTimeout()));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) StripedExecutorTaskView(org.apache.ignite.spi.systemview.view.StripedExecutorTaskView) CountDownLatchView(org.apache.ignite.spi.systemview.view.datastructures.CountDownLatchView) QueueView(org.apache.ignite.spi.systemview.view.datastructures.QueueView) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) TestObjectEnum(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum) ComputeTaskView(org.apache.ignite.spi.systemview.view.ComputeTaskView) Map(java.util.Map) CachePagesListView(org.apache.ignite.spi.systemview.view.CachePagesListView) Cache(javax.cache.Cache) ComputeTask(org.apache.ignite.compute.ComputeTask) SEQUENCES_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.SEQUENCES_VIEW) NodeAttributeView(org.apache.ignite.spi.systemview.view.NodeAttributeView) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) BaselineNodeView(org.apache.ignite.spi.systemview.view.BaselineNodeView) DEFAULT_DS_GROUP_NAME(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DEFAULT_DS_GROUP_NAME) BaselineNodeAttributeViewWalker(org.apache.ignite.internal.managers.systemview.walker.BaselineNodeAttributeViewWalker) SystemView(org.apache.ignite.spi.systemview.view.SystemView) TransactionView(org.apache.ignite.spi.systemview.view.TransactionView) AtomicStampedView(org.apache.ignite.spi.systemview.view.datastructures.AtomicStampedView) IgniteSet(org.apache.ignite.IgniteSet) Set(java.util.Set) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) BASELINE_NODES_SYS_VIEW(org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor.BASELINE_NODES_SYS_VIEW) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) BaselineNodeAttributeView(org.apache.ignite.spi.systemview.view.BaselineNodeAttributeView) LONGS_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.LONGS_VIEW) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PagesListView(org.apache.ignite.spi.systemview.view.PagesListView) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) ClientConnectionView(org.apache.ignite.spi.systemview.view.ClientConnectionView) DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE(org.apache.ignite.configuration.AtomicConfiguration.DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteCompute(org.apache.ignite.IgniteCompute) SETS_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.SETS_VIEW) GridFunc.alwaysTrue(org.apache.ignite.internal.util.lang.GridFunc.alwaysTrue) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ComputeJob(org.apache.ignite.compute.ComputeJob) DEFAULT_VOLATILE_DS_GROUP_NAME(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DEFAULT_VOLATILE_DS_GROUP_NAME) ClusterState(org.apache.ignite.cluster.ClusterState) REFERENCES_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.REFERENCES_VIEW) U(org.apache.ignite.internal.util.typedef.internal.U) NODE_METRICS_SYS_VIEW(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.NODE_METRICS_SYS_VIEW) BINARY_METADATA_VIEW(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW) CACHE_GRP_IO_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_IO_VIEW) DISTRIBUTED_METASTORE_VIEW(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) Lists(com.google.common.collect.Lists) ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteAtomicReference(org.apache.ignite.IgniteAtomicReference) METASTORAGE_CACHE_NAME(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME) IgniteAtomicStamped(org.apache.ignite.IgniteAtomicStamped) STREAM_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.STREAM_POOL_QUEUE_VIEW) TASKS_VIEW(org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW) Properties(java.util.Properties) QUEUES_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.QUEUES_VIEW) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CacheGroupIoView(org.apache.ignite.spi.systemview.view.CacheGroupIoView) Test(org.junit.Test) IgniteQueue(org.apache.ignite.IgniteQueue) AtomicSequenceView(org.apache.ignite.spi.systemview.view.datastructures.AtomicSequenceView) Field(java.lang.reflect.Field) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) SCAN_QRY_SYS_VIEW(org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW) NodeMetricsView(org.apache.ignite.spi.systemview.view.NodeMetricsView) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SNAPSHOT_SYS_VIEW(org.apache.ignite.spi.systemview.view.SnapshotView.SNAPSHOT_SYS_VIEW) CachePagesListViewWalker(org.apache.ignite.internal.managers.systemview.walker.CachePagesListViewWalker) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) NODE_ATTRIBUTES_SYS_VIEW(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.NODE_ATTRIBUTES_SYS_VIEW) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) DATA_REGION_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager.DATA_REGION_PAGE_LIST_VIEW) Connection(java.sql.Connection) ProtocolVersion(org.apache.ignite.internal.client.thin.ProtocolVersion) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) Transaction(org.apache.ignite.transactions.Transaction) FiltrableSystemView(org.apache.ignite.spi.systemview.view.FiltrableSystemView) CACHE_GRP_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW) IgniteEx(org.apache.ignite.internal.IgniteEx) METASTORE_VIEW(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) BinaryMetadataView(org.apache.ignite.spi.systemview.view.BinaryMetadataView) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) ClusterNodeView(org.apache.ignite.spi.systemview.view.ClusterNodeView) LOCKS_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.LOCKS_VIEW) NODES_SYS_VIEW(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.NODES_SYS_VIEW) AtomicReferenceView(org.apache.ignite.spi.systemview.view.datastructures.AtomicReferenceView) IgniteLock(org.apache.ignite.IgniteLock) CyclicBarrier(java.util.concurrent.CyclicBarrier) SVCS_VIEW(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.SVCS_VIEW) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) ServiceView(org.apache.ignite.spi.systemview.view.ServiceView) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) CLI_CONN_VIEW(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) LATCHES_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.LATCHES_VIEW) VOLATILE_DATA_REGION_NAME(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.VOLATILE_DATA_REGION_NAME) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) ACTIVE(org.apache.ignite.transactions.TransactionState.ACTIVE) NodeAttributeViewWalker(org.apache.ignite.internal.managers.systemview.walker.NodeAttributeViewWalker) NotNull(org.jetbrains.annotations.NotNull) DummyService(org.apache.ignite.internal.processors.service.DummyService) ContinuousQueryView(org.apache.ignite.spi.systemview.view.ContinuousQueryView) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) CacheView(org.apache.ignite.spi.systemview.view.CacheView) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) SetView(org.apache.ignite.spi.systemview.view.datastructures.SetView) CACHES_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW) AtomicLongView(org.apache.ignite.spi.systemview.view.datastructures.AtomicLongView) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) SEMAPHORES_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.SEMAPHORES_VIEW) SYS_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.SYS_POOL_QUEUE_VIEW) SnapshotView(org.apache.ignite.spi.systemview.view.SnapshotView) ReentrantLockView(org.apache.ignite.spi.systemview.view.datastructures.ReentrantLockView) GridFunc.identity(org.apache.ignite.internal.util.lang.GridFunc.identity) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ScanQueryView(org.apache.ignite.spi.systemview.view.ScanQueryView) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) MetastorageView(org.apache.ignite.spi.systemview.view.MetastorageView) STAMPED_VIEW(org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.STAMPED_VIEW) F(org.apache.ignite.internal.util.typedef.F) Iterator(java.util.Iterator) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) JdbcConnectionContext(org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) CACHE_GRPS_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW) CacheGroupView(org.apache.ignite.spi.systemview.view.CacheGroupView) TestObjectAllTypes(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Ignition(org.apache.ignite.Ignition) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) BASELINE_NODE_ATTRIBUTES_SYS_VIEW(org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor.BASELINE_NODE_ATTRIBUTES_SYS_VIEW) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) SemaphoreView(org.apache.ignite.spi.systemview.view.datastructures.SemaphoreView) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) ContinuousQueryView(org.apache.ignite.spi.systemview.view.ContinuousQueryView) ScanQuery(org.apache.ignite.cache.query.ScanQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 5 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class IgniteCacheConfigVariationsFullApiTest method testContinuousQuery.

/**
 * @throws Exception If failed.
 */
@Test
public void testContinuousQuery() throws Exception {
    runInAllDataModes(new TestRunnable() {

        @Override
        public void run() throws Exception {
            final AtomicInteger updCnt = new AtomicInteger();
            ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
            qry.setInitialQuery(new ScanQuery<>(new IgniteBiPredicate<Object, Object>() {

                @Override
                public boolean apply(Object key, Object val) {
                    return valueOf(key) >= 3;
                }
            }));
            qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

                @Override
                public void onUpdated(Iterable<CacheEntryEvent<? extends Object, ? extends Object>> evts) throws CacheEntryListenerException {
                    for (CacheEntryEvent<? extends Object, ? extends Object> evt : evts) {
                        int v = valueOf(evt.getKey());
                        // Check filter.
                        assertTrue("v=" + v, v >= 10 && v < 15);
                        updCnt.incrementAndGet();
                    }
                }
            });
            qry.setRemoteFilter(new TestCacheEntryEventSerializableFilter());
            IgniteCache<Object, Object> cache = jcache();
            for (int i = 0; i < 10; i++) cache.put(key(i), value(i));
            try (QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(qry)) {
                int cnt = 0;
                for (Cache.Entry<Object, Object> e : cur) {
                    cnt++;
                    int val = valueOf(e.getKey());
                    assertTrue("v=" + val, val >= 3);
                }
                assertEquals(7, cnt);
                for (int i = 10; i < 20; i++) cache.put(key(i), value(i));
                GridTestUtils.waitForCondition(new GridAbsPredicateX() {

                    @Override
                    public boolean applyx() throws IgniteCheckedException {
                        return updCnt.get() == 5;
                    }
                }, 30_000);
            }
        }
    });
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) MutableEntry(javax.cache.processor.MutableEntry) CacheEntry(org.apache.ignite.cache.CacheEntry) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) GridAbsPredicateX(org.apache.ignite.internal.util.lang.GridAbsPredicateX) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest) Test(org.junit.Test)

Aggregations

QueryCursor (org.apache.ignite.cache.query.QueryCursor)72 IgniteCache (org.apache.ignite.IgniteCache)44 Ignite (org.apache.ignite.Ignite)38 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)36 Cache (javax.cache.Cache)33 Test (org.junit.Test)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)28 ScanQuery (org.apache.ignite.cache.query.ScanQuery)26 ArrayList (java.util.ArrayList)24 IgniteException (org.apache.ignite.IgniteException)22 List (java.util.List)19 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)19 Map (java.util.Map)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)17 CacheException (javax.cache.CacheException)16 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)16 Collection (java.util.Collection)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 Transaction (org.apache.ignite.transactions.Transaction)15