use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheContinuousQueryConcurrentPartitionUpdateTest method concurrentUpdatePartition.
/**
* @param atomicityMode Cache atomicity mode.
* @throws Exception If failed.
*/
private void concurrentUpdatePartition(CacheAtomicityMode atomicityMode) throws Exception {
Ignite srv = startGrid(0);
client = true;
Ignite client = startGrid(1);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setAtomicityMode(atomicityMode);
IgniteCache clientCache = client.createCache(ccfg);
final AtomicInteger evtCnt = new AtomicInteger();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
for (CacheEntryEvent evt : evts) {
assertNotNull(evt.getKey());
assertNotNull(evt.getValue());
evtCnt.incrementAndGet();
}
}
});
clientCache.query(qry);
Affinity<Integer> aff = srv.affinity(DEFAULT_CACHE_NAME);
final List<Integer> keys = new ArrayList<>();
final int KEYS = 10;
for (int i = 0; i < 100_000; i++) {
if (aff.partition(i) == 0) {
keys.add(i);
if (keys.size() == KEYS)
break;
}
}
assertEquals(KEYS, keys.size());
final int THREADS = 10;
final int UPDATES = 1000;
final IgniteCache<Object, Object> srvCache = srv.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 15; i++) {
log.info("Iteration: " + i);
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < UPDATES; i++) srvCache.put(keys.get(rnd.nextInt(KEYS)), i);
return null;
}
}, THREADS, "update");
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
log.info("Events: " + evtCnt.get());
return evtCnt.get() >= THREADS * UPDATES;
}
}, 5000);
assertEquals(THREADS * UPDATES, evtCnt.get());
evtCnt.set(0);
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridCancelledJobsMetricsSelfTest method testCancelledJobs.
/**
* @throws Exception If failed.
*/
public void testCancelledJobs() throws Exception {
final Ignite ignite = G.ignite(getTestIgniteInstanceName());
Collection<ComputeTaskFuture<?>> futs = new ArrayList<>();
for (int i = 1; i <= 10; i++) futs.add(ignite.compute().executeAsync(CancelledTask.class, null));
// Wait to be sure that metrics were updated.
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite.cluster().localNode().metrics().getTotalCancelledJobs() > 0;
}
}, 5000);
colSpi.externalCollision();
for (ComputeTaskFuture<?> fut : futs) {
try {
fut.get();
assert false : "Job was not interrupted.";
} catch (IgniteException e) {
if (e.hasCause(InterruptedException.class))
throw new IgniteCheckedException("Test run has been interrupted.", e);
info("Caught expected exception: " + e.getMessage());
}
}
// Job was cancelled and now we need to calculate metrics.
int totalCancelledJobs = ignite.cluster().localNode().metrics().getTotalCancelledJobs();
assert totalCancelledJobs == 10 : "Metrics were not updated. Expected 10 got " + totalCancelledJobs;
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridEventStorageCheckAllEventsSelfTest method startTimestamp.
/**
* Returns timestamp at the method call moment, but sleeps before return,
* to allow pass {@link IgniteUtils#currentTimeMillis()}.
*
* @return Call timestamp.
* @throws Exception If failed.
*/
private long startTimestamp() throws Exception {
final long tstamp = U.currentTimeMillis();
Thread.sleep(20);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return U.currentTimeMillis() > tstamp;
}
}, 5000);
assert U.currentTimeMillis() > tstamp;
return U.currentTimeMillis();
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridProjectionForCachesSelfTest method testProjectionForDefaultCache.
/**
* @throws Exception If failed.
*/
public void testProjectionForDefaultCache() throws Exception {
final ClusterGroup prj = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
assertNotNull(prj);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return prj.nodes().size() == 3;
}
}, 5000);
assertEquals(3, prj.nodes().size());
assertTrue(prj.nodes().contains(grid(0).localNode()));
assertFalse(prj.nodes().contains(grid(1).localNode()));
assertTrue(prj.nodes().contains(grid(2).localNode()));
assertTrue(prj.nodes().contains(grid(3).localNode()));
assertFalse(prj.nodes().contains(grid(4).localNode()));
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteClientReconnectStreamerTest method testStreamerReconnect.
/**
* @throws Exception If failed.
*/
public void testStreamerReconnect() throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
final IgniteCache<Object, Object> srvCache = srv.cache(CACHE_NAME);
IgniteDataStreamer<Integer, Integer> streamer = client.dataStreamer(CACHE_NAME);
for (int i = 0; i < 50; i++) streamer.addData(i, i);
streamer.flush();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return srvCache.localSize() == 50;
}
}, 2000L);
assertEquals(50, srvCache.localSize());
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
try {
client.dataStreamer(CACHE_NAME);
fail();
} catch (IgniteClientDisconnectedException e) {
assertNotNull(e.reconnectFuture());
}
}
});
checkStreamerClosed(streamer);
streamer = client.dataStreamer(CACHE_NAME);
for (int i = 50; i < 100; i++) streamer.addData(i, i);
streamer.flush();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return srvCache.localSize() == 100;
}
}, 2000L);
assertEquals(100, srvCache.localSize());
streamer.close();
streamer.future().get(2, TimeUnit.SECONDS);
srvCache.removeAll();
}
Aggregations