Search in sources :

Example 86 with IgniteKernal

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

the class GridCacheNestedTxAbstractTest method testTwoTx.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
public void testTwoTx() throws Exception {
    final IgniteCache<String, Integer> c = grid(0).cache(DEFAULT_CACHE_NAME);
    GridKernalContext ctx = ((IgniteKernal) grid(0)).context();
    c.put(CNTR_KEY, 0);
    for (int i = 0; i < 10; i++) {
        try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            c.get(CNTR_KEY);
            ctx.closure().callLocalSafe((new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    assertFalse(((GridCacheAdapter) c).context().tm().inUserTx());
                    assertNull(((GridCacheAdapter) c).context().tm().userTx());
                    return true;
                }
            }), true);
            tx.commit();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Transaction(org.apache.ignite.transactions.Transaction) GridKernalContext(org.apache.ignite.internal.GridKernalContext) Callable(java.util.concurrent.Callable)

Example 87 with IgniteKernal

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

the class GridCacheOrderedPreloadingSelfTest method checkPreloadOrder.

/**
 * @param first First cache mode.
 * @param second Second cache mode.
 * @throws Exception If failed.
 */
private void checkPreloadOrder(CacheMode first, CacheMode second) throws Exception {
    firstCacheMode = first;
    secondCacheMode = second;
    Ignite g = startGrid(0);
    try {
        IgniteCache<Object, Object> cache = g.cache("first");
        // Put some data into cache.
        for (int i = 0; i < 1000; i++) cache.put(i, i);
        for (int i = 1; i < GRID_CNT; i++) startGrid(i);
        // For first node in topology replicated preloader gets completed right away.
        for (int i = 1; i < GRID_CNT; i++) {
            IgniteKernal kernal = (IgniteKernal) grid(i);
            GridFutureAdapter<?> fut1 = (GridFutureAdapter<?>) kernal.internalCache(FIRST_CACHE_NAME).preloader().syncFuture();
            GridFutureAdapter<?> fut2 = (GridFutureAdapter<?>) kernal.internalCache(SECOND_CACHE_NAME).preloader().syncFuture();
            fut1.get();
            fut2.get();
            long firstSyncTime = times.get(i).get(FIRST_CACHE_NAME);
            long secondSyncTime = times.get(i).get(SECOND_CACHE_NAME);
            assertTrue(FIRST_CACHE_NAME + " [syncTime=" + firstSyncTime + "], " + SECOND_CACHE_NAME + " [syncTime=" + secondSyncTime + "]", firstSyncTime <= secondSyncTime);
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Ignite(org.apache.ignite.Ignite)

Example 88 with IgniteKernal

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

the class GridCacheP2PUndeploySelfTest method checkP2PUndeploy.

/**
 * @param cacheName Cache name.
 * @throws Exception If failed.
 */
private void checkP2PUndeploy(final String cacheName) throws Exception {
    assert !F.isEmpty(cacheName);
    ClassLoader ldr = getExternalClassLoader();
    Class valCls = ldr.loadClass(TEST_VALUE);
    try {
        Ignite ignite1 = startGrid(1);
        final IgniteKernal grid2 = (IgniteKernal) startGrid(2);
        IgniteCache<Integer, Object> cache1 = ignite1.cache(cacheName);
        IgniteCache<Integer, Object> cache2 = grid2.cache(cacheName);
        Object v1 = valCls.newInstance();
        cache1.put(1, v1);
        cache1.put(2, valCls.newInstance());
        cache1.put(3, valCls.newInstance());
        cache1.put(4, valCls.newInstance());
        info("Stored value in cache1 [v=" + v1 + ", ldr=" + v1.getClass().getClassLoader() + ']');
        Object v2 = cache2.get(1);
        assert v2 != null;
        info("Read value from cache2 [v=" + v2 + ", ldr=" + v2.getClass().getClassLoader() + ']');
        assert v2 != null;
        assert v2.toString().equals(v1.toString());
        assert !v2.getClass().getClassLoader().equals(getClass().getClassLoader());
        assert v2.getClass().getClassLoader().getClass().getName().contains("GridDeploymentClassLoader");
        cache2.localEvict(ImmutableSet.of(2, 3, 4));
        // Wait until entries stored to disk.
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                try {
                    return size(cacheName, grid2) > 0;
                } catch (IgniteCheckedException e) {
                    throw new AssertionError(e);
                }
            }
        }, 5000);
        stopGrid(1);
        assert waitCacheEmpty(cache2, 10000);
        for (int i = 0; i < 3; i++) {
            long swapSize = size(cacheName, grid2);
            if (swapSize > 0) {
                if (i < 2) {
                    U.warn(log, "Swap size check failed (will retry in 1000 ms): " + swapSize);
                    U.sleep(1000);
                    continue;
                }
                fail("Swap size check failed: " + swapSize);
            } else if (swapSize == 0)
                break;
            else
                assert false : "Negative swap size: " + swapSize;
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Ignite(org.apache.ignite.Ignite)

Example 89 with IgniteKernal

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

the class GridCacheSlowTxWarnTest method testWarningOutput.

/**
 * @throws Exception If failed.
 */
public void testWarningOutput() throws Exception {
    try {
        IgniteKernal g = (IgniteKernal) startGrid(1);
        info(">>> Slow tx timeout is not set, long-live txs simulated.");
        checkCache(g, "partitioned", true, false);
        checkCache(g, "replicated", true, false);
        checkCache(g, "local", true, false);
        info(">>> Slow tx timeout is set, long-live tx simulated.");
        checkCache(g, "partitioned", true, true);
        checkCache(g, "replicated", true, true);
        checkCache(g, "local", true, true);
        info(">>> Slow tx timeout is set, no long-live txs.");
        checkCache(g, "partitioned", false, true);
        checkCache(g, "replicated", false, true);
        checkCache(g, "local", false, true);
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal)

Example 90 with IgniteKernal

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

the class GridCacheVersionMultinodeTest method checkEntryVersion.

/**
 * @param key Key.
 * @throws Exception If failed.
 */
private void checkEntryVersion(String key) throws Exception {
    GridCacheVersion ver = null;
    boolean verified = false;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        GridCacheAdapter<Object, Object> cache = grid.context().cache().internalCache(DEFAULT_CACHE_NAME);
        GridCacheEntryEx e;
        if (cache.affinity().isPrimaryOrBackup(grid.localNode(), key)) {
            if (cache instanceof GridNearCacheAdapter)
                cache = ((GridNearCacheAdapter<Object, Object>) cache).dht();
            e = cache.entryEx(key);
            e.unswap();
            assertNotNull(e.rawGet());
        } else
            e = cache.peekEx(key);
        if (e != null) {
            if (ver != null) {
                assertEquals("Non-equal versions for key: " + key, ver, e instanceof GridNearCacheEntry ? ((GridNearCacheEntry) e).dhtVersion() : e.version());
                verified = true;
            } else
                ver = e instanceof GridNearCacheEntry ? ((GridNearCacheEntry) e).dhtVersion() : e.version();
        }
    }
    assertTrue(verified);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)

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