use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClosureProcessorSelfTest method runAsync.
/**
* @param idx Node index.
* @param jobs Runnable jobs.
* @param p Optional node predicate.
* @return Future object.
*/
private IgniteFuture<?> runAsync(int idx, Collection<ClosureTestRunnable> jobs, @Nullable IgnitePredicate<ClusterNode> p) {
assert idx >= 0 && idx < NODES_CNT;
assert !F.isEmpty(jobs);
execCntr.set(0);
IgniteCompute comp = p != null ? compute(grid(idx).cluster().forPredicate(p)) : grid(idx).compute();
return comp.runAsync(jobs);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClosureProcessorSelfTest method runAsync.
/**
* @param idx Node index.
* @param job Runnable job.
* @param p Optional node predicate.
* @return Future object.
*/
private IgniteFuture<?> runAsync(int idx, IgniteRunnable job, @Nullable IgnitePredicate<ClusterNode> p) {
assert idx >= 0 && idx < NODES_CNT;
assert job != null;
execCntr.set(0);
IgniteCompute comp = p != null ? compute(grid(idx).cluster().forPredicate(p)) : grid(idx).compute();
return comp.runAsync(job);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class IgniteComputeCustomExecutorSelfTest method testAllComputeApiByCustomExecutor.
/**
* @throws Exception If fails.
*/
public void testAllComputeApiByCustomExecutor() throws Exception {
IgniteCompute comp = grid(0).compute().withExecutor(EXEC_NAME0);
comp.affinityRun(CACHE_NAME, primaryKey(grid(1).cache(CACHE_NAME)), new IgniteRunnable() {
@Override
public void run() {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
}
});
comp.affinityCall(CACHE_NAME, 0, new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
});
comp.broadcast(new IgniteRunnable() {
@Override
public void run() {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
}
});
comp.broadcast(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
});
comp.broadcast(new IgniteClosure<Object, Object>() {
@Override
public Object apply(Object o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, 0);
comp.apply(new IgniteClosure<Object, Object>() {
@Override
public Object apply(Object o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, 0);
comp.apply(new IgniteClosure<Integer, Object>() {
@Override
public Object apply(Integer o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, Collections.singletonList(0));
comp.apply(new IgniteClosure<Integer, Object>() {
@Override
public Object apply(Integer o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, Collections.singletonList(0), new IgniteReducer<Object, Object>() {
@Override
public boolean collect(@Nullable Object o) {
return true;
}
@Override
public Object reduce() {
return null;
}
});
List<IgniteCallable<Object>> calls = new ArrayList<>();
for (int i = 0; i < GRID_CNT * 2; ++i) {
calls.add(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
});
}
comp.call(calls.get(0));
comp.call(calls);
comp.call(calls, new IgniteReducer<Object, Object>() {
@Override
public boolean collect(@Nullable Object o) {
return true;
}
@Override
public Object reduce() {
return null;
}
});
List<IgniteRunnable> runs = new ArrayList<>();
for (int i = 0; i < GRID_CNT * 2; ++i) {
runs.add(new IgniteRunnable() {
@Override
public void run() {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
}
});
}
comp.run(runs.get(0));
comp.run(runs);
comp.execute(TestTask.class, null);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class IgniteCacheRandomOperationBenchmark method doScanQuery.
/**
* @param cache Ignite cache.
* @throws Exception If failed.
*/
private void doScanQuery(IgniteCache<Object, Object> cache) throws Exception {
if (!affCaches.contains(cache))
return;
Map<UUID, List<Integer>> partitionsMap = personCachePartitions(cache.getName());
ScanQueryBroadcastClosure c = new ScanQueryBroadcastClosure(cache.getName(), partitionsMap);
ClusterGroup clusterGrp = ignite().cluster().forNodeIds(partitionsMap.keySet());
IgniteCompute compute = ignite().compute(clusterGrp);
compute.broadcast(c);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridMarshallerAbstractTest method testCompute.
/**
* @throws Exception If failed.
*/
public void testCompute() throws Exception {
IgniteConfiguration cfg = optimize(getConfiguration("g1"));
try (Ignite g1 = G.start(cfg)) {
IgniteCompute compute = compute(grid().cluster().forNode(g1.cluster().localNode()));
compute.run(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
GridMarshallerTestBean inBean = newTestBean(compute);
byte[] buf = marshal(inBean);
GridMarshallerTestBean outBean = unmarshal(buf);
assert inBean.getObjectField() != null;
assert outBean.getObjectField() != null;
assert inBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
assert outBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
assert inBean != outBean;
assert inBean.equals(outBean);
ClusterGroup inPrj = compute.clusterGroup();
ClusterGroup outPrj = ((IgniteCompute) outBean.getObjectField()).clusterGroup();
assert inPrj.getClass().equals(outPrj.getClass());
assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
outBean.checkNullResources();
}
}
Aggregations