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