use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class WalModeChangeCommonAbstractSelfTest method afterTest.
/**
* {@inheritDoc}
*/
@Override
protected void afterTest() throws Exception {
for (Ignite node0 : Ignition.allGrids()) {
Collection<String> cacheNames = node0.cacheNames();
for (String cacheName : cacheNames) destroyCache(node0, cacheName);
}
awaitPartitionMapExchange();
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (Ignite node0 : Ignition.allGrids()) {
if (!node0.cacheNames().isEmpty())
return false;
}
return true;
}
}, 2000));
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientStartsFirst.
/**
* @throws Exception If failed.
*/
@Test
public void testClientStartsFirst() throws Exception {
final Ignite ignite0 = startClientGrid(0);
assertTrue(ignite0.configuration().isClientMode());
Ignite ignite1 = startGrid(1);
assertFalse(ignite1.configuration().isClientMode());
IgniteBinary binaries = ignite(1).binary();
IgniteCache<Object, Object> cache = ignite(1).cache(DEFAULT_CACHE_NAME).withKeepBinary();
for (int i = 0; i < 100; i++) {
BinaryObjectBuilder builder = binaries.builder("type-" + i);
builder.setField("f0", i);
cache.put(i, builder.build());
}
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite0.binary().types().size() == 100;
}
}, 5000);
assertEquals(100, ignite(0).binary().types().size());
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteCommunicationBalanceTest method testBalance1.
/**
* @throws Exception If failed.
*/
@Test
public void testBalance1() throws Exception {
if (sslEnabled())
return;
System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "5000");
try {
selectors = 4;
final int SRVS = 6;
startGridsMultiThreaded(SRVS);
final Ignite client = startClientGrid(SRVS);
for (int i = 0; i < SRVS; i++) {
ClusterNode node = client.cluster().node(ignite(i).cluster().localNode().id());
client.compute(client.cluster().forNode(node)).call(new DummyCallable(null));
}
waitNioBalanceStop(Collections.singletonList(client), 10_000);
final GridNioServer srv = ((GridNioServerWrapper) GridTestUtils.getFieldValue(client.configuration().getCommunicationSpi(), "nioSrvWrapper")).nio();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
long readMoveCnt1 = srv.readerMoveCount();
long writeMoveCnt1 = srv.writerMoveCount();
int prevNodeIdx = -1;
for (int iter = 0; iter < 10; iter++) {
int nodeIdx = rnd.nextInt(SRVS);
while (prevNodeIdx == nodeIdx) nodeIdx = rnd.nextInt(SRVS);
prevNodeIdx = nodeIdx;
log.info("Iteration [iter=" + iter + ", node=" + nodeIdx + ']');
final long readMoveCnt = readMoveCnt1;
final long writeMoveCnt = writeMoveCnt1;
final int nodeIdx0 = nodeIdx;
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
byte[] data = new byte[100_000];
for (int j = 0; j < 10; j++) {
for (int i = 0; i < SRVS; i++) {
ClusterNode node = client.cluster().node(ignite(i).cluster().localNode().id());
IgniteCompute compute = client.compute(client.cluster().forNode(node));
compute.call(new DummyCallable(i == nodeIdx0 ? data : null));
}
}
if (usePairedConnections())
return srv.readerMoveCount() > readMoveCnt && srv.writerMoveCount() > writeMoveCnt;
else
return srv.readerMoveCount() > readMoveCnt || srv.writerMoveCount() > writeMoveCnt;
}
}, 30_000);
waitNioBalanceStop(Collections.singletonList(client), 30_000);
long readMoveCnt2 = srv.readerMoveCount();
long writeMoveCnt2 = srv.writerMoveCount();
log.info("Move counts [rc1=" + readMoveCnt1 + ", wc1=" + writeMoveCnt1 + ", rc2=" + readMoveCnt2 + ", wc2=" + writeMoveCnt2 + ']');
if (usePairedConnections()) {
assertTrue(readMoveCnt2 > readMoveCnt1);
assertTrue(writeMoveCnt2 > writeMoveCnt1);
} else
assertTrue(readMoveCnt2 > readMoveCnt1 || writeMoveCnt2 > writeMoveCnt1);
readMoveCnt1 = readMoveCnt2;
writeMoveCnt1 = writeMoveCnt2;
}
waitNioBalanceStop(G.allGrids(), 10_000);
} finally {
System.setProperty(IgniteSystemProperties.IGNITE_IO_BALANCE_PERIOD, "");
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method testEvictExpired.
/**
* @throws Exception In case of error.
*/
@Test
public void testEvictExpired() throws Exception {
final IgniteCache<String, Integer> cache = jcache();
final String key = primaryKeysForCache(1).get(0);
cache.put(key, 1);
assertEquals((Integer) 1, cache.get(key));
long ttl = 500;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
grid(0).cache(cacheName()).withExpiryPolicy(expiry).put(key, 1);
boolean wait = waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
if (jcache(i).localPeek(key) != null)
return false;
}
return true;
}
}, ttl + 1000);
assertTrue("Failed to wait for entry expiration.", wait);
// Expired entry should not be swapped.
cache.localEvict(Collections.singleton(key));
assertNull(cache.localPeek("key"));
assertNull(cache.localPeek(key, ONHEAP));
assertTrue(cache.localSize() == 0);
if (storeEnabled()) {
load(cache, key, true);
Affinity<String> aff = ignite(0).affinity(cacheName());
for (int i = 0; i < gridCount(); i++) {
if (aff.isPrimary(grid(i).cluster().localNode(), key))
assertEquals(1, jcache(i).localPeek(key));
if (aff.isBackup(grid(i).cluster().localNode(), key))
assertEquals(1, jcache(i).localPeek(key));
}
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method testPeekExpired.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11885")
@Test
public void testPeekExpired() throws Exception {
final IgniteCache<String, Integer> c = jcache();
final String key = primaryKeysForCache(1).get(0);
info("Using key: " + key);
c.put(key, 1);
assertEquals(Integer.valueOf(1), c.localPeek(key));
int ttl = 500;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
c.withExpiryPolicy(expiry).put(key, 1);
Thread.sleep(ttl + 100);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return c.localPeek(key) == null;
}
}, 2000);
assertNull(c.localPeek(key));
assert c.localSize() == 0 : "Cache is not empty.";
}
Aggregations