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;
}
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());
}
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));
}
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);
}
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());
}
Aggregations