Search in sources :

Example 81 with GridAbsPredicate

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

the class TcpClientDiscoverySpiSelfTest method waitSegmented.

/**
 * @param ignite Ignite.
 * @throws Exception If failed.
 */
private void waitSegmented(final Ignite ignite) throws Exception {
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return IgniteState.STOPPED_ON_SEGMENTATION == Ignition.state(ignite.name());
        }
    }, 5000);
    assertEquals(IgniteState.STOPPED_ON_SEGMENTATION, Ignition.state(ignite.name()));
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 82 with GridAbsPredicate

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

the class TcpDiscoverySelfTest method waitNodeStop.

/**
 * @param nodeName Node name.
 * @throws Exception If failed.
 */
private void waitNodeStop(final String nodeName) throws Exception {
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                Ignition.ignite(nodeName);
                return false;
            } catch (IgniteIllegalStateException ignored) {
                return true;
            }
        }
    }, 30_000);
    if (!wait)
        U.dumpThreads(log);
    assertTrue("Failed to wait for node stop.", wait);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Example 83 with GridAbsPredicate

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

the class TcpDiscoverySelfTest method testIpFinderCleaning.

/**
 * @throws Exception If any error occurs.
 */
public void testIpFinderCleaning() throws Exception {
    try {
        ipFinder.registerAddresses(Arrays.asList(new InetSocketAddress("1.1.1.1", 1024), new InetSocketAddress("1.1.1.2", 1024)));
        Ignite g1 = startGrid(1);
        long failureDetectTimeout = g1.configuration().getFailureDetectionTimeout();
        long timeout = (long) (discoMap.get(g1.name()).getIpFinderCleanFrequency() * 1.5) + failureDetectTimeout;
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ipFinder.getRegisteredAddresses().size() == 1;
            }
        }, timeout);
        if (ipFinder.getRegisteredAddresses().size() != 1) {
            log.error("Failed to wait for IP cleanup, will dump threads.");
            U.dumpThreads(log);
        }
        assert ipFinder.getRegisteredAddresses().size() == 1 : "ipFinder=" + ipFinder.getRegisteredAddresses();
        // Check that missing addresses are returned back.
        // Unregister valid address.
        ipFinder.unregisterAddresses(ipFinder.getRegisteredAddresses());
        ipFinder.registerAddresses(Arrays.asList(new InetSocketAddress("1.1.1.1", 1024), new InetSocketAddress("1.1.1.2", 1024)));
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ipFinder.getRegisteredAddresses().size() == 1;
            }
        }, timeout);
        assert ipFinder.getRegisteredAddresses().size() == 1 : "ipFinder=" + ipFinder.getRegisteredAddresses();
    } finally {
        stopAllGrids();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) InetSocketAddress(java.net.InetSocketAddress) Ignite(org.apache.ignite.Ignite)

Example 84 with GridAbsPredicate

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

the class TcpDiscoveryVmIpFinderSelfTest method testUnregistration.

/**
 */
public void testUnregistration() throws Exception {
    Ignition.start(config("server1", false, false));
    int srvSize = IP_FINDER.getRegisteredAddresses().size();
    Ignition.start(config("server2", false, false));
    Ignition.start(config("client1", true, false));
    assertEquals(2 * srvSize, IP_FINDER.getRegisteredAddresses().size());
    Ignition.start(config("client2", true, false));
    Ignition.start(config("client3", true, false));
    assertEquals(2 * srvSize, IP_FINDER.getRegisteredAddresses().size());
    Ignition.start(config("client4", true, true));
    assertEquals(3 * srvSize, IP_FINDER.getRegisteredAddresses().size());
    Ignition.stop("client1", true);
    Ignition.stop("client2", true);
    Ignition.stop("client3", true);
    assertEquals(3 * srvSize, IP_FINDER.getRegisteredAddresses().size());
    Ignition.stop("client4", true);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return 2 == G.allGrids().size();
        }
    }, 10000);
    Ignition.stop("server1", true);
    Ignition.stop("server2", true);
    boolean res = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return G.allGrids().isEmpty();
        }
    }, 10000);
    assertTrue(res);
    assertTrue(3 * srvSize >= IP_FINDER.getRegisteredAddresses().size());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 85 with GridAbsPredicate

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

the class DiscoveryUnmarshalVulnerabilityTest method testExploit.

/**
 * @param positive Positive.
 */
private void testExploit(boolean positive) throws Exception {
    try {
        startGrid();
        attack(marshal(new Exploit()));
        boolean res = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return SHARED.get();
            }
        }, 3000L);
        if (positive)
            assertTrue(res);
        else
            assertFalse(res);
    } finally {
        stopAllGrids();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Aggregations

GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)175 Ignite (org.apache.ignite.Ignite)81 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ClusterNode (org.apache.ignite.cluster.ClusterNode)32 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 IgniteException (org.apache.ignite.IgniteException)22 CountDownLatch (java.util.concurrent.CountDownLatch)20 IgniteKernal (org.apache.ignite.internal.IgniteKernal)19 ArrayList (java.util.ArrayList)18 IgniteCache (org.apache.ignite.IgniteCache)16 Map (java.util.Map)15 Transaction (org.apache.ignite.transactions.Transaction)15 IgniteEx (org.apache.ignite.internal.IgniteEx)14 Duration (javax.cache.expiry.Duration)13 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)13 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)11 Event (org.apache.ignite.events.Event)11