Search in sources :

Example 21 with GridAbsPredicate

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

the class WalModeChangeCommonAbstractSelfTest method afterTest.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTest() throws Exception {
    for (Ignite node0 : Ignition.allGrids()) {
        Collection<String> cacheNames = node0.cacheNames();
        for (String cacheName : cacheNames) destroyCache(node0, cacheName);
    }
    awaitPartitionMapExchange();
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (Ignite node0 : Ignition.allGrids()) {
                if (!node0.cacheNames().isEmpty())
                    return false;
            }
            return true;
        }
    }, 2000));
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite)

Example 22 with GridAbsPredicate

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

the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientStartsFirst.

/**
 * @throws Exception If failed.
 */
@Test
public void testClientStartsFirst() throws Exception {
    final Ignite ignite0 = startClientGrid(0);
    assertTrue(ignite0.configuration().isClientMode());
    Ignite ignite1 = startGrid(1);
    assertFalse(ignite1.configuration().isClientMode());
    IgniteBinary binaries = ignite(1).binary();
    IgniteCache<Object, Object> cache = ignite(1).cache(DEFAULT_CACHE_NAME).withKeepBinary();
    for (int i = 0; i < 100; i++) {
        BinaryObjectBuilder builder = binaries.builder("type-" + i);
        builder.setField("f0", i);
        cache.put(i, builder.build());
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return ignite0.binary().types().size() == 100;
        }
    }, 5000);
    assertEquals(100, ignite(0).binary().types().size());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with GridAbsPredicate

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

the class IgniteCommunicationBalanceTest method testBalance1.

/**
 * @throws Exception If failed.
 */
@Test
public void testBalance1() throws Exception {
    if (sslEnabled())
        return;
    System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "5000");
    try {
        selectors = 4;
        final int SRVS = 6;
        startGridsMultiThreaded(SRVS);
        final Ignite client = startClientGrid(SRVS);
        for (int i = 0; i < SRVS; i++) {
            ClusterNode node = client.cluster().node(ignite(i).cluster().localNode().id());
            client.compute(client.cluster().forNode(node)).call(new DummyCallable(null));
        }
        waitNioBalanceStop(Collections.singletonList(client), 10_000);
        final GridNioServer srv = ((GridNioServerWrapper) GridTestUtils.getFieldValue(client.configuration().getCommunicationSpi(), "nioSrvWrapper")).nio();
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        long readMoveCnt1 = srv.readerMoveCount();
        long writeMoveCnt1 = srv.writerMoveCount();
        int prevNodeIdx = -1;
        for (int iter = 0; iter < 10; iter++) {
            int nodeIdx = rnd.nextInt(SRVS);
            while (prevNodeIdx == nodeIdx) nodeIdx = rnd.nextInt(SRVS);
            prevNodeIdx = nodeIdx;
            log.info("Iteration [iter=" + iter + ", node=" + nodeIdx + ']');
            final long readMoveCnt = readMoveCnt1;
            final long writeMoveCnt = writeMoveCnt1;
            final int nodeIdx0 = nodeIdx;
            GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    byte[] data = new byte[100_000];
                    for (int j = 0; j < 10; j++) {
                        for (int i = 0; i < SRVS; i++) {
                            ClusterNode node = client.cluster().node(ignite(i).cluster().localNode().id());
                            IgniteCompute compute = client.compute(client.cluster().forNode(node));
                            compute.call(new DummyCallable(i == nodeIdx0 ? data : null));
                        }
                    }
                    if (usePairedConnections())
                        return srv.readerMoveCount() > readMoveCnt && srv.writerMoveCount() > writeMoveCnt;
                    else
                        return srv.readerMoveCount() > readMoveCnt || srv.writerMoveCount() > writeMoveCnt;
                }
            }, 30_000);
            waitNioBalanceStop(Collections.singletonList(client), 30_000);
            long readMoveCnt2 = srv.readerMoveCount();
            long writeMoveCnt2 = srv.writerMoveCount();
            log.info("Move counts [rc1=" + readMoveCnt1 + ", wc1=" + writeMoveCnt1 + ", rc2=" + readMoveCnt2 + ", wc2=" + writeMoveCnt2 + ']');
            if (usePairedConnections()) {
                assertTrue(readMoveCnt2 > readMoveCnt1);
                assertTrue(writeMoveCnt2 > writeMoveCnt1);
            } else
                assertTrue(readMoveCnt2 > readMoveCnt1 || writeMoveCnt2 > writeMoveCnt1);
            readMoveCnt1 = readMoveCnt2;
            writeMoveCnt1 = writeMoveCnt2;
        }
        waitNioBalanceStop(G.allGrids(), 10_000);
    } finally {
        System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "");
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) IgniteCompute(org.apache.ignite.IgniteCompute) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with GridAbsPredicate

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

the class IgniteCacheConfigVariationsFullApiTest method testEvictExpired.

/**
 * @throws Exception In case of error.
 */
@Test
public void testEvictExpired() throws Exception {
    final IgniteCache<String, Integer> cache = jcache();
    final String key = primaryKeysForCache(1).get(0);
    cache.put(key, 1);
    assertEquals((Integer) 1, cache.get(key));
    long ttl = 500;
    final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
    grid(0).cache(cacheName()).withExpiryPolicy(expiry).put(key, 1);
    boolean wait = waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (int i = 0; i < gridCount(); i++) {
                if (jcache(i).localPeek(key) != null)
                    return false;
            }
            return true;
        }
    }, ttl + 1000);
    assertTrue("Failed to wait for entry expiration.", wait);
    // Expired entry should not be swapped.
    cache.localEvict(Collections.singleton(key));
    assertNull(cache.localPeek("key"));
    assertNull(cache.localPeek(key, ONHEAP));
    assertTrue(cache.localSize() == 0);
    if (storeEnabled()) {
        load(cache, key, true);
        Affinity<String> aff = ignite(0).affinity(cacheName());
        for (int i = 0; i < gridCount(); i++) {
            if (aff.isPrimary(grid(i).cluster().localNode(), key))
                assertEquals(1, jcache(i).localPeek(key));
            if (aff.isBackup(grid(i).cluster().localNode(), key))
                assertEquals(1, jcache(i).localPeek(key));
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest) Test(org.junit.Test)

Example 25 with GridAbsPredicate

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

the class IgniteCacheConfigVariationsFullApiTest method testPeekExpired.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11885")
@Test
public void testPeekExpired() throws Exception {
    final IgniteCache<String, Integer> c = jcache();
    final String key = primaryKeysForCache(1).get(0);
    info("Using key: " + key);
    c.put(key, 1);
    assertEquals(Integer.valueOf(1), c.localPeek(key));
    int ttl = 500;
    final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
    c.withExpiryPolicy(expiry).put(key, 1);
    Thread.sleep(ttl + 100);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return c.localPeek(key) == null;
        }
    }, 2000);
    assertNull(c.localPeek(key));
    assert c.localSize() == 0 : "Cache is not empty.";
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration) Ignore(org.junit.Ignore) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest) Test(org.junit.Test)

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