use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridClosureProcessorSelfTest method testRunAsyncSingle.
/**
* @throws Exception If failed.
*/
public void testRunAsyncSingle() throws Exception {
IgniteRunnable job = new ClosureTestRunnable();
IgniteFuture<?> fut = broadcast(0, job, null);
assert fut.get() == null;
assertEquals(NODES_CNT, execCntr.getAndSet(0));
fut = broadcast(0, job, singleNodePredicate(0));
assert fut.get() == null;
assertEquals(1, execCntr.get());
fut = runAsync(0, job, null);
assert fut.get() == null : "Execution result must be null.";
assert execCntr.get() == 1 : "Execution counter must be equal to 1, actual: " + execCntr.get();
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class OptimizedMarshallerSelfTest method testTestMarshalling.
/**
* @throws Exception If failed.
*/
public void testTestMarshalling() throws Exception {
final String msg = "PASSED";
byte[] buf = marshal(new IgniteRunnable() {
@Override
public void run() {
c1.apply(msg);
c2.apply(msg);
c3.apply();
c4.reduce();
System.out.println("Test message: " + msg);
}
});
Runnable r = unmarshal(buf);
assertNotNull(r);
r.run();
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridComputeJobExecutionErrorToLogManualTest method testRuntimeException.
/**
* @throws Exception If fails.
*/
public void testRuntimeException() throws Exception {
Ignite ignite = grid(0);
ignite.compute().runAsync(new IgniteRunnable() {
@Override
public void run() {
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {
// No-op.
}
}
}).listen(new IgniteInClosure<IgniteFuture<Void>>() {
@Override
public void apply(IgniteFuture<Void> future) {
throw new RuntimeException();
}
});
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridTestMain method colocateJobs.
/**
* @throws Exception If failed.
*/
private static void colocateJobs() throws Exception {
X.println("Collocating jobs...");
Ignite g = G.ignite();
final IgniteCache<GridTestKey, Long> cache = g.cache("partitioned");
final BlockingQueue<IgniteFuture> q = new ArrayBlockingQueue<>(400);
long start = System.currentTimeMillis();
// Collocate computations and data.
for (long i = 0; i < GridTestConstants.ENTRY_COUNT; i++) {
final long key = i;
final IgniteFuture<?> f = g.compute().affinityRunAsync("partitioned", GridTestKey.affinityKey(key), new IgniteRunnable() {
// This code will execute on remote nodes by collocating keys with cached data.
@Override
public void run() {
Long val = cache.localPeek(new GridTestKey(key), CachePeekMode.ONHEAP);
if (val == null || val != key)
throw new RuntimeException("Invalid value found [key=" + key + ", val=" + val + ']');
}
});
q.put(f);
f.listen(new CI1<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> o) {
q.poll();
}
});
if (i % 10000 == 0)
X.println("Executed jobs: " + i);
}
long end = System.currentTimeMillis();
X.println("Executed " + GridTestConstants.ENTRY_COUNT + " computations in " + (end - start) + "ms.");
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class IgniteDynamicCacheStartStopConcurrentTest method testConcurrentStartStop.
/**
* @throws Exception If failed.
*/
public void testConcurrentStartStop() throws Exception {
awaitPartitionMapExchange();
int minorVer = ignite(0).configuration().isLateAffinityAssignment() ? 1 : 0;
checkTopologyVersion(new AffinityTopologyVersion(NODES, minorVer));
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
@Override
public void apply(Integer idx) {
Ignite ignite = ignite(idx);
ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
}
}, NODES, "cache-thread");
minorVer++;
checkTopologyVersion(new AffinityTopologyVersion(NODES, minorVer));
ignite(0).compute().affinityRun(DEFAULT_CACHE_NAME, 1, new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
@Override
public void apply(Integer idx) {
Ignite ignite = ignite(idx);
ignite.destroyCache(DEFAULT_CACHE_NAME);
}
}, NODES, "cache-thread");
minorVer++;
checkTopologyVersion(new AffinityTopologyVersion(NODES, minorVer));
}
}
Aggregations