use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class TcpRestUnmarshalVulnerabilityTest method testExploit.
/**
* @param positive Positive.
*/
private void testExploit(boolean positive) throws Exception {
try {
startGrid();
attack(marshal(new Exploit()).array());
boolean res = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return SHARED.get();
}
}, 3000L);
if (positive)
assertTrue(res);
else
assertFalse(res);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridCacheAbstractLocalStoreSelfTest method testSwap.
/**
* @throws Exception If failed.
*/
@Test
public void testSwap() throws Exception {
Ignite ignite1 = startGrid(1);
IgniteCache<Object, Object> cache = ignite1.cache(DEFAULT_CACHE_NAME);
// Populate cache and check that local store has all value.
for (int i = 0; i < KEYS; i++) cache.put(i, i);
checkLocalStore(ignite1, LOCAL_STORE_1, DEFAULT_CACHE_NAME);
// Push entry to swap.
for (int i = 0; i < KEYS; i++) cache.localEvict(Lists.newArrayList(i));
for (int i = 0; i < KEYS; i++) assertNull(cache.localPeek(i, CachePeekMode.ONHEAP));
final AtomicInteger evtCnt = new AtomicInteger(0);
if (getCacheMode() != REPLICATED) {
ignite1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
evtCnt.incrementAndGet();
return true;
}
}, EventType.EVT_CACHE_REBALANCE_PART_UNLOADED);
}
final Ignite ignite2 = startGrid(2);
if (getCacheMode() != REPLICATED) {
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
// Partition count which must be transferred to 2'nd node.
int parts = ignite2.affinity(DEFAULT_CACHE_NAME).allPartitions(ignite2.cluster().localNode()).length;
return evtCnt.get() >= parts;
}
}, 5000);
assertTrue(wait);
}
assertEquals(Ignition.allGrids().size(), 2);
checkLocalStore(ignite1, LOCAL_STORE_1, DEFAULT_CACHE_NAME);
checkLocalStore(ignite2, LOCAL_STORE_2, DEFAULT_CACHE_NAME);
}
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 = ignite(0);
final UUID id = client.localNode().id();
DiscoverySpi srvSpi = spi0(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());
while (true) {
try {
cache.put(1, 1);
break;
} catch (Exception e) {
MvccFeatureChecker.assertMvccWriteConflict(e);
}
}
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 IgniteClientReconnectDelayedSpiTest method testReconnectCacheDestroyedDelayedAffinityChange.
/**
* Test checks correctness of stale {@link CacheAffinityChangeMessage} processing by client node as delayed
* {@link GridDhtPartitionsSingleMessage} with exchId = null sends after client node reconnect happens.
*
* @throws Exception If failed.
*/
@Test
public void testReconnectCacheDestroyedDelayedAffinityChange() throws Exception {
Ignite ignite = ignite(1);
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);
spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite.name());
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() == null;
}
});
final Ignite client = startClientGrid(getConfiguration());
client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
final Ignite srv = clientRouter(client);
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
srv.destroyCache(DEFAULT_CACHE_NAME);
srv.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
}
});
// Resend delayed GridDhtPartitionsSingleMessage.
spi.waitForBlocked();
spi.stopBlock();
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
final GridDiscoveryManager srvDisco = ((IgniteEx) srv).context().discovery();
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return F.eq(true, srvDisco.cacheClientNode(client.cluster().localNode(), DEFAULT_CACHE_NAME));
}
}, 5000));
}
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));
final int CLIENTS = 5;
List<Ignite> clients = new ArrayList<>();
for (int i = 0; i < CLIENTS; i++) {
Ignite client = startClientGrid(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++) {
startClientGrid(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(expNodes, 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());
}
startGrid(nodes++);
srvNodes++;
startClientGrid(nodes++);
}
}
Aggregations