Search in sources :

Example 36 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 37 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 38 with IgniteKernal

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

the class TaskCommandHandlerSelfTest method testManyTasksRun.

/**
 * @throws Exception If failed.
 */
@Test
public void testManyTasksRun() throws Exception {
    GridClientCompute compute = client.compute();
    for (int i = 0; i < 1000; i++) assertEquals(new Integer("executing".length()), compute.execute(TestTask.class.getName(), "executing"));
    GridClientFactory.stop(client.id(), true);
    IgniteKernal g = (IgniteKernal) grid(0);
    Map<GridRestCommand, GridRestCommandHandler> handlers = U.field(g.context().rest(), "handlers");
    GridTaskCommandHandler taskHnd = (GridTaskCommandHandler) F.find(handlers.values(), null, new P1<GridRestCommandHandler>() {

        @Override
        public boolean apply(GridRestCommandHandler e) {
            return e instanceof GridTaskCommandHandler;
        }
    });
    assertNotNull("GridTaskCommandHandler was not found", taskHnd);
    ConcurrentLinkedHashMap taskDesc = U.field(taskHnd, "taskDescs");
    assertTrue("Task result map size exceeded max value [mapSize=" + taskDesc.sizex() + ", " + "maxSize=" + MAX_TASK_RESULTS + ']', taskDesc.sizex() <= MAX_TASK_RESULTS);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridRestCommandHandler(org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler) IgniteKernal(org.apache.ignite.internal.IgniteKernal) P1(org.apache.ignite.internal.util.typedef.P1) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) GridTaskCommandHandler(org.apache.ignite.internal.processors.rest.handlers.task.GridTaskCommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 39 with IgniteKernal

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

the class GridBinaryMarshaller method threadLocalContext.

/**
 * @return Thread-bound context.
 */
public static BinaryContext threadLocalContext() {
    BinaryContext ctx = BINARY_CTX.get().get();
    if (ctx == null) {
        IgniteKernal ignite = IgnitionEx.localIgnite();
        IgniteCacheObjectProcessor proc = ignite.context().cacheObjects();
        if (proc instanceof CacheObjectBinaryProcessorImpl)
            return ((CacheObjectBinaryProcessorImpl) proc).binaryContext();
        else
            throw new IgniteIllegalStateException("Ignite instance must be started with " + BinaryMarshaller.class.getName() + " [name=" + ignite.name() + ']');
    }
    return ctx;
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Example 40 with IgniteKernal

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

the class GridCacheSlowTxWarnTest method checkCache.

/**
 * @param g Grid.
 * @param cacheName Cache.
 * @param simulateTimeout Simulate timeout.
 * @param configureTimeout Alter configuration of TX manager.
 * @throws Exception If failed.
 */
private void checkCache(Ignite g, String cacheName, boolean simulateTimeout, boolean configureTimeout) throws Exception {
    if (configureTimeout) {
        GridCacheAdapter<Integer, Integer> cache = ((IgniteKernal) g).internalCache(cacheName);
        cache.context().tm().slowTxWarnTimeout(500);
    }
    IgniteCache<Object, Object> cache1 = g.cache(cacheName);
    Transaction tx = g.transactions().txStart();
    try {
        cache1.put(1, 1);
        if (simulateTimeout)
            Thread.sleep(800);
        tx.commit();
    } finally {
        tx.close();
    }
    tx = g.transactions().txStart();
    try {
        cache1.put(1, 1);
        if (simulateTimeout)
            Thread.sleep(800);
        tx.rollback();
    } finally {
        tx.close();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) Transaction(org.apache.ignite.transactions.Transaction)

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