Search in sources :

Example 1 with ATTR_IGNITE_INSTANCE_NAME

use of org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME in project ignite by apache.

the class ScanQueriesTopologyMappingTest method checkQueryWithNodeFilter.

/**
 */
private void checkQueryWithNodeFilter(CacheMode cacheMode) throws Exception {
    IgniteEx ign0 = startGrid(0);
    String name0 = ign0.name();
    IgniteCache<Object, Object> cache0 = ign0.createCache(new CacheConfiguration<>(GridAbstractTest.DEFAULT_CACHE_NAME).setCacheMode(cacheMode).setNodeFilter(node -> name0.equals(node.attribute(ATTR_IGNITE_INSTANCE_NAME))));
    cache0.put(1, 2);
    startGrid(1);
    client = true;
    startGrid(10);
    int part = ign0.affinity(DEFAULT_CACHE_NAME).partition(1);
    for (int i = 0; i < 100; i++) {
        for (Ignite ign : G.allGrids()) {
            IgniteCache<Object, Object> cache = ign.cache(GridAbstractTest.DEFAULT_CACHE_NAME);
            List<Cache.Entry<Object, Object>> res = cache.query(new ScanQuery<>()).getAll();
            assertEquals(1, res.size());
            assertEquals(1, res.get(0).getKey());
            assertEquals(2, res.get(0).getValue());
            res = new ArrayList<>();
            for (Cache.Entry<Object, Object> entry : cache) {
                res.add(entry);
            }
            assertEquals(1, res.size());
            assertEquals(1, res.get(0).getKey());
            assertEquals(2, res.get(0).getValue());
            res = cache.query(new ScanQuery<>(part)).getAll();
            assertEquals(1, res.size());
            assertEquals(1, res.get(0).getKey());
            assertEquals(2, res.get(0).getValue());
        }
        ScanQuery<Object, Object> qry = new ScanQuery<>().setLocal(true);
        {
            List<Cache.Entry<Object, Object>> res0 = grid(0).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
            assertEquals(1, res0.size());
            assertEquals(1, res0.get(0).getKey());
            assertEquals(2, res0.get(0).getValue());
        }
        {
            List<Cache.Entry<Object, Object>> res1 = grid(1).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
            assertTrue(res1.isEmpty());
        }
        {
            List<Cache.Entry<Object, Object>> res1 = grid(10).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
            assertTrue(res1.isEmpty());
        }
    }
}
Also used : G(org.apache.ignite.internal.util.typedef.G) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteCache(org.apache.ignite.IgniteCache) ATTR_IGNITE_INSTANCE_NAME(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME) ArrayList(java.util.ArrayList) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Cache(javax.cache.Cache) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CacheMode(org.apache.ignite.cache.CacheMode) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Cache (javax.cache.Cache)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 CacheMode (org.apache.ignite.cache.CacheMode)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 ATTR_IGNITE_INSTANCE_NAME (org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME)1 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)1 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)1 G (org.apache.ignite.internal.util.typedef.G)1 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)1 Message (org.apache.ignite.plugin.extensions.communication.Message)1 GridAbstractTest (org.apache.ignite.testframework.junits.GridAbstractTest)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1