Search in sources :

Example 96 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheStoreUsageMultinodeAbstractTest method testStoreUpdate.

/**
     * @param cache Cache.
     * @param key Key.
     * @param tc Transaction concurrency mode.
     * @throws Exception If failed.
     */
protected void testStoreUpdate(IgniteCache<Object, Object> cache, Object key, @Nullable TransactionConcurrency tc) throws Exception {
    boolean storeOnPrimary = atomicityMode() == ATOMIC || locStore || writeBehind;
    assertTrue(writeMap.isEmpty());
    Ignite ignite = cache.unwrap(Ignite.class);
    Affinity<Object> obj = ignite.affinity(cache.getName());
    ClusterNode node = obj.mapKeyToNode(key);
    assertNotNull(node);
    String expNode = storeOnPrimary ? (String) node.attribute(ATTR_IGNITE_INSTANCE_NAME) : ignite.name();
    assertNotNull(expNode);
    log.info("Put [node=" + ignite.name() + ", key=" + key + ", primary=" + node.attribute(ATTR_IGNITE_INSTANCE_NAME) + ", tx=" + tc + ", nearCache=" + (cache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null) + ", storeOnPrimary=" + storeOnPrimary + ']');
    Transaction tx = tc != null ? ignite.transactions().txStart(tc, REPEATABLE_READ) : null;
    try {
        cache.put(key, key);
        if (tx != null)
            tx.commit();
    } finally {
        if (tx != null)
            tx.close();
    }
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return writeMap.size() > 0;
        }
    }, 1000);
    assertTrue("Store is not updated", wait);
    assertEquals("Write on wrong node: " + writeMap, locStore ? 2 : 1, writeMap.size());
    if (!locStore)
        assertEquals(expNode, writeMap.keySet().iterator().next());
    writeMap.clear();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Transaction(org.apache.ignite.transactions.Transaction) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite)

Example 97 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate 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 98 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class GridCacheSetAbstractSelfTest method testCreateRemove.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
private void testCreateRemove(boolean collocated) throws Exception {
    for (int i = 0; i < gridCount(); i++) assertNull(grid(i).set(SET_NAME, null));
    CollectionConfiguration colCfg0 = config(collocated);
    IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg0);
    assertNotNull(set0);
    for (int i = 0; i < gridCount(); i++) {
        CollectionConfiguration colCfg = config(collocated);
        IgniteSet<Integer> set = grid(i).set(SET_NAME, colCfg);
        assertNotNull(set);
        assertTrue(set.isEmpty());
        assertEquals(0, set.size());
        assertEquals(SET_NAME, set.name());
        if (collectionCacheMode() == PARTITIONED)
            assertEquals(collocated, set.collocated());
    }
    set0.close();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                for (int i = 0; i < gridCount(); i++) {
                    if (grid(i).set(SET_NAME, null) != null)
                        return false;
                }
                return true;
            } catch (Exception e) {
                fail("Unexpected exception: " + e);
                return true;
            }
        }
    }, 1000);
    for (int i = 0; i < gridCount(); i++) assertNull(grid(i).set(SET_NAME, null));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 99 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheLockReleaseNodeLeaveTest method testTxLockRelease2.

/**
     * @throws Exception If failed.
     */
public void testTxLockRelease2() throws Exception {
    final Ignite ignite0 = startGrid(0);
    Ignite ignite1 = startGrid(1);
    IgniteCache cache = ignite1.cache(DEFAULT_CACHE_NAME);
    ignite1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
    cache.get(1);
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            startGrid(2);
            return null;
        }
    });
    final AffinityTopologyVersion topVer = new AffinityTopologyVersion(2, 0);
    // Wait when affinity change exchange start.
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            AffinityTopologyVersion topVer0 = ((IgniteKernal) ignite0).context().cache().context().exchange().topologyVersion();
            return topVer.compareTo(topVer0) < 0;
        }
    }, 10_000);
    assertTrue(wait);
    assertFalse(fut.isDone());
    ignite1.close();
    fut.get(10_000);
    Ignite ignite2 = ignite(2);
    cache = ignite2.cache(DEFAULT_CACHE_NAME);
    try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.get(1);
        tx.commit();
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite)

Example 100 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheLockReleaseNodeLeaveTest method testLockRelease2.

/**
     * @throws Exception If failed.
     */
public void testLockRelease2() throws Exception {
    final Ignite ignite0 = startGrid(0);
    Ignite ignite1 = startGrid(1);
    Lock lock = ignite1.cache(DEFAULT_CACHE_NAME).lock("key");
    lock.lock();
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            startGrid(2);
            return null;
        }
    });
    final AffinityTopologyVersion topVer = new AffinityTopologyVersion(2, 0);
    // Wait when affinity change exchange start.
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            AffinityTopologyVersion topVer0 = ((IgniteKernal) ignite0).context().cache().context().exchange().topologyVersion();
            return topVer.compareTo(topVer0) < 0;
        }
    }, 10_000);
    assertTrue(wait);
    assertFalse(fut.isDone());
    ignite1.close();
    fut.get(10_000);
    Ignite ignite2 = ignite(2);
    lock = ignite2.cache(DEFAULT_CACHE_NAME).lock("key");
    lock.lock();
    lock.unlock();
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) Lock(java.util.concurrent.locks.Lock)

Aggregations

GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)137 Ignite (org.apache.ignite.Ignite)59 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)38 ClusterNode (org.apache.ignite.cluster.ClusterNode)26 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteException (org.apache.ignite.IgniteException)20 CountDownLatch (java.util.concurrent.CountDownLatch)17 ArrayList (java.util.ArrayList)14 Duration (javax.cache.expiry.Duration)13 IgniteKernal (org.apache.ignite.internal.IgniteKernal)13 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)13 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)11 IgniteCache (org.apache.ignite.IgniteCache)11 Event (org.apache.ignite.events.Event)11 GridNioServer (org.apache.ignite.internal.util.nio.GridNioServer)11 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)11 Transaction (org.apache.ignite.transactions.Transaction)11 Collection (java.util.Collection)10 Map (java.util.Map)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10