Search in sources :

Example 26 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 27 with IgniteKernal

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

the class IgniteTxMultiNodeAbstractTest method nearEntry.

/**
 * @param nodeId Node ID.
 * @param key Key.
 * @return Near entry.
 */
@Nullable
private static GridCacheEntryEx nearEntry(UUID nodeId, Object key) {
    Ignite g = G.ignite(nodeId);
    GridNearCacheAdapter<Object, Integer> near = ((IgniteKernal) g).<Object, Integer>internalCache(DEFAULT_CACHE_NAME).context().near();
    return near.peekEx(key);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Ignite(org.apache.ignite.Ignite) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with IgniteKernal

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

the class IgnitePutAllUpdateNonPreloadedPartitionSelfTest method testPessimistic.

/**
 * @throws Exception If failed.
 */
@Test
public void testPessimistic() throws Exception {
    backups = 2;
    startGrids(GRID_CNT - 1);
    try {
        for (int i = 0; i < GRID_CNT - 1; i++) grid(i).cache(DEFAULT_CACHE_NAME).rebalance().get();
        startGrid(GRID_CNT - 1);
        IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        final int keyCnt = 100;
        try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            for (int k = 0; k < keyCnt; k++) cache.get(k);
            for (int k = 0; k < keyCnt; k++) cache.put(k, k);
            tx.commit();
        }
        // Check that no stale transactions left and all locks are released.
        for (int g = 0; g < GRID_CNT; g++) {
            IgniteKernal k = (IgniteKernal) grid(g);
            GridCacheAdapter<Object, Object> cacheAdapter = k.context().cache().internalCache(DEFAULT_CACHE_NAME);
            assertEquals(0, cacheAdapter.context().tm().idMapSize());
            for (int i = 0; i < keyCnt; i++) {
                if (cacheAdapter.isNear()) {
                    GridDhtCacheEntry entry = (GridDhtCacheEntry) ((GridNearCacheAdapter<Object, Object>) cacheAdapter).dht().peekEx(i);
                    if (entry != null) {
                        assertFalse(entry.lockedByAny());
                        assertTrue(entry.localCandidates().isEmpty());
                        assertTrue(entry.remoteMvccSnapshot().isEmpty());
                    }
                }
                GridCacheEntryEx entry = cacheAdapter.peekEx(i);
                if (entry != null) {
                    assertFalse(entry.lockedByAny());
                    assertTrue(entry.localCandidates().isEmpty());
                    assertTrue(entry.remoteMvccSnapshot().isEmpty());
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) Transaction(org.apache.ignite.transactions.Transaction) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 29 with IgniteKernal

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

the class IgniteTxAbstractTest method checkCommit.

/**
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If check failed.
 */
protected void checkCommit(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
    int gridIdx = RAND.nextInt(gridCount());
    Ignite ignite = grid(gridIdx);
    if (isTestDebug())
        debug("Checking commit on grid: " + ignite.cluster().localNode().id());
    for (int i = 0; i < iterations(); i++) {
        IgniteCache<Integer, String> cache = jcache(gridIdx);
        try (Transaction tx = ignite(gridIdx).transactions().txStart(concurrency, isolation, 0, 0)) {
            int prevKey = -1;
            for (Integer key : getKeys()) {
                // Make sure we have the same locking order for all concurrent transactions.
                assert key >= prevKey : "key: " + key + ", prevKey: " + prevKey;
                if (isTestDebug()) {
                    AffinityFunction aff = cache.getConfiguration(CacheConfiguration.class).getAffinity();
                    int part = aff.partition(key);
                    debug("Key affinity [key=" + key + ", partition=" + part + ", affinity=" + U.toShortString(ignite(gridIdx).affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(part)) + ']');
                }
                String val = Integer.toString(key);
                switch(getOp()) {
                    case READ:
                        {
                            if (isTestDebug())
                                debug("Reading key [key=" + key + ", i=" + i + ']');
                            val = cache.get(key);
                            if (isTestDebug())
                                debug("Read value for key [key=" + key + ", val=" + val + ']');
                            break;
                        }
                    case WRITE:
                        {
                            if (isTestDebug())
                                debug("Writing key and value [key=" + key + ", val=" + val + ", i=" + i + ']');
                            cache.put(key, val);
                            break;
                        }
                    case REMOVE:
                        {
                            if (isTestDebug())
                                debug("Removing key [key=" + key + ", i=" + i + ']');
                            cache.remove(key);
                            break;
                        }
                    default:
                        {
                            assert false;
                        }
                }
            }
            tx.commit();
            if (isTestDebug())
                debug("Committed transaction [i=" + i + ", tx=" + tx + ']');
        } catch (TransactionOptimisticException e) {
            if (!(concurrency == OPTIMISTIC && isolation == SERIALIZABLE)) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        } catch (CacheException e) {
            MvccFeatureChecker.assertMvccWriteConflict(e);
        } catch (Throwable e) {
            log.error("Unexpected error: " + e, e);
            throw e;
        }
    }
    Transaction tx = ignite(gridIdx).transactions().tx();
    assertNull("Thread should not have transaction upon completion", tx);
    if (printMemoryStats()) {
        if (cntr.getAndIncrement() % 100 == 0)
            // Print transaction memory stats.
            ((IgniteKernal) grid(gridIdx)).internalCache(DEFAULT_CACHE_NAME).context().tm().printMemoryStats();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) Ignite(org.apache.ignite.Ignite) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 30 with IgniteKernal

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

the class IgniteDynamicClientCacheStartSelfTest method checkNoCache.

/**
 * @param ignite Node.
 * @param cacheName Cache name.
 * @throws Exception If failed.
 */
private void checkNoCache(Ignite ignite, final String cacheName) throws Exception {
    GridCacheAdapter<Object, Object> cache = ((IgniteKernal) ignite).context().cache().internalCache(cacheName);
    assertNull("Unexpected cache on node " + ignite.name(), cache);
    final ClusterNode node = ((IgniteKernal) ignite).localNode();
    for (Ignite ignite0 : Ignition.allGrids()) {
        final GridDiscoveryManager disco = ((IgniteKernal) ignite0).context().discovery();
        if (ignite0 == ignite)
            assertFalse(ignite0.name(), disco.cacheNode(node, cacheName));
        else {
            assertTrue(ignite0.name(), GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    return !disco.cacheNode(node, cacheName);
                }
            }, 5000));
        }
        assertFalse(disco.cacheAffinityNode(node, cacheName));
        assertFalse(disco.cacheNearNode(node, cacheName));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite)

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