Search in sources :

Example 56 with GridAbsPredicate

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

the class ClusterNodeMetricsSelfTest method testClusterNodeMetrics.

/**
 * @throws Exception If failed.
 */
public void testClusterNodeMetrics() throws Exception {
    final Ignite ignite0 = grid();
    final Ignite ignite1 = startGrid(1);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return ignite0.cluster().nodes().size() == 2 && ignite1.cluster().nodes().size() == 2;
        }
    }, 3000L);
    ClusterMetrics metrics0 = ignite0.cluster().localNode().metrics();
    ClusterMetrics nodesMetrics = ignite0.cluster().forNode(ignite0.cluster().localNode(), ignite1.cluster().localNode()).metrics();
    assertEquals(metrics0.getTotalCpus(), nodesMetrics.getTotalCpus());
    assertEquals(1, metrics0.getTotalNodes());
    assertEquals(2, nodesMetrics.getTotalNodes());
    assert metrics0.getHeapMemoryUsed() > 0;
    assert metrics0.getHeapMemoryTotal() > 0;
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite)

Example 57 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.
 */
public void testStreamerReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = clientRouter(client);
    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)

Example 58 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.
 */
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 = U.field(commSpi, "nioSrvr");
    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) 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)

Example 59 with GridAbsPredicate

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

the class GridEventStorageCheckAllEventsSelfTest method testTaskUndeployEvents.

/**
 * @throws Exception If test failed.
 */
public void testTaskUndeployEvents() throws Exception {
    final long tstamp = startTimestamp();
    generateEvents(null, new GridAllEventsSuccessTestJob()).get();
    // TODO: IGNITE-3099 (hotfix the test to check the event order in common case).
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                List<Event> evts = pullEvents(tstamp, 10);
                return evts.get(evts.size() - 1).type() == EVT_JOB_FINISHED;
            } catch (Exception ignored) {
                return false;
            }
        }
    }, 500);
    ignite.compute().undeployTask(GridAllEventsTestTask.class.getName());
    ignite.compute().localDeployTask(GridAllEventsTestTask.class, GridAllEventsTestTask.class.getClassLoader());
    List<Event> evts = pullEvents(tstamp, 12);
    assertEvent(evts.get(0).type(), EVT_TASK_STARTED, evts);
    assertEvent(evts.get(1).type(), EVT_JOB_MAPPED, evts);
    assertEvent(evts.get(2).type(), EVT_JOB_QUEUED, evts);
    assertEvent(evts.get(3).type(), EVT_JOB_STARTED, evts);
    assertEvent(evts.get(4).type(), EVT_CHECKPOINT_SAVED, evts);
    assertEvent(evts.get(5).type(), EVT_CHECKPOINT_REMOVED, evts);
    assertEvent(evts.get(6).type(), EVT_JOB_RESULTED, evts);
    assertEvent(evts.get(7).type(), EVT_TASK_REDUCED, evts);
    assertEvent(evts.get(8).type(), EVT_TASK_FINISHED, evts);
    assertEvent(evts.get(9).type(), EVT_JOB_FINISHED, evts);
    assertEvent(evts.get(10).type(), EVT_TASK_UNDEPLOYED, evts);
    assertEvent(evts.get(11).type(), EVT_TASK_DEPLOYED, evts);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) CheckpointEvent(org.apache.ignite.events.CheckpointEvent) DeploymentEvent(org.apache.ignite.events.DeploymentEvent) List(java.util.List) ArrayList(java.util.ArrayList) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException)

Example 60 with GridAbsPredicate

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

the class GridProjectionForCachesSelfTest method testProjectionForNamedCache.

/**
 * @throws Exception If failed.
 */
public void testProjectionForNamedCache() throws Exception {
    final ClusterGroup prj = ignite.cluster().forCacheNodes(CACHE_NAME);
    assertNotNull(prj);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return prj.nodes().size() == 3;
        }
    }, 5000);
    assertEquals("Invalid projection: " + prj.nodes(), 3, prj.nodes().size());
    assert !prj.nodes().contains(grid(0).localNode());
    assert prj.nodes().contains(grid(1).localNode());
    assert prj.nodes().contains(grid(2).localNode());
    assert prj.nodes().contains(grid(3).localNode());
    assert !prj.nodes().contains(grid(4).localNode());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

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