use of org.apache.ignite.GridTestTaskSession in project ignite by apache.
the class GridWeightedRandomLoadBalancingSpiSelfTest method testSingleNode.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "ObjectEquality" })
public void testSingleNode() throws Exception {
List<ClusterNode> nodes = Collections.singletonList((ClusterNode) new GridTestNode(UUID.randomUUID()));
ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(), nodes, new GridTestJob());
assert nodes.contains(node);
// Verify that same instance is returned every time.
ClusterNode balancedNode = getSpi().getBalancedNode(new GridTestTaskSession(), nodes, new GridTestJob());
assert node == balancedNode;
}
use of org.apache.ignite.GridTestTaskSession in project ignite by apache.
the class GridWeightedRandomLoadBalancingSpiWeightedSelfTest method testWeights.
/**
* @throws Exception If test failed.
*/
public void testWeights() throws Exception {
List<ClusterNode> nodes = new ArrayList<>();
for (int i = 0; i < 10; i++) {
GridTestNode node = new GridTestNode(UUID.randomUUID());
node.addAttribute(U.spiAttribute(getSpi(), NODE_WEIGHT_ATTR_NAME), i + 1);
nodes.add(node);
}
// Seal it.
nodes = Collections.unmodifiableList(nodes);
int[] cnts = new int[10];
// Invoke load balancer a large number of times, so statistics won't lie.
for (int i = 0; i < 100000; i++) {
ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob());
int weight = (Integer) node.attribute(U.spiAttribute(getSpi(), NODE_WEIGHT_ATTR_NAME));
// Increment number of times a node was picked.
cnts[weight - 1]++;
}
for (int i = 0; i < cnts.length - 1; i++) {
assert cnts[i] < cnts[i + 1] : "Invalid node counts for index [idx=" + i + ", cnts[i]=" + cnts[i] + ", cnts[i+1]=" + cnts[i + 1] + ']';
}
info("Node counts: " + Arrays.toString(cnts));
}
use of org.apache.ignite.GridTestTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiMultipleNodesSelfTest method testMultipleNodes.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings({ "ObjectEquality" })
public void testMultipleNodes() throws Exception {
List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
// Initialize.
getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
List<UUID> orderedNodes = new ArrayList<>(getSpi().getNodeIds(ses));
// Check the round-robin actually did circle.
for (int i = 0; i < allNodes.size(); i++) {
ClusterNode node = getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
assert orderedNodes.get(i) == node.id();
}
// Double-check.
for (int i = 0; i < allNodes.size(); i++) {
ClusterNode node = getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
assert orderedNodes.get(i) == node.id();
}
}
use of org.apache.ignite.GridTestTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testMultipleTaskSessions.
/**
* @throws Exception If test failed.
*/
public void testMultipleTaskSessions() throws Exception {
ComputeTaskSession ses1 = new GridTestTaskSession(IgniteUuid.randomUuid());
ComputeTaskSession ses2 = new GridTestTaskSession(IgniteUuid.randomUuid());
List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
List<UUID> orderedNodes = getSpi().getNodeIds(ses1);
assertEquals("Balancer doesn't use all available nodes", orderedNodes.size(), allNodes.size());
checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses1, ses2);
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.GridTestTaskSession in project ignite by apache.
the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testMultipleNodes.
/**
* @throws Exception If test failed.
*/
public void testMultipleNodes() throws Exception {
List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
ComputeTaskSession ses = new GridTestTaskSession();
List<UUID> orderedNodes = new ArrayList<>(getSpi().getNodeIds(ses));
assertEquals("Balancer doesn't use all available nodes", orderedNodes.size(), allNodes.size());
checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
}
Aggregations