Search in sources :

Example 16 with IgniteKernal

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

the class BasicWarmupClosure method doWarmup.

/**
 * @param grids Grids to warmup.
 */
private void doWarmup(Iterable<Ignite> grids) throws Exception {
    Ignite first = F.first(grids);
    ExecutorService svc = Executors.newFixedThreadPool(threadCnt);
    try {
        for (IgniteCacheProxy cache : ((IgniteKernal) first).caches()) {
            if (!cache.context().userCache())
                continue;
            IgniteInternalCache<Object, Object> cache0 = cache.context().cache();
            for (String warmupMethod : warmupMethods) {
                Collection<Future> futs = new ArrayList<>(threadCnt);
                for (int i = 0; i < threadCnt; i++) {
                    Callable call;
                    switch(warmupMethod) {
                        case "get":
                            {
                                call = new GetCallable(cache0);
                                break;
                            }
                        case "put":
                            {
                                call = new PutCallable(cache0);
                                break;
                            }
                        case "putx":
                            {
                                call = new PutxCallable(cache0);
                                break;
                            }
                        case "remove":
                            {
                                call = new RemoveCallable(cache0);
                                break;
                            }
                        case "removex":
                            {
                                call = new RemovexCallable(cache0);
                                break;
                            }
                        case "putIfAbsent":
                            {
                                call = new PutIfAbsentCallable(cache0);
                                break;
                            }
                        case "replace":
                            {
                                call = new ReplaceCallable(cache0);
                                break;
                            }
                        default:
                            throw new IgniteCheckedException("Unsupported warmup method: " + warmupMethod);
                    }
                    futs.add(svc.submit(call));
                }
                out("Running warmup [cacheName=" + U.maskName(cache.getName()) + ", method=" + warmupMethod + ']');
                for (Future fut : futs) fut.get();
                for (int key = 0; key < keyRange; key++) cache0.getAndRemove(key);
            }
        }
    } finally {
        svc.shutdownNow();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) ArrayList(java.util.ArrayList) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) Callable(java.util.concurrent.Callable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Ignite(org.apache.ignite.Ignite)

Example 17 with IgniteKernal

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

the class GridCachePreloadingEvictionsSelfTest method checkCachesConsistency.

/**
 * @param ignite1 Grid 1.
 * @param ignite2 Grid 2.
 * @throws Exception If failed.
 */
private void checkCachesConsistency(Ignite ignite1, Ignite ignite2) throws Exception {
    IgniteKernal g1 = (IgniteKernal) ignite1;
    IgniteKernal g2 = (IgniteKernal) ignite2;
    GridCacheAdapter<Integer, Object> cache1 = g1.internalCache(DEFAULT_CACHE_NAME);
    GridCacheAdapter<Integer, Object> cache2 = g2.internalCache(DEFAULT_CACHE_NAME);
    // Sleeping to allow the cache sizes to settle down.
    U.sleep(3000);
    info("Cache1 size: " + cache1.size(ALL_PEEK_MODES));
    info("Cache2 size: " + cache2.size(ALL_PEEK_MODES));
    assert cache1.size(ALL_PEEK_MODES) == cache2.size(ALL_PEEK_MODES) : "Sizes do not match [s1=" + cache1.size(ALL_PEEK_MODES) + ", s2=" + cache2.size(ALL_PEEK_MODES) + ']';
    for (Integer key : cache1.keySet()) {
        Object e = cache1.localPeek(key, new CachePeekMode[] { CachePeekMode.ONHEAP });
        if (e != null)
            assert cache2.containsKey(key) : "Cache2 does not contain key: " + key;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteKernal(org.apache.ignite.internal.IgniteKernal)

Example 18 with IgniteKernal

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

the class GridCacheStopSelfTest method testStopMultithreaded.

/**
 * @throws Exception If failed.
 */
@Test
public void testStopMultithreaded() throws Exception {
    try {
        startGrid(0);
        for (int i = 0; i < 5; i++) {
            log.info("Iteration: " + i);
            startGridsMultiThreaded(1, 3);
            final AtomicInteger threadIdx = new AtomicInteger(0);
            final IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    int idx = threadIdx.getAndIncrement();
                    IgniteKernal node = (IgniteKernal) ignite(idx % 3 + 1);
                    IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
                    while (true) {
                        try {
                            cacheOperations(node, cache);
                        } catch (Exception ignored) {
                            if (node.isStopping())
                                break;
                        }
                    }
                    return null;
                }
            }, 20, "tx-node-stop-thread");
            IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    IgniteKernal node = (IgniteKernal) ignite(0);
                    IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
                    while (!fut1.isDone()) {
                        try {
                            cacheOperations(node, cache);
                        } catch (Exception ignore) {
                        // No-op.
                        }
                    }
                    return null;
                }
            }, 2, "tx-thread");
            Thread.sleep(3000);
            final AtomicInteger nodeIdx = new AtomicInteger(1);
            GridTestUtils.runMultiThreaded(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    int idx = nodeIdx.getAndIncrement();
                    log.info("Stop node: " + idx);
                    ignite(idx).close();
                    return null;
                }
            }, 3, "stop-node");
            fut1.get();
            fut2.get();
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCache(org.apache.ignite.IgniteCache) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 19 with IgniteKernal

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

the class GridCacheMvccManagerSelfTest method testCandidates.

/**
 * @param gridCnt Grid count.
 * @throws Exception If failed.
 */
private void testCandidates(int gridCnt) throws Exception {
    try {
        Ignite ignite = startGridsMultiThreaded(gridCnt);
        IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
        Transaction tx = ignite.transactions().txStart();
        cache.put(1, 1);
        tx.commit();
        for (int i = 0; i < gridCnt; i++) {
            assert ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME).context().mvcc().localCandidates().isEmpty();
            assert ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME).context().mvcc().remoteCandidates().isEmpty();
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite)

Example 20 with IgniteKernal

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

the class GridCacheSequenceApiSelfAbstractTest method testCacheSets.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheSets() throws Exception {
    // Make new atomic sequence in cache.
    IgniteAtomicSequence seq = grid().atomicSequence(UUID.randomUUID().toString(), 0, true);
    seq.incrementAndGet();
    final String cacheName = DataStructuresProcessor.ATOMICS_CACHE_NAME + "@default-ds-group";
    GridCacheAdapter cache = ((IgniteKernal) grid()).internalCache(cacheName);
    assertNotNull(cache);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            grid().cache(cacheName);
            return null;
        }
    }, IllegalStateException.class, null);
    for (String seqName : seqNames) assert null != cache.get(new GridCacheInternalKeyImpl(seqName, "default-ds-group"));
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) IgniteException(org.apache.ignite.IgniteException) 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