Search in sources :

Example 36 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode 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 37 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridAdaptiveLoadBalancingSpiSelfTest method initSpiContext.

/**
 * {@inheritDoc}
 */
@Override
protected GridSpiTestContext initSpiContext() throws Exception {
    GridSpiTestContext ctx = super.initSpiContext();
    ctx.setLocalNode(new GridTestNode(UUID.randomUUID()));
    return ctx;
}
Also used : GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 38 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode 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 39 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode 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)

Example 40 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridWeightedRandomLoadBalancingSpiSelfTest method testMultipleNodes.

/**
 * @throws Exception If failed.
 */
public void testMultipleNodes() throws Exception {
    List<ClusterNode> nodes = new ArrayList<>();
    for (int i = 0; i < 10; i++) nodes.add(new GridTestNode(UUID.randomUUID()));
    // Seal it.
    nodes = Collections.unmodifiableList(nodes);
    ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(), nodes, new GridTestJob());
    assert node != null;
    assert nodes.contains(node);
}
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)

Aggregations

GridTestNode (org.apache.ignite.testframework.GridTestNode)43 ClusterNode (org.apache.ignite.cluster.ClusterNode)27 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)17 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)14 ArrayList (java.util.ArrayList)11 GridTestJob (org.apache.ignite.GridTestJob)9 HashMap (java.util.HashMap)7 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)7 GridTimeoutProcessor (org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 Map (java.util.Map)5 GridTestJobResult (org.apache.ignite.GridTestJobResult)5 GridFailoverTestContext (org.apache.ignite.spi.failover.GridFailoverTestContext)5 Serializable (java.io.Serializable)4 List (java.util.List)4 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)4 ClusterMetricsSnapshot (org.apache.ignite.internal.ClusterMetricsSnapshot)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)3