Search in sources :

Example 41 with GridAbsPredicate

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

the class IgniteClientReconnectCacheTest method checkCacheDiscoveryData.

/**
 * @param srv Server node.
 * @param client Client node.
 * @param cacheName Cache name.
 * @param cacheExists Cache exists flag.
 * @param clientCache {@code True} if client node has client cache.
 * @param clientNear {@code True} if client node has near-enabled client cache.
 * @throws Exception If failed.
 */
private void checkCacheDiscoveryData(Ignite srv, Ignite client, final String cacheName, boolean cacheExists, final boolean clientCache, boolean clientNear) throws Exception {
    final GridDiscoveryManager srvDisco = ((IgniteKernal) srv).context().discovery();
    GridDiscoveryManager clientDisco = ((IgniteKernal) client).context().discovery();
    ClusterNode srvNode = ((IgniteKernal) srv).localNode();
    final ClusterNode clientNode = ((IgniteKernal) client).localNode();
    assertFalse(srvDisco.cacheAffinityNode(clientNode, cacheName));
    assertFalse(clientDisco.cacheAffinityNode(clientNode, cacheName));
    assertEquals(cacheExists, srvDisco.cacheAffinityNode(srvNode, cacheName));
    if (clientNear) {
        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return srvDisco.cacheNearNode(clientNode, cacheName);
            }
        }, 5000));
        assertTrue(srvDisco.cacheNearNode(clientNode, cacheName));
    } else {
        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return F.eq(clientCache, srvDisco.cacheClientNode(clientNode, cacheName));
            }
        }, 5000));
        assertEquals(clientCache, srvDisco.cacheClientNode(clientNode, cacheName));
    }
    assertEquals(cacheExists, clientDisco.cacheAffinityNode(srvNode, cacheName));
    if (clientNear)
        assertTrue(clientDisco.cacheNearNode(clientNode, cacheName));
    else
        assertEquals(clientCache, clientDisco.cacheClientNode(clientNode, cacheName));
    if (cacheExists) {
        if (clientCache || clientNear) {
            assertTrue(client.cluster().forClientNodes(cacheName).nodes().contains(clientNode));
            assertTrue(srv.cluster().forClientNodes(cacheName).nodes().contains(clientNode));
        } else {
            assertFalse(client.cluster().forClientNodes(cacheName).nodes().contains(clientNode));
            assertFalse(srv.cluster().forClientNodes(cacheName).nodes().contains(clientNode));
        }
    } else {
        assertTrue(client.cluster().forClientNodes(cacheName).nodes().isEmpty());
        assertTrue(srv.cluster().forClientNodes(cacheName).nodes().isEmpty());
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 42 with GridAbsPredicate

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

the class GridVersionSelfTest method testVersions.

/**
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IGNITE_UPDATE_NOTIFIER, value = "true")
public void testVersions() throws Exception {
    try {
        final IgniteEx ignite = (IgniteEx) startGrid();
        IgniteProductVersion currVer = ignite.version();
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ignite.latestVersion() != null;
            }
        }, 2 * 60_000);
        String newVer = ignite.latestVersion();
        info("Versions [cur=" + currVer + ", latest=" + newVer + ']');
        assertNotNull(newVer);
        assertNotSame(currVer.toString(), newVer);
    } finally {
        stopGrid();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 43 with GridAbsPredicate

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

the class IgniteClientReconnectStreamerTest method testStreamerReconnectInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testStreamerReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    final IgniteCache<Object, Object> srvCache = srv.cache(CACHE_NAME);
    final IgniteDataStreamer<Integer, Integer> streamer = client.dataStreamer(CACHE_NAME);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    commSpi.blockMessage(DataStreamerResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                for (int i = 0; i < 50; i++) streamer.addData(i, i);
                streamer.flush();
            } catch (CacheException e) {
                checkAndWait(e);
                return true;
            } finally {
                streamer.close();
            }
            return false;
        }
    });
    // Check that client waiting operation.
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return fut.get(200);
        }
    }, IgniteFutureTimeoutCheckedException.class, null);
    assertNotDone(fut);
    commSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
    checkStreamerClosed(streamer);
    IgniteDataStreamer<Integer, Integer> streamer2 = client.dataStreamer(CACHE_NAME);
    for (int i = 0; i < 50; i++) streamer2.addData(i, i);
    streamer2.close();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return srvCache.localSize() == 50;
        }
    }, 2000L);
    assertEquals(50, srvCache.localSize());
}
Also used : CacheException(javax.cache.CacheException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CacheException(javax.cache.CacheException) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 44 with GridAbsPredicate

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

the class IgniteSlowClientDetectionSelfTest method testSlowClient.

/**
 * @throws Exception If failed.
 */
@Test
public void testSlowClient() throws Exception {
    final IgniteEx slowClient = grid(nodeCount() - 1);
    final ClusterNode slowClientNode = slowClient.localNode();
    final CountDownLatch evtSegmentedLatch = new CountDownLatch(1);
    slowClient.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            assertEquals("Unexpected event: " + evt, evt.type(), EventType.EVT_NODE_SEGMENTED);
            DiscoveryEvent evt0 = (DiscoveryEvent) evt;
            assertEquals(slowClientNode, evt0.eventNode());
            assertEquals(5L, evt0.topologyVersion());
            evtSegmentedLatch.countDown();
            return false;
        }
    }, EventType.EVT_NODE_SEGMENTED);
    final CountDownLatch evtFailedLatch = new CountDownLatch(nodeCount() - 1);
    for (int i = 0; i < nodeCount() - 1; i++) {
        grid(i).events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                assertEquals("Unexpected event: " + evt, evt.type(), EventType.EVT_NODE_FAILED);
                DiscoveryEvent evt0 = (DiscoveryEvent) evt;
                assertEquals(slowClientNode, evt0.eventNode());
                assertEquals(6L, evt0.topologyVersion());
                assertEquals(4, evt0.topologyNodes().size());
                evtFailedLatch.countDown();
                return false;
            }
        }, EventType.EVT_NODE_FAILED);
    }
    assertTrue(slowClient.cluster().localNode().isClient());
    IgniteCache<Object, Object> cache = slowClient.getOrCreateCache(PARTITIONED);
    IgniteEx client0 = grid(nodeCount() - 2);
    assertTrue(client0.cluster().localNode().isClient());
    IgniteCache<Object, Object> cache0 = client0.getOrCreateCache(PARTITIONED);
    cache.query(new ContinuousQuery<>().setLocalListener(new Listener()));
    for (int i = 0; i < 100; i++) cache0.put(0, i);
    GridIoManager ioMgr = slowClient.context().io();
    TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ((Object[]) U.field(ioMgr, "spis"))[0];
    GridNioServer nioSrvr = ((GridNioServerWrapper) GridTestUtils.getFieldValue(commSpi, "nioSrvWrapper")).nio();
    GridTestUtils.setFieldValue(nioSrvr, "skipRead", true);
    // Initiate messages for client.
    for (int i = 0; i < 100; i++) cache0.put(0, new byte[10 * 1024]);
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return Ignition.state(slowClient.name()) == IgniteState.STOPPED_ON_SEGMENTATION;
        }
    }, getTestTimeout());
    assertTrue(wait);
    assertTrue("Failed to wait for client failed event", evtFailedLatch.await(5000, MILLISECONDS));
    assertTrue("Failed to wait for client segmented event", evtSegmentedLatch.await(5000, MILLISECONDS));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) CountDownLatch(java.util.concurrent.CountDownLatch) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 45 with GridAbsPredicate

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

the class CacheLoadingConcurrentGridStartSelfTest method assertCacheSize.

/**
 * @throws Exception If failed.
 */
private void assertCacheSize(int expectedCacheSize) throws Exception {
    final IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    boolean consistentCache = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            int size = cache.size(CachePeekMode.PRIMARY);
            if (size != expectedCacheSize)
                log.info("Cache size: " + size);
            int total = 0;
            for (int i = 0; i < GRIDS_CNT; i++) total += grid(i).cache(DEFAULT_CACHE_NAME).localSize(CachePeekMode.PRIMARY);
            if (total != expectedCacheSize)
                log.info("Total size: " + size);
            return size == expectedCacheSize && expectedCacheSize == total;
        }
    }, 2 * 60_000);
    assertTrue("Data lost. Actual cache size: " + cache.size(CachePeekMode.PRIMARY), consistentCache);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

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