use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridSessionWaitAttributeSelfTest method checkWaitAttributeMethod.
/**
* @param type Type.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void checkWaitAttributeMethod(WaitAttributeType type) throws Exception {
assert type != null;
Ignite ignite1 = G.ignite(getTestIgniteInstanceName() + '1');
Ignite ignite2 = G.ignite(getTestIgniteInstanceName() + '2');
assert ignite1 != null;
assert ignite2 != null;
ignite1.compute().localDeployTask(TestSessionTask.class, TestSessionTask.class.getClassLoader());
ComputeTaskFuture<?> fut = ignite1.compute().executeAsync(TestSessionTask.class.getName(), type);
fut.getTaskSession().mapFuture().get();
ComputeTaskSession ses = fut.getTaskSession();
info("Task job siblings [size=" + ses.getJobSiblings().size() + ", siblings=" + ses.getJobSiblings() + ']');
for (int i = 0; i < ATTR_NUM; i++) {
String key = createKey("fut", type, i);
String val = createValue("fut", type, i);
ses.setAttribute(key, val);
}
// Check all job attributes.
for (ComputeJobSibling sibling : ses.getJobSiblings()) {
info("Checking session attributes for sibling: " + sibling);
checkSessionAttributes(ses, sibling.getJobId().toString(), type);
}
// Check that fut attributes have been set.
checkSessionAttributes(ses, "fut", type);
// Signal finish.
ses.setAttribute("done", true);
fut.get();
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiMultipleNodesSelfTest method testMultipleTasks.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings({ "ObjectEquality" })
public void testMultipleTasks() throws Exception {
ComputeTaskSession ses1 = new GridTestTaskSession(IgniteUuid.randomUuid());
ComputeTaskSession ses2 = new GridTestTaskSession(IgniteUuid.randomUuid());
List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
// Initialize.
getSpi().getBalancedNode(ses1, allNodes, new GridTestJob());
getSpi().getBalancedNode(ses2, allNodes, new GridTestJob());
List<UUID> orderedNodes1 = getSpi().getNodeIds(ses1);
List<UUID> orderedNodes2 = getSpi().getNodeIds(ses2);
assert orderedNodes1 != orderedNodes2;
// Check the round-robin actually did circle.
for (int i = 0; i < allNodes.size(); i++) {
ClusterNode node1 = getSpi().getBalancedNode(ses1, allNodes, new GridTestJob());
assert orderedNodes1.get(i) == node1.id();
ClusterNode node2 = getSpi().getBalancedNode(ses2, allNodes, new GridTestJob());
assert orderedNodes2.get(i) == node2.id();
assert orderedNodes1.get(i) == orderedNodes2.get(i);
}
// Double-check.
for (int i = 0; i < allNodes.size(); i++) {
ClusterNode node1 = getSpi().getBalancedNode(ses1, allNodes, new GridTestJob());
assert orderedNodes1.get(i) == node1.id();
ClusterNode node2 = getSpi().getBalancedNode(ses2, allNodes, new GridTestJob());
assert orderedNodes2.get(i) == node2.id();
assert orderedNodes1.get(i) == orderedNodes2.get(i);
}
getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FINISHED, ses1.getId(), null, null, false, null));
getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FAILED, ses2.getId(), null, null, false, null));
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridAdaptiveLoadBalancingSpiSelfTest method testSingleNodeZeroWeight.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "ObjectEquality" })
public void testSingleNodeZeroWeight() throws Exception {
GridTestNode node = (GridTestNode) getSpiContext().nodes().iterator().next();
node.addAttribute("load", 0d);
List<ClusterNode> nodes = Collections.singletonList((ClusterNode) node);
ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
GridTestNode pick1 = (GridTestNode) getSpi().getBalancedNode(ses, nodes, new GridTestJob());
pick1.setAttribute("used", true);
assert nodes.contains(pick1);
// Verify that same instance is returned every time.
ClusterNode pick2 = getSpi().getBalancedNode(ses, nodes, new GridTestJob());
assert pick1 == pick2;
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridAdaptiveLoadBalancingSpiSelfTest method testSingleNodeSameSession.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "ObjectEquality" })
public void testSingleNodeSameSession() throws Exception {
GridTestNode node = (GridTestNode) getSpiContext().nodes().iterator().next();
node.addAttribute("load", 1d);
List<ClusterNode> nodes = Collections.singletonList((ClusterNode) node);
ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
GridTestNode pick1 = (GridTestNode) getSpi().getBalancedNode(ses, nodes, new GridTestJob());
pick1.setAttribute("used", true);
assert nodes.contains(pick1);
// Verify that same instance is returned every time.
ClusterNode pick2 = getSpi().getBalancedNode(ses, nodes, new GridTestJob());
assert pick1 == pick2;
}
use of org.apache.ignite.compute.ComputeTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testBalancingOneNode.
/**
* @throws Exception If test failed.
*/
public void testBalancingOneNode() throws Exception {
ComputeTaskSession ses = new GridTestTaskSession();
List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
List<ClusterNode> balancedNode = Arrays.asList(allNodes.get(0));
ClusterNode firstNode = getSpi().getBalancedNode(ses, balancedNode, new GridTestJob());
ClusterNode secondNode = getSpi().getBalancedNode(ses, balancedNode, new GridTestJob());
assertEquals(firstNode, secondNode);
}
Aggregations