Search in sources :

Example 26 with GridAbsPredicate

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

the class IgniteCacheEntryListenerAbstractTest method afterTest.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTest() throws Exception {
    super.afterTest();
    for (int i = 0; i < gridCount(); i++) {
        GridContinuousProcessor proc = grid(i).context().continuous();
        final ConcurrentMap<?, ?> syncMsgFuts = GridTestUtils.getFieldValue(proc, "syncMsgFuts");
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return syncMsgFuts.isEmpty();
            }
        }, 5000);
        assertEquals(0, syncMsgFuts.size());
    }
    serialized.set(false);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor)

Example 27 with GridAbsPredicate

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

the class AbstractCdcTest method createCdc.

/**
 */
protected CdcMain createCdc(CdcConsumer cnsmr, IgniteConfiguration cfg, CountDownLatch latch, GridAbsPredicate... conditions) {
    CdcConfiguration cdcCfg = new CdcConfiguration();
    cdcCfg.setConsumer(cnsmr);
    cdcCfg.setKeepBinary(keepBinary());
    cdcCfg.setMetricExporterSpi(metricExporters());
    return new CdcMain(cfg, null, cdcCfg) {

        @Override
        protected CdcConsumerState createState(Path stateDir) {
            return new CdcConsumerState(stateDir) {

                @Override
                public void save(WALPointer ptr) throws IOException {
                    super.save(ptr);
                    if (!F.isEmpty(conditions)) {
                        for (GridAbsPredicate p : conditions) {
                            if (!p.apply())
                                return;
                        }
                        latch.countDown();
                    }
                }
            };
        }
    };
}
Also used : Path(java.nio.file.Path) CdcConsumerState(org.apache.ignite.internal.cdc.CdcConsumerState) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CdcMain(org.apache.ignite.internal.cdc.CdcMain) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 28 with GridAbsPredicate

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

the class CdcSelfTest method testMultiNodeConsumption.

/**
 */
