Search in sources :

Example 1 with GridTestTaskSession

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

Example 2 with GridTestTaskSession

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

Example 3 with GridTestTaskSession

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

Example 4 with GridTestTaskSession

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

the class GridJobStealingFailoverSpiSelfTest method testMaxHopsExceededThiefNotSet.

/**
     * @throws Exception If test failed.
     */
public void testMaxHopsExceededThiefNotSet() throws Exception {
    ClusterNode rmt = getSpiContext().remoteNodes().iterator().next();
    GridTestJobResult failed = new GridTestJobResult(rmt);
    failed.getJobContext().setAttribute(FAILOVER_ATTEMPT_COUNT_ATTR, getSpi().getMaximumFailoverAttempts());
    ClusterNode other = getSpi().failover(new GridFailoverTestContext(new GridTestTaskSession(), failed), new ArrayList<>(getSpiContext().nodes()));
    assert other == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext)

Example 5 with GridTestTaskSession

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

the class GridJobStealingFailoverSpiSelfTest method testThiefEqualsVictim.

/**
     * @throws Exception If test failed.
     */
public void testThiefEqualsVictim() throws Exception {
    ClusterNode rmt = getSpiContext().remoteNodes().iterator().next();
    GridTestJobResult failed = new GridTestJobResult(rmt);
    failed.getJobContext().setAttribute(THIEF_NODE_ATTR, rmt.id());
    ClusterNode other = getSpi().failover(new GridFailoverTestContext(new GridTestTaskSession(), failed), new ArrayList<>(getSpiContext().nodes()));
    assert other != null;
    assert other != rmt;
    assert other.equals(getSpiContext().localNode());
    checkAttributes(failed.getJobContext(), rmt, 1);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext)

Aggregations

GridTestTaskSession (org.apache.ignite.GridTestTaskSession)29 ClusterNode (org.apache.ignite.cluster.ClusterNode)29 GridTestJob (org.apache.ignite.GridTestJob)14 GridTestNode (org.apache.ignite.testframework.GridTestNode)14 GridTestJobResult (org.apache.ignite.GridTestJobResult)13 GridFailoverTestContext (org.apache.ignite.spi.failover.GridFailoverTestContext)13 ArrayList (java.util.ArrayList)12 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)10 List (java.util.List)7 UUID (java.util.UUID)5 ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)2 TaskEvent (org.apache.ignite.events.TaskEvent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteException (org.apache.ignite.IgniteException)1