Search in sources :

Example 31 with IgniteKernal

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

the class IgniteClientAffinityAssignmentSelfTest method checkAffinityFunction.

/**
 * @throws Exception If failed.
 */
private void checkAffinityFunction() throws Exception {
    startGridsMultiThreaded(3, true);
    long topVer = 3;
    try {
        checkAffinity(topVer++);
        final Ignite ignite3 = startClientGrid(3);
        GridTestUtils.assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                ((IgniteKernal) ignite3).getCache(DEFAULT_CACHE_NAME);
                return null;
            }
        }, IllegalArgumentException.class, null);
        // Start client cache.
        assertNotNull(ignite3.cache(DEFAULT_CACHE_NAME));
        ((IgniteKernal) ignite3).getCache(DEFAULT_CACHE_NAME);
        checkAffinity(topVer++);
        final Ignite ignite4 = startClientGrid(4);
        GridTestUtils.assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                ((IgniteKernal) ignite4).getCache(DEFAULT_CACHE_NAME);
                return null;
            }
        }, IllegalArgumentException.class, null);
        // Start client cache.
        assertNotNull(ignite4.cache(DEFAULT_CACHE_NAME));
        ((IgniteKernal) ignite4).getCache(DEFAULT_CACHE_NAME);
        checkAffinity(topVer++);
        // Node without cache.
        final Ignite ignite5 = startClientGrid(5);
        GridTestUtils.assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                ((IgniteKernal) ignite5).getCache(DEFAULT_CACHE_NAME);
                return null;
            }
        }, IllegalArgumentException.class, null);
        checkAffinity(topVer++);
        stopGrid(5);
        checkAffinity(topVer++);
        stopGrid(4);
        checkAffinity(topVer++);
        stopGrid(3);
        checkAffinity(topVer);
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) Ignite(org.apache.ignite.Ignite)

Example 32 with IgniteKernal

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

the class IgniteClientCacheStartFailoverTest method testRebalanceStateConcurrentStart.

/**
 * @throws Exception If failed.
 */
@Test
public void testRebalanceStateConcurrentStart() throws Exception {
    final int SRVS1 = 3;
    final int CLIENTS = 5;
    final int SRVS2 = 5;
    startGrids(SRVS1);
    Ignite srv0 = ignite(0);
    final int KEYS = 1000;
    final List<String> cacheNames = startCaches(srv0, KEYS);
    final List<Ignite> clients = new ArrayList<>();
    for (int i = 0; i < CLIENTS; i++) clients.add(startClientGrid(SRVS1 + i));
    final CyclicBarrier barrier = new CyclicBarrier(clients.size() + SRVS2);
    final AtomicInteger clientIdx = new AtomicInteger();
    final Set<Integer> keys = new HashSet<>();
    for (int i = 0; i < KEYS; i++) keys.add(i);
    IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            barrier.await();
            Ignite client = clients.get(clientIdx.getAndIncrement());
            for (String cacheName : cacheNames) client.cache(cacheName);
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            for (int i = 0; i < 10; i++) {
                for (String cacheName : cacheNames) {
                    IgniteCache<Object, Object> cache = client.cache(cacheName);
                    Map<Object, Object> map0 = cache.getAll(keys);
                    assertEquals("[cache=" + cacheName + ", expected=" + KEYS + ", actual=" + map0.size() + ']', KEYS, map0.size());
                    int key = rnd.nextInt(KEYS);
                    try {
                        cache.put(key, i);
                    } catch (CacheException e) {
                        log.error("It couldn't put a value [cache=" + cacheName + ", key=" + key + ", val=" + i + ']', e);
                        CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
                        TransactionSerializationException txEx = X.cause(e, TransactionSerializationException.class);
                        boolean notContains = !txEx.getMessage().contains("Cannot serialize transaction due to write conflict (transaction is marked for rollback)");
                        if (txEx == null || ccfg.getAtomicityMode() != TRANSACTIONAL_SNAPSHOT || notContains)
                            fail("Assert violated because exception was thrown [e=" + e.getMessage() + ']');
                    }
                }
            }
            return null;
        }
    }, clients.size(), "client-cache-start");
    final AtomicInteger srvIdx = new AtomicInteger(SRVS1 + CLIENTS);
    IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            barrier.await();
            startGrid(srvIdx.incrementAndGet());
            return null;
        }
    }, SRVS2, "node-start");
    fut1.get();
    fut2.get();
    final AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS1 + SRVS2 + CLIENTS, 1);
    for (Ignite client : clients) {
        for (String cacheName : cacheNames) {
            final GridDhtPartitionTopology top = ((IgniteKernal) client).context().cache().internalCache(cacheName).context().topology();
            GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    return top.rebalanceFinished(topVer);
                }
            }, 5000);
            assertTrue(top.rebalanceFinished(topVer));
        }
    }
}
Also used : TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) CacheException(javax.cache.CacheException) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet) IgniteKernal(org.apache.ignite.internal.IgniteKernal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) CacheException(javax.cache.CacheException) TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TreeMap(java.util.TreeMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 33 with IgniteKernal

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

the class IgniteDynamicCacheStartSelfTest method checkStartStopCacheSimple.

/**
 * @param mode Cache atomicity mode.
 * @throws Exception If failed.
 */
private void checkStartStopCacheSimple(CacheAtomicityMode mode) throws Exception {
    final IgniteEx kernal = grid(0);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAtomicityMode(mode);
    ccfg.setName(DYNAMIC_CACHE_NAME);
    kernal.createCache(ccfg);
    for (int g = 0; g < nodeCount(); g++) {
        IgniteEx kernal0 = grid(g);
        info("Getting cache for node: " + g);
        assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME));
    }
    grid(0).cache(DYNAMIC_CACHE_NAME).put("1", "1");
    for (int g = 0; g < nodeCount(); g++) assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));
    // Grab caches before stop.
    final IgniteCache[] caches = new IgniteCache[nodeCount()];
    for (int g = 0; g < nodeCount(); g++) caches[g] = grid(g).cache(DYNAMIC_CACHE_NAME);
    kernal.destroyCache(DYNAMIC_CACHE_NAME);
    awaitPartitionMapExchange();
    for (int g = 0; g < nodeCount(); g++) {
        final IgniteKernal kernal0 = (IgniteKernal) grid(g);
        final int idx = g;
        assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
        GridTestUtils.assertThrows(log, new Callable<Object>() {

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

Example 34 with IgniteKernal

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

the class IgniteDynamicCacheStartSelfTest method testStartFromClientNode.

/**
 * @throws Exception If failed.
 */
@Test
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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 35 with IgniteKernal

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

the class IgniteDynamicCacheStartSelfTest method testStartStopCacheAddNode.

/**
 * @throws Exception If failed.
 */
@Test
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);
        awaitPartitionMapExchange();
        // 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);
            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) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteKernal (org.apache.ignite.internal.IgniteKernal)203 Ignite (org.apache.ignite.Ignite)88 Test (org.junit.Test)70 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)63 ClusterNode (org.apache.ignite.cluster.ClusterNode)38 ArrayList (java.util.ArrayList)36 Transaction (org.apache.ignite.transactions.Transaction)36 Map (java.util.Map)35 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)29 IgniteCache (org.apache.ignite.IgniteCache)29 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)28 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)27 IgniteEx (org.apache.ignite.internal.IgniteEx)27 UUID (java.util.UUID)25 IgniteException (org.apache.ignite.IgniteException)25 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)23 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)20 CacheException (javax.cache.CacheException)17 HashMap (java.util.HashMap)16