use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method waitExpired.
/**
* @param keys Keys.
* @throws Exception If failed.
*/
private void waitExpired(final Collection<Integer> keys) throws Exception {
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
for (Integer key : keys) {
Object val = jcache(i).localPeek(key);
if (val != null) {
return false;
}
}
}
return false;
}
}, 3000);
checkNoValue(keys);
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class HadoopTaskExecutionSelfTest method testTaskCancelling.
/**
* @throws Exception If failed.
*/
public void testTaskCancelling() throws Exception {
Configuration cfg = prepareJobForCancelling();
HadoopJobId jobId = new HadoopJobId(UUID.randomUUID(), 1);
final IgniteInternalFuture<?> fut = grid(0).hadoop().submit(jobId, createJobInfo(cfg, null));
if (!GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return splitsCount.get() > 0;
}
}, 20000)) {
U.dumpThreads(log);
assertTrue(false);
}
if (!GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return executedTasks.get() == splitsCount.get();
}
}, 20000)) {
U.dumpThreads(log);
assertTrue(false);
}
// Fail mapper with id "1", cancels others
failMapperId.set(1);
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
fut.get();
return null;
}
}, IgniteCheckedException.class, null);
assertEquals(executedTasks.get(), cancelledTasks.get() + 1);
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteClientCacheStartFailoverTest method testRebalanceStateConcurrentStart.
/**
* @throws Exception If failed.
*/
public void testRebalanceStateConcurrentStart() throws Exception {
final int SRVS1 = 3;
final int CLIENTS = 5;
final int SRVS2 = 5;
startGrids(SRVS1);
Ignite srv0 = ignite(0);
final int KEYS = 1000;
final List<String> cacheNames = startCaches(srv0, KEYS);
client = true;
final List<Ignite> clients = new ArrayList<>();
for (int i = 0; i < CLIENTS; i++) clients.add(startGrid(SRVS1 + i));
client = false;
final CyclicBarrier barrier = new CyclicBarrier(clients.size() + SRVS2);
final AtomicInteger clientIdx = new AtomicInteger();
final Set<Integer> keys = new HashSet<>();
for (int i = 0; i < KEYS; i++) keys.add(i);
IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
Ignite client = clients.get(clientIdx.getAndIncrement());
for (String cacheName : cacheNames) client.cache(cacheName);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 10; i++) {
for (String cacheName : cacheNames) {
IgniteCache<Object, Object> cache = client.cache(cacheName);
Map<Object, Object> map0 = cache.getAll(keys);
assertEquals(KEYS, map0.size());
cache.put(rnd.nextInt(KEYS), i);
}
}
return null;
}
}, clients.size(), "client-cache-start");
final AtomicInteger srvIdx = new AtomicInteger(SRVS1 + CLIENTS);
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
startGrid(srvIdx.incrementAndGet());
return null;
}
}, SRVS2, "node-start");
fut1.get();
fut2.get();
final AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS1 + SRVS2 + CLIENTS, 1);
for (Ignite client : clients) {
for (String cacheName : cacheNames) {
final GridDhtPartitionTopology top = ((IgniteKernal) client).context().cache().internalCache(cacheName).context().topology();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return top.rebalanceFinished(topVer);
}
}, 5000);
assertTrue(top.rebalanceFinished(topVer));
}
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridCacheAbstractFullApiSelfTest method testPeekExpiredTx.
/**
* TODO GG-11133.
*
* @throws Exception If failed.
*/
public void testPeekExpiredTx() throws Exception {
if (txShouldBeUsed()) {
final IgniteCache<String, Integer> c = jcache();
final String key = "1";
int ttl = 500;
try (Transaction tx = grid(0).transactions().txStart()) {
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry).put(key, 1);
tx.commit();
}
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return peek(c, key) == null;
}
}, 2000);
assertNull(peek(c, key));
assert c.localSize() == 0;
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method testPeekExpired.
/**
* JUnit.
*
* @throws Exception If failed.
*/
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