use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridCacheSetAbstractSelfTest method testAffinityRun.
/**
* @throws Exception If failed.
*/
public void testAffinityRun() throws Exception {
final CollectionConfiguration colCfg = collectionConfiguration();
colCfg.setCollocated(false);
colCfg.setCacheMode(CacheMode.PARTITIONED);
colCfg.setGroupName("testGroup");
try (final IgniteSet<Integer> set1 = grid(0).set("Set1", colCfg)) {
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
set1.affinityRun(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
return null;
}
}, IgniteException.class, "Failed to execute affinityRun() for non-collocated set: " + set1.name() + ". This operation is supported only for collocated sets.");
}
colCfg.setCollocated(true);
try (final IgniteSet<Integer> set2 = grid(0).set("Set2", colCfg)) {
set2.add(100);
final String cacheName = cctx(set2).name();
set2.affinityRun(new IgniteRunnable() {
@IgniteInstanceResource
private IgniteEx ignite;
@Override
public void run() {
assertTrue(ignite.cachex(cacheName).affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Set2"));
assertEquals(100, set2.iterator().next().intValue());
}
});
}
}
use of org.apache.ignite.lang.IgniteRunnable 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.lang.IgniteRunnable in project ignite by apache.
the class GridFactorySelfTest method testCurrentIgnite.
/**
* @throws Exception If failed.
*/
public void testCurrentIgnite() throws Exception {
final String LEFT = "LEFT";
final String RIGHT = "RIGHT";
try {
Ignite iLEFT = startGrid(LEFT);
Ignite iRIGHT = startGrid(RIGHT);
waitForDiscovery(iLEFT, iRIGHT);
iLEFT.compute(iLEFT.cluster().forRemotes()).run(new IgniteRunnable() {
@Override
public void run() {
assert Ignition.localIgnite().name().equals(RIGHT);
}
});
iRIGHT.compute(iRIGHT.cluster().forRemotes()).run(new IgniteRunnable() {
@Override
public void run() {
assert Ignition.localIgnite().name().equals(LEFT);
}
});
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.lang.IgniteRunnable 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();
}
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class TcpCommunicationSpiDropNodesTest method testOneNode.
/**
* @throws Exception If failed.
*/
public void testOneNode() throws Exception {
pred = new IgniteBiPredicate<ClusterNode, ClusterNode>() {
@Override
public boolean apply(ClusterNode locNode, ClusterNode rmtNode) {
return block && rmtNode.order() == 3;
}
};
startGrids(NODES_CNT);
final CountDownLatch latch = new CountDownLatch(1);
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
latch.countDown();
return true;
}
}, EVT_NODE_FAILED);
// Wait for write timeout and closing idle connections.
U.sleep(1000);
block = true;
grid(0).compute().broadcast(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
assertTrue(latch.await(15, TimeUnit.SECONDS));
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return grid(3).cluster().topologyVersion() == NODES_CNT + 1;
}
}, 5000));
for (int i = 0; i < 10; i++) {
U.sleep(1000);
assertEquals(NODES_CNT - 1, grid(0).cluster().nodes().size());
int liveNodesCnt = 0;
for (int j = 0; j < NODES_CNT; j++) {
IgniteEx ignite;
try {
ignite = grid(j);
log.info("Checking topology for grid(" + j + "): " + ignite.cluster().nodes());
ClusterNode locNode = ignite.localNode();
if (locNode.order() != 3) {
assertEquals(NODES_CNT - 1, ignite.cluster().nodes().size());
for (ClusterNode node : ignite.cluster().nodes()) assertTrue(node.order() != 3);
liveNodesCnt++;
}
} catch (Exception e) {
log.info("Checking topology for grid(" + j + "): no grid in topology.");
}
}
assertEquals(NODES_CNT - 1, liveNodesCnt);
}
}
Aggregations