@Test
@WithSystemProperty(key = IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID, value = "true")
public void testMultiNodeConsumption() throws Exception {
    IgniteEx ign1 = startGrid(0);
    IgniteEx ign2 = startGrid(1);
    ign1.cluster().state(ACTIVE);
    IgniteCache<Integer, User> cache = ign1.getOrCreateCache(DEFAULT_CACHE_NAME);
    // Calculate expected count of key for each node.
    int[] keysCnt = new int[2];
    for (int i = 0; i < KEYS_CNT * 2; i++) {
        Ignite primary = primaryNode(i, DEFAULT_CACHE_NAME);
        assertTrue(primary == ign1 || primary == ign2);
        keysCnt[primary == ign1 ? 0 : 1]++;
    }
    // Adds data concurrently with CDC start.
    IgniteInternalFuture<?> addDataFut = runAsync(() -> addData(cache, 0, KEYS_CNT));
    UserCdcConsumer cnsmr1 = new UserCdcConsumer();
    UserCdcConsumer cnsmr2 = new UserCdcConsumer();
    IgniteConfiguration cfg1 = getConfiguration(ign1.name());
    IgniteConfiguration cfg2 = getConfiguration(ign2.name());
    // Always run CDC with consistent id to ensure instance read data for specific node.
    if (!specificConsistentId) {
        cfg1.setConsistentId((Serializable) ign1.localNode().consistentId());
        cfg2.setConsistentId((Serializable) ign2.localNode().consistentId());
    }
    CountDownLatch latch = new CountDownLatch(2);
    GridAbsPredicate sizePredicate1 = sizePredicate(keysCnt[0], DEFAULT_CACHE_NAME, UPDATE, cnsmr1);
    GridAbsPredicate sizePredicate2 = sizePredicate(keysCnt[1], DEFAULT_CACHE_NAME, UPDATE, cnsmr2);
    CdcMain cdc1 = createCdc(cnsmr1, cfg1, latch, sizePredicate1);
    CdcMain cdc2 = createCdc(cnsmr2, cfg2, latch, sizePredicate2);
    IgniteInternalFuture<?> fut1 = runAsync(cdc1);
    IgniteInternalFuture<?> fut2 = runAsync(cdc2);
    addDataFut.get(getTestTimeout());
    runAsync(() -> addData(cache, KEYS_CNT, KEYS_CNT * 2)).get(getTestTimeout());
    // Wait while predicate will become true and state saved on the disk for both cdc.
    assertTrue(latch.await(getTestTimeout(), MILLISECONDS));
    checkMetrics(cdc1, keysCnt[0]);
    checkMetrics(cdc2, keysCnt[1]);
    assertFalse(cnsmr1.stopped());
    assertFalse(cnsmr2.stopped());
    fut1.cancel();
    fut2.cancel();
    assertTrue(cnsmr1.stopped());
    assertTrue(cnsmr2.stopped());
    removeData(cache, 0, KEYS_CNT * 2);
    cdc1 = createCdc(cnsmr1, cfg1);
    cdc2 = createCdc(cnsmr2, cfg2);
    IgniteInternalFuture<?> rmvFut1 = runAsync(cdc1);
    IgniteInternalFuture<?> rmvFut2 = runAsync(cdc2);
    waitForSize(KEYS_CNT * 2, DEFAULT_CACHE_NAME, DELETE, cnsmr1, cnsmr2);
    checkMetrics(cdc1, keysCnt[0]);
    checkMetrics(cdc2, keysCnt[1]);
    rmvFut1.cancel();
    rmvFut2.cancel();
    assertTrue(cnsmr1.stopped());
    assertTrue(cnsmr2.stopped());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CdcMain(org.apache.ignite.internal.cdc.CdcMain) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 29 with GridAbsPredicate

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

the class IgniteOnePhaseCommitNearSelfTest method finalCheck.

/**
 * @throws Exception If failed.
 */
private void finalCheck(final int key, boolean onePhase) throws Exception {
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                for (int i = 0; i < GRID_CNT; i++) {
                    GridCacheAdapter<Object, Object> cache = ((IgniteKernal) ignite(i)).internalCache(DEFAULT_CACHE_NAME);
                    GridCacheEntryEx entry = cache.peekEx(key);
                    if (entry != null) {
                        if (entry.lockedByAny()) {
                            info("Near entry is still locked [i=" + i + ", entry=" + entry + ']');
                            return false;
                        }
                    }
                    entry = cache.context().near().dht().peekEx(key);
                    if (entry != null) {
                        if (entry.lockedByAny()) {
                            info("DHT entry is still locked [i=" + i + ", entry=" + entry + ']');
                            return false;
                        }
                    }
                }
                return true;
            } catch (GridCacheEntryRemovedException ignore) {
                info("Entry was removed, will retry");
                return false;
            }
        }
    }, 10_000);
    if (onePhase) {
        assertMessageCount(GridNearTxPrepareRequest.class, 1);
        assertMessageCount(GridDhtTxPrepareRequest.class, 1);
        assertMessageCount(GridNearTxFinishRequest.class, 1);
        assertMessageCount(GridDhtTxFinishRequest.class, 1);
        msgCntMap.clear();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 30 with GridAbsPredicate

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

GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)229 Ignite (org.apache.ignite.Ignite)109 Test (org.junit.Test)102 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)65 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 ClusterNode (org.apache.ignite.cluster.ClusterNode)37 IgniteEx (org.apache.ignite.internal.IgniteEx)34 IgniteException (org.apache.ignite.IgniteException)31 ArrayList (java.util.ArrayList)29 CountDownLatch (java.util.concurrent.CountDownLatch)28 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)28 Transaction (org.apache.ignite.transactions.Transaction)25 Map (java.util.Map)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 IgniteCache (org.apache.ignite.IgniteCache)19 IgniteKernal (org.apache.ignite.internal.IgniteKernal)19 HashMap (java.util.HashMap)17 Duration (javax.cache.expiry.Duration)15 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)13 UUID (java.util.UUID)12