Search in sources :

Example 51 with Ignite

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

the class IgniteCacheDistributedQueryCancelSelfTest method testQueryResponseFailCode.

/**
 */
public void testQueryResponseFailCode() throws Exception {
    try (Ignite client = startGrid("client")) {
        CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
        cfg.setSqlFunctionClasses(Functions.class);
        cfg.setIndexedTypes(Integer.class, Integer.class);
        cfg.setName("test");
        IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);
        cache.put(1, 1);
        QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery("select fail() from Integer"));
        try {
            qry.getAll();
            fail();
        } catch (Exception e) {
            assertTrue(e.getCause() instanceof CacheException);
        }
    }
}
Also used : CacheException(javax.cache.CacheException) Ignite(org.apache.ignite.Ignite) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException)

Example 52 with Ignite

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

the class IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest method testQueryCancel.

/**
 */
private void testQueryCancel(int keyCnt, int valSize, String sql, int timeoutUnits, TimeUnit timeUnit, boolean timeout) throws Exception {
    try (Ignite client = startGrid("client")) {
        IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
        assertEquals(0, cache.localSize());
        int p = 1;
        for (int i = 1; i <= keyCnt; i++) {
            char[] tmp = new char[valSize];
            Arrays.fill(tmp, ' ');
            cache.put(i, new String(tmp));
            if (i / (float) keyCnt >= p / 10f) {
                log().info("Loaded " + i + " of " + keyCnt);
                p++;
            }
        }
        assertEquals(0, cache.localSize());
        SqlFieldsQuery qry = new SqlFieldsQuery(sql);
        final QueryCursor<List<?>> cursor;
        if (timeout) {
            qry.setTimeout(timeoutUnits, timeUnit);
            cursor = cache.query(qry);
        } else {
            cursor = cache.query(qry);
            client.scheduler().runLocal(new Runnable() {

                @Override
                public void run() {
                    cursor.close();
                }
            }, timeoutUnits, timeUnit);
        }
        try (QueryCursor<List<?>> ignored = cursor) {
            cursor.iterator();
        } catch (CacheException ex) {
            log().error("Got expected exception", ex);
            assertTrue("Must throw correct exception", ex.getCause() instanceof QueryCancelledException);
        }
        // Give some time to clean up.
        Thread.sleep(TimeUnit.MILLISECONDS.convert(timeoutUnits, timeUnit) + 3_000);
        checkCleanState();
    }
}
Also used : CacheException(javax.cache.CacheException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException)

Example 53 with Ignite

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

the class ClosureServiceClientsNodesTest method testDefaultService.

/**
 * @throws Exception If failed.
 */
public void testDefaultService() throws Exception {
    UUID clientNodeId = grid(0).cluster().localNode().id();
    for (int i = 0; i < NODES_CNT; i++) {
        log.info("Iteration: " + i);
        final Ignite ignite = grid(i);
        ignite.services().deployNodeSingleton(SINGLETON_NAME, new TestService());
        final ClusterGroup grp = ignite.cluster();
        assertEquals(NODES_CNT, grp.nodes().size());
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ignite.services(grp).serviceDescriptors().size() == 1;
            }
        }, 5000);
        Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
        assertEquals(1, srvDscs.size());
        Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
        assertEquals(NODES_CNT - 1, nodesMap.size());
        for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
            assertFalse(clientNodeId.equals(nodeInfo.getKey()));
            assertEquals(1, nodeInfo.getValue().intValue());
        }
        ignite.services().cancelAll();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) ServiceDescriptor(org.apache.ignite.services.ServiceDescriptor) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) Map(java.util.Map)

Example 54 with Ignite

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

the class IgniteCacheReplicatedFieldsQueryJoinNoPrimaryPartitionsSelfTest method beforeTest.

/**
 *{@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    startGridsMultiThreaded(3);
    Ignite cli = startGrid(NODE_CLI);
    for (int i = 0; i < REP_CNT; i++) cli.cache(CACHE_REPLICATED).put(i, new RepValue(i));
    for (int i = 0; i < PART_CNT; i++) cli.cache(CACHE_PARTITIONED).put(i, new PartValue(i, ((i + 1) % REP_CNT)));
}
Also used : Ignite(org.apache.ignite.Ignite)

Example 55 with Ignite

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

the class ClosureServiceClientsNodesTest method testClientService.

/**
 * @throws Exception If failed.
 */
public void testClientService() throws Exception {
    UUID clientNodeId = grid(0).cluster().localNode().id();
    for (int i = 0; i < NODES_CNT; i++) {
        log.info("Iteration: " + i);
        final Ignite ignite = grid(i);
        ignite.services(ignite.cluster().forClients()).deployNodeSingleton(SINGLETON_NAME, new TestService());
        final ClusterGroup grp = ignite.cluster();
        assertEquals(NODES_CNT, grp.nodes().size());
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ignite.services(grp).serviceDescriptors().size() == 1;
            }
        }, 5000);
        Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
        assertEquals(1, srvDscs.size());
        Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
        assertEquals(1, nodesMap.size());
        for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
            assertEquals(clientNodeId, nodeInfo.getKey());
            assertEquals(1, nodeInfo.getValue().intValue());
        }
        ignite.services().cancelAll();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) ServiceDescriptor(org.apache.ignite.services.ServiceDescriptor) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) Map(java.util.Map)

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