Search in sources :

Example 96 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteDynamicCacheStartSelfTest method testStartStopCacheAddNode.

/**
     * @throws Exception If failed.
     */
public void testStartStopCacheAddNode() throws Exception {
    final IgniteEx kernal = grid(0);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(CacheMode.REPLICATED);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setName(DYNAMIC_CACHE_NAME);
    kernal.createCache(ccfg);
    info(">>>>>>> Deployed dynamic cache");
    startGrid(nodeCount());
    try {
        // Check that cache got deployed on new node.
        IgniteCache<Object, Object> cache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);
        cache.put("1", "1");
        for (int g = 0; g < nodeCount() + 1; g++) {
            assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));
            Collection<ClusterNode> nodes = grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(0);
            assertEquals(nodeCount() + 1, nodes.size());
        }
        // Undeploy cache.
        kernal.destroyCache(DYNAMIC_CACHE_NAME);
        startGrid(nodeCount() + 1);
        // Check that cache is not deployed on new node after undeploy.
        for (int g = 0; g < nodeCount() + 2; g++) {
            final IgniteKernal kernal0 = (IgniteKernal) grid(g);
            for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get();
            assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
        }
    } finally {
        stopGrid(nodeCount() + 1);
        stopGrid(nodeCount());
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 97 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteDynamicCacheStartSelfTest method testStartFromClientNode.

/**
     * @throws Exception If failed.
     */
public void testStartFromClientNode() throws Exception {
    try {
        testAttribute = false;
        startGrid(nodeCount());
        final IgniteEx kernal = grid(0);
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
        ccfg.setName(DYNAMIC_CACHE_NAME);
        ccfg.setNodeFilter(NODE_FILTER);
        final IgniteKernal started = (IgniteKernal) grid(nodeCount());
        started.createCache(ccfg);
        GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME);
        assertNotNull(cache);
        assertFalse(cache.context().affinityNode());
        // Should obtain client cache on new node.
        IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);
        clientCache.put("1", "1");
        for (int g = 0; g < nodeCount() + 1; g++) assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));
        kernal.destroyCache(DYNAMIC_CACHE_NAME);
    } finally {
        stopGrid(nodeCount());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 98 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteDynamicCacheStartSelfTest method checkStartStopCachesSimple.

/**
     * @param mode Cache atomicity mode.
     * @throws Exception If failed.
     */
private void checkStartStopCachesSimple(CacheAtomicityMode mode) throws Exception {
    final IgniteEx kernal = grid(0);
    final int cacheCnt = 3;
    List<CacheConfiguration> ccfgList = new ArrayList<>();
    for (int i = 0; i < cacheCnt; i++) {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
        ccfg.setAtomicityMode(mode);
        ccfg.setName(DYNAMIC_CACHE_NAME + Integer.toString(i));
        ccfgList.add(ccfg);
    }
    kernal.createCaches(ccfgList);
    for (int g = 0; g < nodeCount(); g++) {
        IgniteEx kernal0 = grid(g);
        for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get();
        info("Getting cache for node: " + g);
        for (int i = 0; i < cacheCnt; i++) assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME + Integer.toString(i)));
    }
    for (int i = 0; i < cacheCnt; i++) grid(0).cache(DYNAMIC_CACHE_NAME + Integer.toString(i)).put(Integer.toString(i), Integer.toString(i));
    for (int g = 0; g < nodeCount(); g++) {
        for (int i = 0; i < cacheCnt; i++) {
            assertEquals(Integer.toString(i), grid(g).cache(DYNAMIC_CACHE_NAME + Integer.toString(i)).get(Integer.toString(i)));
        }
    }
    // Grab caches before stop.
    final IgniteCache[] caches = new IgniteCache[nodeCount() * cacheCnt];
    for (int g = 0; g < nodeCount(); g++) {
        for (int i = 0; i < cacheCnt; i++) caches[g * nodeCount() + i] = grid(g).cache(DYNAMIC_CACHE_NAME + Integer.toString(i));
    }
    List<String> namesToDestroy = new ArrayList<>();
    for (int i = 0; i < cacheCnt; i++) namesToDestroy.add(DYNAMIC_CACHE_NAME + Integer.toString(i));
    kernal.destroyCaches(namesToDestroy);
    for (int g = 0; g < nodeCount(); g++) {
        final IgniteKernal kernal0 = (IgniteKernal) grid(g);
        for (int i = 0; i < cacheCnt; i++) {
            final int idx = g * nodeCount() + i;
            final int expVal = i;
            for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get();
            assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
            GridTestUtils.assertThrows(log, new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    return caches[idx].get(Integer.toString(expVal));
                }
            }, IllegalStateException.class, null);
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CacheExistsException(org.apache.ignite.cache.CacheExistsException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 99 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteDynamicCacheWithConfigStartSelfTest method testStartCacheOnClient.

/**
     * @throws Exception If failed.
     */
public void testStartCacheOnClient() throws Exception {
    int srvCnt = 3;
    startGrids(srvCnt);
    try {
        client = true;
        IgniteEx client = startGrid(srvCnt);
        for (int i = 0; i < 100; i++) client.cache(CACHE_NAME).put(i, i);
        for (int i = 0; i < 100; i++) assertEquals(i, grid(0).cache(CACHE_NAME).get(i));
        client.cache(CACHE_NAME).removeAll();
        for (int i = 0; i < 100; i++) assertNull(grid(0).cache(CACHE_NAME).get(i));
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 100 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteDynamicCacheStartNoExchangeTimeoutTest method oldestNotAffinityNode1.

/**
     * @param ccfg Cache configuration.
     * @throws Exception If failed.
     */
private void oldestNotAffinityNode1(final CacheConfiguration ccfg) throws Exception {
    log.info("Test with cache: " + ccfg.getName());
    IgniteEx ignite = grid(0);
    assertEquals(1L, ignite.localNode().order());
    ccfg.setNodeFilter(new TestFilterExcludeOldest());
    assertNotNull(ignite.getOrCreateCache(ccfg));
    awaitPartitionMapExchange();
    checkCache(ccfg.getName());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)198 Ignite (org.apache.ignite.Ignite)42 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)40 IgniteException (org.apache.ignite.IgniteException)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)32 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)26 Transaction (org.apache.ignite.transactions.Transaction)25 HashMap (java.util.HashMap)18 CacheException (javax.cache.CacheException)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 ArrayList (java.util.ArrayList)16 LinkedHashMap (java.util.LinkedHashMap)16 IgniteCache (org.apache.ignite.IgniteCache)16 CountDownLatch (java.util.concurrent.CountDownLatch)14 IgniteKernal (org.apache.ignite.internal.IgniteKernal)14 UUID (java.util.UUID)13 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)12 IOException (java.io.IOException)11 Map (java.util.Map)11