Search in sources :

Example 91 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteSqlQueryMinMaxTest method testGroupHavingMinMax.

/**
 * Check min() and max() over group with having clause
 */
public void testGroupHavingMinMax() throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Integer, ValueObj> cache = client.cache(CACHE_NAME_2);
        int count = 1_000;
        int groupSize = 100;
        for (int idx = 0; idx < count; ++idx) cache.put(idx, new ValueObj(count - idx - 1, groupSize));
        QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select groupVal, min(idxVal), max(idxVal), min(nonIdxVal), max(nonIdxVal) " + "from ValueObj group by groupVal having min(idxVal) = ?").setArgs(0));
        List<List<?>> result = cursor.getAll();
        assertEquals(1, result.size());
        // groupVal
        assertEquals(0, result.get(0).get(0));
        // min(idxVal)
        assertEquals(0, result.get(0).get(1));
        // max(idxVal)
        assertEquals(groupSize - 1, result.get(0).get(2));
        // min(nonIdxVal)
        assertEquals(0, result.get(0).get(3));
        // max(nonIdxVal)
        assertEquals(groupSize - 1, result.get(0).get(4));
        cursor = cache.query(new SqlFieldsQuery("select groupVal, min(idxVal), max(idxVal), min(nonIdxVal), max(nonIdxVal) " + "from ValueObj group by groupVal having max(idxVal) = ?").setArgs(count - 1));
        result = cursor.getAll();
        assertEquals(1, result.size());
        // groupVal
        assertEquals((count - 1) / groupSize, result.get(0).get(0));
        // min(idxVal)
        assertEquals(count - groupSize, result.get(0).get(1));
        // max(idxVal)
        assertEquals(count - 1, result.get(0).get(2));
        // min(nonIdxVal)
        assertEquals(count - groupSize, result.get(0).get(3));
        // max(nonIdxVal)
        assertEquals(count - 1, result.get(0).get(4));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 92 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteSqlQueryMinMaxTest method testQueryMinMaxEmptyCache.

/**
 * Check min() and max() on empty cache
 */
public void testQueryMinMaxEmptyCache() throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Integer, ValueObj> cache = client.cache(CACHE_NAME_2);
        QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select min(idxVal), max(idxVal) from ValueObj"));
        List<List<?>> result = cursor.getAll();
        assertEquals(1, result.size());
        assertEquals(2, result.get(0).size());
        assertNull(result.get(0).get(0));
        assertNull(result.get(0).get(1));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 93 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class GridMessagingSelfTest method testRemoteListenWithIntTopic.

/**
 * Tests simple message sending-receiving with the use of
 * remoteListen() method and topics.
 *
 * @throws Exception If error occurs.
 */
public void testRemoteListenWithIntTopic() throws Exception {
    final Collection<Object> rcvMsgs = new GridConcurrentHashSet<>();
    // to make it modifiable
    final AtomicBoolean error = new AtomicBoolean(false);
    rcvLatch = new CountDownLatch(3);
    ignite2.message().remoteListen(I_TOPIC_1, new P2<UUID, Object>() {

        @IgniteInstanceResource
        private transient Ignite g;

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            assertEquals(ignite2, g);
            try {
                log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + I_TOPIC_1 + ']');
                if (!nodeId.equals(ignite1.cluster().localNode().id())) {
                    log.error("Unexpected sender node: " + nodeId);
                    error.set(true);
                    return false;
                }
                if (!MSG_1.equals(msg)) {
                    log.error("Unexpected message " + msg + " for topic: " + I_TOPIC_1);
                    error.set(true);
                    return false;
                }
                rcvMsgs.add(msg);
                return true;
            } finally {
                rcvLatch.countDown();
            }
        }
    });
    ignite2.message().remoteListen(I_TOPIC_2, new P2<UUID, Object>() {

        @IgniteInstanceResource
        private transient Ignite g;

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            assertEquals(ignite2, g);
            try {
                log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=" + I_TOPIC_2 + ']');
                if (!nodeId.equals(ignite1.cluster().localNode().id())) {
                    log.error("Unexpected sender node: " + nodeId);
                    error.set(true);
                    return false;
                }
                if (!MSG_2.equals(msg)) {
                    log.error("Unexpected message " + msg + " for topic: " + I_TOPIC_2);
                    error.set(true);
                    return false;
                }
                rcvMsgs.add(msg);
                return true;
            } finally {
                rcvLatch.countDown();
            }
        }
    });
    ignite2.message().remoteListen(null, new P2<UUID, Object>() {

        @IgniteInstanceResource
        private transient Ignite g;

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            assertEquals(ignite2, g);
            try {
                log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ", topic=default]");
                if (!nodeId.equals(ignite1.cluster().localNode().id())) {
                    log.error("Unexpected sender node: " + nodeId);
                    error.set(true);
                    return false;
                }
                if (!MSG_3.equals(msg)) {
                    log.error("Unexpected message " + msg + " for topic: default");
                    error.set(true);
                    return false;
                }
                rcvMsgs.add(msg);
                return true;
            } finally {
                rcvLatch.countDown();
            }
        }
    });
    // Includes node from grid2.
    ClusterGroup prj2 = ignite1.cluster().forRemotes();
    message(prj2).send(I_TOPIC_1, MSG_1);
    message(prj2).send(I_TOPIC_2, MSG_2);
    message(prj2).send(null, MSG_3);
    assertTrue(rcvLatch.await(3, TimeUnit.SECONDS));
    assertFalse(error.get());
    assertTrue(rcvMsgs.contains(MSG_1));
    assertTrue(rcvMsgs.contains(MSG_2));
    assertTrue(rcvMsgs.contains(MSG_3));
}
Also used : GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Example 94 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteCacheQueriesLoadTest1 method runQueries.

