use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgfsBackupFailoverSelfTest method testWriteFailoverWhileStoppingMultipleNodes.
/**
* @throws Exception
*/
public void testWriteFailoverWhileStoppingMultipleNodes() throws Exception {
final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
clear(igfs0);
IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
final IgfsOutputStream[] outStreams = new IgfsOutputStream[files];
// Create files:
for (int f = 0; f < files; f++) {
final byte[] data = createChunk(fileSize, f);
IgfsOutputStream os = null;
try {
os = igfs0.create(filePath(f), 256, true, null, 0, -1, null);
assert os != null;
writeFileChunks(os, data);
} finally {
if (os != null)
os.flush();
}
outStreams[f] = os;
X.println("write #1 completed: " + f);
}
final AtomicBoolean stop = new AtomicBoolean();
GridTestUtils.runMultiThreadedAsync(new Callable() {
@Override
public Object call() throws Exception {
// Some delay to ensure read is in progress.
Thread.sleep(10_000);
// Now stop all the nodes but the 1st:
for (int n = 1; n < numIgfsNodes; n++) {
stopGrid(n);
X.println("#### grid " + n + " stopped.");
}
// Thread.sleep(10_000);
stop.set(true);
return null;
}
}, 1, "igfs-node-stopper");
// Write #2:
for (int f0 = 0; f0 < files; f0++) {
final IgfsOutputStream os = outStreams[f0];
assert os != null;
final int f = f0;
int att = doWithRetries(1, new Callable<Void>() {
@Override
public Void call() throws Exception {
IgfsOutputStream ios = os;
try {
writeChunks0(igfs0, ios, f);
} catch (IOException ioe) {
log().warning("Attempt to append the data to existing stream failed: ", ioe);
ios = igfs0.append(filePath(f), false);
assert ios != null;
writeChunks0(igfs0, ios, f);
}
return null;
}
});
assert att == 1;
X.println("write #2 completed: " + f0 + " in " + att + " attempts.");
}
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return stop.get();
}
}, 25_000);
// Check files:
for (int f = 0; f < files; f++) {
IgfsPath path = filePath(f);
byte[] data = createChunk(fileSize, f);
// Check through 1st node:
checkExist(igfs0, path);
assertEquals("File length mismatch.", data.length * 2, igfs0.size(path));
checkFileContent(igfs0, path, data, data);
X.println("Read test completed: " + f);
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridVersionSelfTest method testVersions.
/**
* @throws Exception If failed.
*/
public void testVersions() throws Exception {
String propVal = System.getProperty(IGNITE_UPDATE_NOTIFIER);
System.setProperty(IGNITE_UPDATE_NOTIFIER, "true");
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();
if (propVal != null)
System.setProperty(IGNITE_UPDATE_NOTIFIER, propVal);
else
System.clearProperty(IGNITE_UPDATE_NOTIFIER);
}
}
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 IgniteClientReconnectCacheTest method checkOperationInProgressFails.
/**
* @param client Client.
* @param ccfg Cache configuration.
* @param msgToBlock Message to block.
* @param c Cache operation closure.
* @throws Exception If failed.
*/
private void checkOperationInProgressFails(final IgniteEx client, final CacheConfiguration<Object, Object> ccfg, Class<?> msgToBlock, final IgniteInClosure<IgniteCache<Object, Object>> c) throws Exception {
Ignite srv = clientRouter(client);
final UUID id = client.localNode().id();
TestTcpDiscoverySpi srvSpi = spi(srv);
final IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg);
for (int i = 0; i < SRV_CNT; i++) {
TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) grid(i).configuration().getCommunicationSpi();
srvCommSpi.blockMessages(msgToBlock, client.localNode().id());
}
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteClientDisconnectedException e0 = null;
try {
assertEquals(id, client.localNode().id());
c.apply(cache);
fail();
} catch (IgniteClientDisconnectedException e) {
log.info("Expected exception: " + e);
e0 = e;
} catch (CacheException e) {
log.info("Expected exception: " + e);
assertTrue("Unexpected cause: " + e.getCause(), e.getCause() instanceof IgniteClientDisconnectedException);
e0 = (IgniteClientDisconnectedException) e.getCause();
}
assertNotNull(e0);
assertNotNull(e0.reconnectFuture());
e0.reconnectFuture().get();
assertNotEquals(id, client.localNode().id());
c.apply(cache);
return null;
}
});
Thread.sleep(1000);
assertNotDone(fut);
log.info("Fail client: " + client.localNode().id());
srvSpi.failNode(client.localNode().id(), null);
try {
fut.get();
} finally {
for (int i = 0; i < SRV_CNT; i++) ((TestCommunicationSpi) grid(i).configuration().getCommunicationSpi()).stopBlock(false);
}
assertNotEquals(id, client.localNode().id());
cache.put(1, 1);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return cache.get(1) != null;
}
}, 5000);
assertEquals(1, cache.get(1));
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteClientReconnectCacheTest method reconnectMultinode.
/**
* @param longHist If {@code true} generates many discovery events to overflow events history.
* @throws Exception If failed.
*/
private void reconnectMultinode(boolean longHist) throws Exception {
grid(0).createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
clientMode = true;
final int CLIENTS = 5;
List<Ignite> clients = new ArrayList<>();
for (int i = 0; i < CLIENTS; i++) {
Ignite client = startGrid(SRV_CNT + i);
assertNotNull(client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)));
clients.add(client);
}
if (longHist) {
// Generate many discovery events to overflow discovery events history.
final AtomicInteger nodeIdx = new AtomicInteger(SRV_CNT + CLIENTS);
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = nodeIdx.incrementAndGet();
for (int i = 0; i < 25; i++) {
startGrid(idx);
stopGrid(idx);
}
return null;
}
}, 4, "restart-thread");
}
int nodes = SRV_CNT + CLIENTS;
int srvNodes = SRV_CNT;
for (int iter = 0; iter < 5; iter++) {
log.info("Iteration: " + iter);
reconnectClientNodes(log, clients, grid(0), null);
final int expNodes = CLIENTS + srvNodes;
for (final Ignite client : clients) {
IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
cache.put(client.name(), 1);
assertEquals(1, cache.get(client.name()));
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
ClusterGroup grp = client.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
return grp.nodes().size() == expNodes;
}
}, 5000);
ClusterGroup grp = client.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
assertEquals(CLIENTS + srvNodes, grp.nodes().size());
grp = client.cluster().forClientNodes(DEFAULT_CACHE_NAME);
assertEquals(CLIENTS, grp.nodes().size());
}
for (int i = 0; i < nodes; i++) {
final Ignite ignite = grid(i);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
ClusterGroup grp = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
return grp.nodes().size() == expNodes;
}
}, 5000);
ClusterGroup grp = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
assertEquals(CLIENTS + srvNodes, grp.nodes().size());
grp = ignite.cluster().forClientNodes(DEFAULT_CACHE_NAME);
assertEquals(CLIENTS, grp.nodes().size());
}
clientMode = false;
startGrid(nodes++);
srvNodes++;
clientMode = true;
startGrid(nodes++);
}
}
Aggregations