use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingNotPerTaskMultithreadedSelfTest method testMultipleTaskSessionsMultithreaded.
/**
*
* @throws Exception If failed.
*/
public void testMultipleTaskSessionsMultithreaded() throws Exception {
final RoundRobinLoadBalancingSpi spi = getSpi();
final List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
Map<UUID, AtomicInteger> nodeCnts = new HashMap<>();
for (int i = 1; i <= ITER_CNT; i++) {
ClusterNode node = spi.getBalancedNode(ses, allNodes, new GridTestJob());
if (!nodeCnts.containsKey(node.id()))
nodeCnts.put(node.id(), new AtomicInteger(1));
else
nodeCnts.get(node.id()).incrementAndGet();
}
int predictCnt = ITER_CNT / allNodes.size();
// Consider +-20% is permissible spread for single node measure.
int floor = (int) (predictCnt * 0.8);
double avgSpread = 0;
for (ClusterNode n : allNodes) {
int curCnt = nodeCnts.get(n.id()).intValue();
avgSpread += Math.abs(predictCnt - curCnt);
String msg = "Node stats [id=" + n.id() + ", cnt=" + curCnt + ", floor=" + floor + ", predictCnt=" + predictCnt + ']';
info(msg);
assertTrue(msg, curCnt >= floor);
}
avgSpread /= allNodes.size();
avgSpread = 100.0 * avgSpread / predictCnt;
info("Average spread for " + allNodes.size() + " nodes is " + avgSpread + " percents");
// Consider +-10% is permissible average spread for all nodes.
assertTrue("Average spread is too big: " + avgSpread, avgSpread <= 10);
return null;
}
}, THREAD_CNT, "balancer-test-worker");
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testNodeNotInTopology.
/** */
public void testNodeNotInTopology() throws Exception {
ComputeTaskSession ses = new GridTestTaskSession();
ClusterNode node = new GridTestNode(UUID.randomUUID());
List<ClusterNode> notInTop = Arrays.asList(node);
try {
getSpi().getBalancedNode(ses, notInTop, new GridTestJob());
} catch (IgniteException e) {
assertTrue(e.getMessage().contains("Task topology does not have alive nodes"));
}
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiTopologyChangeSelfTest method testTopologyChange.
/**
* @throws Exception If failed.
*/
public void testTopologyChange() throws Exception {
ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
// Warm up.
List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
List<UUID> orderedNodes = getSpi().getNodeIds(ses);
checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
// Remove node.
UUID doomed = orderedNodes.get(0);
if (getSpiContext().localNode().id().equals(doomed))
doomed = orderedNodes.get(1);
getSpiContext().removeNode(doomed);
assertTrue(allNodes.remove(new GridTestNode(doomed)));
orderedNodes = getSpi().getNodeIds(ses);
assertFalse("Balancer uses removed node", orderedNodes.contains(doomed));
checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
// Add node.
ClusterNode newNode = new GridTestNode(UUID.randomUUID());
getSpiContext().addNode(newNode);
assertTrue(allNodes.add(newNode));
// Check that new node was added to balancing.
boolean foundNewNode = false;
for (int i = 0; i < allNodes.size(); i++) {
ClusterNode node = getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
if (newNode.id().equals(node.id())) {
foundNewNode = true;
break;
}
}
assertTrue("Balancer doesn't use added node", foundNewNode);
orderedNodes = getSpi().getNodeIds(ses);
checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridTaskExecutionContextSelfTest method testWithName.
/**
* @throws Exception If failed.
*/
public void testWithName() throws Exception {
IgniteCallable<String> f = new IgniteCallable<String>() {
@TaskSessionResource
private ComputeTaskSession ses;
@Override
public String call() {
return ses.getTaskName();
}
};
Ignite g = grid(0);
assert "name1".equals(g.compute().withName("name1").call(f));
assert "name2".equals(g.compute().withName("name2").call(f));
assert f.getClass().getName().equals(g.compute().call(f));
assert "name1".equals(g.compute().withName("name1").execute(new TestTask(false), null));
assert "name2".equals(g.compute().withName("name2").execute(new TestTask(false), null));
assert TestTask.class.getName().equals(g.compute().execute(new TestTask(false), null));
}
Aggregations