/**
 * @param threads Threads number.
 * @param checkBalance Check balance flag.
 * @param time Execution time.
 * @throws Exception If failed.
 */
private void runQueries(int threads, final boolean checkBalance, final long time) throws Exception {
    final Ignite ignite = grid(0);
    GridTestUtils.runMultiThreaded(new Callable<Object>() {

        @Override
        public Object call() {
            long endTime = System.currentTimeMillis() + time;
            while (System.currentTimeMillis() < endTime) {
                ScanQueryBroadcastClosure c = new ScanQueryBroadcastClosure(partitionsMap, checkBalance);
                ignite.compute().broadcast(c);
            }
            return null;
        }
    }, threads, "test-thread");
}
Also used : Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 95 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class IgniteCacheCrossCacheJoinRandomTest method checkJoinQueries.

/**
 * @param ccfgs Configurations.
 * @param cachesData Caches data.
 * @throws Exception If failed.
 */
private void checkJoinQueries(List<CacheConfiguration> ccfgs, List<Map<Integer, Integer>> cachesData) throws Exception {
    Ignite client = ignite(SRVS);
    final int CACHES = ccfgs.size();
    try {
        IgniteCache cache = null;
        boolean hasReplicated = false;
        for (int i = 0; i < CACHES; i++) {
            CacheConfiguration ccfg = ccfgs.get(i);
            IgniteCache cache0 = client.createCache(ccfg);
            if (ccfg.getCacheMode() == REPLICATED)
                hasReplicated = true;
            if (cache == null && ccfg.getCacheMode() == PARTITIONED)
                cache = cache0;
            insertCache(cachesData.get(i), cache0);
        }
        boolean distributedJoin = true;
        // Do not use distributed join if all caches are REPLICATED.
        if (cache == null) {
            cache = client.cache(ccfgs.get(0).getName());
            distributedJoin = false;
        }
        Object[] args = {};
        compareQueryRes0(cache, createQuery(CACHES, false, null), distributedJoin, false, args, Ordering.RANDOM);
        if (!hasReplicated) {
            compareQueryRes0(cache, createQuery(CACHES, false, null), distributedJoin, true, args, Ordering.RANDOM);
            compareQueryRes0(cache, createQuery(CACHES, true, null), distributedJoin, true, args, Ordering.RANDOM);
        }
        Map<Integer, Integer> data = cachesData.get(CACHES - 1);
        final int QRY_CNT = CACHES > 4 ? 2 : 50;
        int cnt = 0;
        for (Integer objId : data.keySet()) {
            compareQueryRes0(cache, createQuery(CACHES, false, objId), distributedJoin, false, args, Ordering.RANDOM);
            if (!hasReplicated) {
                compareQueryRes0(cache, createQuery(CACHES, false, objId), distributedJoin, true, args, Ordering.RANDOM);
                compareQueryRes0(cache, createQuery(CACHES, true, objId), distributedJoin, true, args, Ordering.RANDOM);
            }
            if (cnt++ == QRY_CNT)
                break;
        }
    } finally {
        for (CacheConfiguration ccfg : ccfgs) client.destroyCache(ccfg.getName());
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

Ignite (org.apache.ignite.Ignite)2007 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)358 CountDownLatch (java.util.concurrent.CountDownLatch)238 IgniteCache (org.apache.ignite.IgniteCache)234 IgniteException (org.apache.ignite.IgniteException)216 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)215 Transaction (org.apache.ignite.transactions.Transaction)194 ArrayList (java.util.ArrayList)177 ClusterNode (org.apache.ignite.cluster.ClusterNode)152 UUID (java.util.UUID)137 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)135 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)128 CacheException (javax.cache.CacheException)112 Event (org.apache.ignite.events.Event)112 HashMap (java.util.HashMap)105 List (java.util.List)89 IgniteEx (org.apache.ignite.internal.IgniteEx)85 Map (java.util.Map)84 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)81 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)78