Search in sources :

Example 1 with ScanQuery

use of org.apache.ignite.cache.query.ScanQuery in project camel by apache.

the class IgniteCacheContinuousQueryTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry answer = super.createRegistry();
    ScanQuery<Integer, Person> scanQuery1 = new ScanQuery<>(new IgniteBiPredicate<Integer, Person>() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean apply(Integer key, Person person) {
            return person.getId() > 50;
        }
    });
    CacheEntryEventSerializableFilter<Integer, Person> remoteFilter = new CacheEntryEventSerializableFilter<Integer, IgniteCacheContinuousQueryTest.Person>() {

        private static final long serialVersionUID = 5624973479995548199L;

        @Override
        public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Person> event) throws CacheEntryListenerException {
            return event.getValue().getId() > 150;
        }
    };
    answer.bind("query1", scanQuery1);
    answer.bind("remoteFilter1", remoteFilter);
    return answer;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Example 2 with ScanQuery

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

the class IgniteCacheNodeJoinAbstractTest method testScanQuery.

/**
     * @throws Exception If failed.
     */
public void testScanQuery() throws Exception {
    final IgniteCache<Integer, Integer> cache = jcache(0);
    for (int i = 0; i < 5; i++) {
        log.info("Iteration: " + i);
        final IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                startGrid(1);
                return null;
            }
        });
        final AtomicBoolean stop = new AtomicBoolean();
        GridTestUtils.runMultiThreaded(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                ScanQuery qry = new ScanQuery();
                while (!stop.get() && !fut.isDone()) cache.query(qry).getAll();
                return null;
            }
        }, 10, "test-qry");
        try {
            fut.get(60_000);
        } finally {
            stop.set(true);
        }
        stopGrid(1);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 3 with ScanQuery

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

the class IgniteCacheBinaryObjectsScanSelfTest method testScanNoClasses.

/**
     * @throws Exception If failed.
     */
public void testScanNoClasses() throws Exception {
    Ignite client = grid("client");
    IgniteCache<Object, Object> cache = client.cache("testCache");
    List<Cache.Entry<Object, Object>> entries = cache.query(new ScanQuery<>()).getAll();
    assertEquals(100, entries.size());
    for (Cache.Entry<Object, Object> entry : entries) {
        assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName());
        assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName());
    }
    entries = new ArrayList<>();
    int partCnt = client.affinity("testCache").partitions();
    for (int i = 0; i < partCnt; i++) entries.addAll(cache.query(new ScanQuery<>(i)).getAll());
    assertEquals(100, entries.size());
    for (Cache.Entry<Object, Object> entry : entries) {
        assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName());
        assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName());
    }
}
Also used : ScanQuery(org.apache.ignite.cache.query.ScanQuery) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Example 4 with ScanQuery

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

the class IgniteCacheConfigVariationsFullApiTest method testContinuousQuery.

/**
     * @throws Exception If failed.
     */
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)

Example 5 with ScanQuery

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

the class GridCacheQueryTransformerSelfTest method testLocalFiltered.

/**
     * @throws Exception If failed.
     */
public void testLocalFiltered() throws Exception {
    IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
    try {
        for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
        Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public List<Integer> call() throws Exception {
                IgniteBiPredicate<Integer, Value> filter = new IgniteBiPredicate<Integer, Value>() {

                    @Override
                    public boolean apply(Integer k, Value v) {
                        return v.idx % 1000 == 0;
                    }
                };
                IgniteClosure<Cache.Entry<Integer, Value>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, Value>, Integer>() {

                    @Override
                    public Integer apply(Cache.Entry<Integer, Value> e) {
                        return e.getValue().idx;
                    }
                };
                return ignite.cache("test-cache").query(new ScanQuery<>(filter).setLocal(true), transformer).getAll();
            }
        });
        List<Integer> res = new ArrayList<>(F.flatCollections(lists));
        assertEquals(5, res.size());
        Collections.sort(res);
        for (int i = 0; i < 5; i++) assertEquals(i * 1000, res.get(i).intValue());
    } finally {
        cache.destroy();
    }
}
Also used : IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ArrayList(java.util.ArrayList) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) ArrayList(java.util.ArrayList) List(java.util.List) Ignite(org.apache.ignite.Ignite) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Aggregations

ScanQuery (org.apache.ignite.cache.query.ScanQuery)29 Ignite (org.apache.ignite.Ignite)17 Cache (javax.cache.Cache)16 IgniteCache (org.apache.ignite.IgniteCache)16 CacheException (javax.cache.CacheException)7 List (java.util.List)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 ArrayList (java.util.ArrayList)4 IgniteException (org.apache.ignite.IgniteException)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Map (java.util.Map)3 BinaryOperator (java.util.function.BinaryOperator)3 EntryProcessorException (javax.cache.processor.EntryProcessorException)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 Ignition (org.apache.ignite.Ignition)3 Affinity (org.apache.ignite.cache.affinity.Affinity)3