Search in sources :

Example 66 with IgniteKernal

use of org.apache.ignite.internal.IgniteKernal 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);
        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);
    awaitPartitionMapExchange();
    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;
            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) 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 67 with IgniteKernal

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

the class IgniteDynamicCacheStartStopConcurrentTest method checkTopologyVersion.

/**
 * @param topVer Expected version.
 */
private void checkTopologyVersion(AffinityTopologyVersion topVer) {
    for (int i = 0; i < NODES; i++) {
        IgniteKernal ignite = (IgniteKernal) ignite(i);
        assertEquals(ignite.name(), topVer, ignite.context().discovery().topologyVersionEx());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal)

Example 68 with IgniteKernal

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

the class IgniteCachePeekModesAbstractTest method checkStorage.

/**
 * @param nodeIdx Node index.
 * @throws Exception If failed.
 */
private void checkStorage(int nodeIdx) throws Exception {
    if (// TODO GG-11148.
    true)
        return;
    IgniteCache<Integer, String> cache0 = jcache(nodeIdx);
    List<Integer> keys = primaryKeys(cache0, 100, 10_000);
    try {
        final String val = "test_value";
        for (Integer key : keys) cache0.put(key, val);
        Ignite ignite = ignite(nodeIdx);
        GridCacheAdapter<Integer, String> internalCache = ((IgniteKernal) ignite).context().cache().internalCache(DEFAULT_CACHE_NAME);
        CacheObjectContext coctx = internalCache.context().cacheObjectContext();
        Set<Integer> swapKeys = new HashSet<>();
        // TODO GG-11148.
        // SwapSpaceSpi swap = ignite.configuration().getSwapSpaceSpi();
        // 
        // IgniteSpiCloseableIterator<KeyCacheObject> it = swap.keyIterator(SPACE_NAME, null);
        IgniteSpiCloseableIterator<KeyCacheObject> it = new GridEmptyCloseableIterator<>();
        assertNotNull(it);
        while (it.hasNext()) {
            KeyCacheObject next = it.next();
            assertTrue(swapKeys.add((Integer) next.value(coctx, false)));
        }
        assertFalse(swapKeys.isEmpty());
        assertTrue(swapKeys.size() + HEAP_ENTRIES < 100);
        Set<Integer> offheapKeys = new HashSet<>();
        // TODO GG-11148.
        Iterator<Map.Entry<Integer, String>> offheapIt = Collections.EMPTY_MAP.entrySet().iterator();
        while (offheapIt.hasNext()) {
            Map.Entry<Integer, String> e = offheapIt.next();
            assertTrue(offheapKeys.add(e.getKey()));
            assertFalse(swapKeys.contains(e.getKey()));
        }
        assertFalse(offheapKeys.isEmpty());
        Set<Integer> heapKeys = new HashSet<>(keys);
        heapKeys.removeAll(offheapKeys);
        heapKeys.removeAll(swapKeys);
        assertFalse(heapKeys.isEmpty());
        log.info("Keys [swap=" + swapKeys.size() + ", offheap=" + offheapKeys.size() + ", heap=" + heapKeys.size() + ']');
        assertEquals(100, swapKeys.size() + offheapKeys.size() + heapKeys.size());
        for (Integer key : swapKeys) {
            assertEquals(val, cache0.localPeek(key));
            assertEquals(val, cache0.localPeek(key, PRIMARY));
            assertEquals(val, cache0.localPeek(key, ONHEAP));
            assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP));
            assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP));
            assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP, OFFHEAP));
            if (cacheMode() == LOCAL) {
                assertEquals(val, cache0.localPeek(key, BACKUP));
                assertEquals(val, cache0.localPeek(key, NEAR));
            } else {
                assertNull(cache0.localPeek(key, BACKUP));
                assertNull(cache0.localPeek(key, NEAR));
            }
            assertNull(cache0.localPeek(key, ONHEAP));
            assertNull(cache0.localPeek(key, OFFHEAP));
        }
        for (Integer key : offheapKeys) {
            assertEquals(val, cache0.localPeek(key, OFFHEAP));
            assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP));
            assertEquals(val, cache0.localPeek(key, ONHEAP, OFFHEAP));
            assertEquals(val, cache0.localPeek(key, PRIMARY, OFFHEAP));
            if (cacheMode() == LOCAL) {
                assertEquals(val, cache0.localPeek(key, OFFHEAP, BACKUP));
                assertEquals(val, cache0.localPeek(key, OFFHEAP, NEAR));
            } else {
                assertNull(cache0.localPeek(key, OFFHEAP, BACKUP));
                assertNull(cache0.localPeek(key, OFFHEAP, NEAR));
            }
            assertNull(cache0.localPeek(key, ONHEAP));
            assertNull(cache0.localPeek(key));
        }
        for (Integer key : heapKeys) {
            assertEquals(val, cache0.localPeek(key, ONHEAP));
            assertEquals(val, cache0.localPeek(key, ONHEAP));
            assertEquals(val, cache0.localPeek(key, OFFHEAP, ONHEAP));
            assertEquals(val, cache0.localPeek(key, PRIMARY, ONHEAP));
            if (cacheMode() == LOCAL) {
                assertEquals(val, cache0.localPeek(key, ONHEAP, BACKUP));
                assertEquals(val, cache0.localPeek(key, ONHEAP, NEAR));
            } else {
                assertNull(cache0.localPeek(key, ONHEAP, BACKUP));
                assertNull(cache0.localPeek(key, ONHEAP, NEAR));
            }
            assertNull(cache0.localPeek(key));
            assertNull(cache0.localPeek(key, OFFHEAP));
        }
    } finally {
        cache0.removeAll(new HashSet<>(keys));
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridEmptyCloseableIterator(org.apache.ignite.internal.util.GridEmptyCloseableIterator) Ignite(org.apache.ignite.Ignite) Map(java.util.Map) HashSet(java.util.HashSet)

Example 69 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 {
    cache = true;
    startGridsMultiThreaded(3, true);
    long topVer = 3;
    try {
        checkAffinity(topVer++);
        cache = false;
        final Ignite ignite3 = startGrid(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 = startGrid(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 = startGrid(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 70 with IgniteKernal

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

the class IgniteTopologyPrintFormatSelfTest method setLogger.

/**
 * Set log.
 *
 * @param log Log.
 * @param server Ignite.
 */
private void setLogger(MockLogger log, Ignite server) {
    IgniteKernal server0 = (IgniteKernal) server;
    GridDiscoveryManager discovery = server0.context().discovery();
    GridTestUtils.setFieldValue(discovery, GridManagerAdapter.class, "log", log);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal)

Aggregations

IgniteKernal (org.apache.ignite.internal.IgniteKernal)181 Ignite (org.apache.ignite.Ignite)78 ClusterNode (org.apache.ignite.cluster.ClusterNode)35 ArrayList (java.util.ArrayList)34 Map (java.util.Map)30 Transaction (org.apache.ignite.transactions.Transaction)30 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)27 IgniteCache (org.apache.ignite.IgniteCache)26 UUID (java.util.UUID)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)22 IgniteException (org.apache.ignite.IgniteException)21 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)20 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)19 IgniteEx (org.apache.ignite.internal.IgniteEx)15 HashMap (java.util.HashMap)14 List (java.util.List)14 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13