Search in sources :

Example 51 with IgniteKernal

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

the class IgniteCacheLockFailoverSelfTest method testUnlockPrimaryLeft.

/**
 * @throws Exception If failed.
 */
public void testUnlockPrimaryLeft() throws Exception {
    GridCacheAdapter<Integer, Integer> cache = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
    Integer key = backupKey(grid(0).cache(DEFAULT_CACHE_NAME));
    cache.lock(key, 0);
    stopGrid(1);
    cache.unlock(key);
    GridCacheEntryEx entry = cache.peekEx(key);
    assertTrue("Remote MVCC is not empty: " + entry, entry == null || entry.remoteMvccSnapshot().isEmpty());
    startGrid(1);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx)

Example 52 with IgniteKernal

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

the class IgniteCacheLockFailoverSelfTest method testLockFailover.

/**
 * @throws Exception If failed.
 */
public void testLockFailover() throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    Integer key = backupKey(cache);
    final AtomicBoolean stop = new AtomicBoolean();
    IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!stop.get()) {
                stopGrid(1);
                U.sleep(500);
                startGrid(1);
            }
            return null;
        }
    });
    try {
        long end = System.currentTimeMillis() + 60_000;
        long iter = 0;
        while (System.currentTimeMillis() < end) {
            if (iter % 100 == 0)
                log.info("Iteration: " + iter);
            iter++;
            GridCacheAdapter<Object, Object> adapter = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
            IgniteInternalFuture<Boolean> fut = adapter.lockAsync(key, 0);
            try {
                fut.get(30_000);
                U.sleep(1);
            } catch (IgniteFutureTimeoutException e) {
                info("Entry: " + adapter.peekEx(key));
                fail("Lock timeout [fut=" + fut + ", err=" + e + ']');
            } catch (Exception e) {
                log.error("Error: " + e);
            } finally {
                adapter.unlock(key);
            }
        }
    } finally {
        stop.set(true);
        restartFut.get();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 53 with IgniteKernal

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

the class GridCacheSyncReplicatedPreloadSelfTest method testNodeRestart.

/**
 * @throws Exception If test failed.
 */
@SuppressWarnings({ "TooBroadScope" })
public void testNodeRestart() throws Exception {
    int keyCnt = 1000;
    int retries = 20;
    Ignite g0 = startGrid(0);
    Ignite g1 = startGrid(1);
    for (int i = 0; i < keyCnt; i++) g0.cache(DEFAULT_CACHE_NAME).put(i, i);
    assertEquals(keyCnt, ((IgniteKernal) g0).internalCache(DEFAULT_CACHE_NAME).size());
    assertEquals(keyCnt, ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).size());
    for (int n = 0; n < retries; n++) {
        info("Starting additional grid node...");
        Ignite g2 = startGrid(2);
        assertEquals(keyCnt, ((IgniteKernal) g2).internalCache(DEFAULT_CACHE_NAME).size());
        info("Stopping additional grid node...");
        stopGrid(2);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) Ignite(org.apache.ignite.Ignite)

Example 54 with IgniteKernal

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

the class HadoopJobTrackerSelfTest method checkStatus.

/**
 * Checks job execution status.
 *
 * @param jobId Job ID.
 * @param complete Completion status.
 * @throws Exception If failed.
 */
private void checkStatus(HadoopJobId jobId, boolean complete) throws Exception {
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal kernal = (IgniteKernal) grid(i);
        Hadoop hadoop = kernal.hadoop();
        HadoopJobStatus stat = hadoop.status(jobId);
        assert stat != null;
        IgniteInternalFuture<?> fut = hadoop.finishFuture(jobId);
        if (!complete)
            assertFalse(fut.isDone());
        else {
            info("Waiting for status future completion on node [idx=" + i + ", nodeId=" + kernal.getLocalNodeId() + ']');
            fut.get();
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) HadoopJobStatus(org.apache.ignite.internal.processors.hadoop.HadoopJobStatus) Hadoop(org.apache.ignite.internal.processors.hadoop.Hadoop)

Example 55 with IgniteKernal

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

the class IgniteCacheExpiryPolicyWithStoreAbstractTest method checkTtl.

/**
 * @param key Key.
 * @param ttl TTL.
 * @param primaryOnly If {@code true} expect entries only on primary node.
 * @throws Exception If failed.
 */
private void checkTtl(Object key, final long ttl, boolean primaryOnly) throws Exception {
    boolean found = 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 = null;
        try {
            e = cache.entryEx(key);
            e.unswap();
        } catch (GridDhtInvalidPartitionException ignore) {
        // No-op.
        }
        if ((e == null || e.rawGet() == null) && cache.context().isNear())
            e = cache.context().near().dht().peekEx(key);
        if (e == null || e.rawGet() == null)
            e = null;
        if (e == null) {
            if (primaryOnly)
                assertTrue("Not found " + key, !grid.affinity(DEFAULT_CACHE_NAME).isPrimary(grid.localNode(), key));
            else
                assertTrue("Not found " + key, !grid.affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid.localNode(), key));
        } else {
            found = true;
            if (ttl > 0)
                assertTrue(e.expireTime() > 0);
            else
                assertEquals(0, e.expireTime());
        }
    }
    assertTrue(found);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx)

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