Search in sources :

Example 11 with GridTestJob

use of org.apache.ignite.GridTestJob in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiLocalNodeSelfTest method testLocalNode.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "ObjectEquality" })
public void testLocalNode() throws Exception {
    assert getDiscoverySpi().getRemoteNodes().isEmpty();
    ClusterNode locNode = getDiscoverySpi().getLocalNode();
    ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), Collections.singletonList(locNode), new GridTestJob());
    assert node == locNode;
    // Double check.
    node = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), Collections.singletonList(locNode), new GridTestJob());
    assert node == locNode;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) GridTestJob(org.apache.ignite.GridTestJob)

Example 12 with GridTestJob

use of org.apache.ignite.GridTestJob 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"));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) IgniteException(org.apache.ignite.IgniteException) GridTestJob(org.apache.ignite.GridTestJob) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 13 with GridTestJob

use of org.apache.ignite.GridTestJob in project ignite by apache.

the class GridAdaptiveLoadBalancingSpiMultipleNodeSelfTest method testWeights.

/**
     * @throws Exception If failed.
     */
public void testWeights() throws Exception {
    // Seal it.
    List<ClusterNode> nodes = new ArrayList<>(getSpiContext().remoteNodes());
    int[] cnts = new int[RMT_NODE_CNT];
    // Invoke load balancer a large number of times, so statistics won't lie.
    for (int i = 0; i < 50000; i++) {
        GridTestNode node = (GridTestNode) getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob());
        int idx = ((Double) node.attribute("load")).intValue() - 1;
        if (cnts[idx] == 0)
            node.setAttribute("used", true);
        // Increment number of times a node was picked.
        cnts[idx]++;
    }
    info("Node counts: " + Arrays.toString(cnts));
    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] + ']';
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) GridTestJob(org.apache.ignite.GridTestJob) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 14 with GridTestJob

use of org.apache.ignite.GridTestJob in project ignite by apache.

the class GridAdaptiveLoadBalancingSpiSelfTest method testSingleNodeDifferentSession.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "ObjectEquality" })
public void testSingleNodeDifferentSession() throws Exception {
    GridTestNode node = (GridTestNode) getSpiContext().nodes().iterator().next();
    node.addAttribute("load", 2d);
    List<ClusterNode> nodes = Collections.singletonList((ClusterNode) node);
    GridTestNode pick1 = (GridTestNode) getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob());
    pick1.setAttribute("used", true);
    assert nodes.contains(pick1);
    // Verify that same instance is returned every time.
    ClusterNode pick2 = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob());
    assert pick1 == pick2;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) GridTestJob(org.apache.ignite.GridTestJob) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 15 with GridTestJob

use of org.apache.ignite.GridTestJob 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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) List(java.util.List) UUID(java.util.UUID) GridTestJob(org.apache.ignite.GridTestJob) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Aggregations

GridTestJob (org.apache.ignite.GridTestJob)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)14 GridTestNode (org.apache.ignite.testframework.GridTestNode)9 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)8 ArrayList (java.util.ArrayList)6 List (java.util.List)5 UUID (java.util.UUID)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteException (org.apache.ignite.IgniteException)1 TaskEvent (org.apache.ignite.events.TaskEvent)1