Search in sources :

Example 16 with GridTestNode

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

the class GridAlwaysFailoverSpiSelfTest method testMaxAttempts.

/**
     * @throws Exception If failed.
     */
public void testMaxAttempts() throws Exception {
    AlwaysFailoverSpi spi = getSpi();
    spi.setMaximumFailoverAttempts(1);
    List<ClusterNode> nodes = new ArrayList<>();
    nodes.add(new GridTestNode(UUID.randomUUID()));
    nodes.add(new GridTestNode(UUID.randomUUID()));
    ComputeJobResult jobRes = new GridTestJobResult(nodes.get(0));
    // First attempt.
    ClusterNode node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
    assert node != null;
    assert node.equals(nodes.get(1));
    checkFailedNodes(jobRes, 1);
    // Second attempt (exceeds default max attempts of 1).
    node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
    assert node == null;
    checkFailedNodes(jobRes, 1);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult)

Example 17 with GridTestNode

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

the class GridJobStealingFailoverSpiOneNodeSelfTest method initSpiContext.

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

Example 18 with GridTestNode

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

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

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

the class GridTcpCommunicationSpiLanTest method beforeTestsStarted.

/** {@inheritDoc} */
@Override
protected void beforeTestsStarted() throws Exception {
    spi = createSpi();
    spiRsrc = new IgniteTestResources(getMBeanServer());
    locNode = new GridTestNode(spiRsrc.getNodeId());
    GridSpiTestContext ctx = initSpiContext();
    ctx.setLocalNode(locNode);
    info(">>> Initialized context: nodeId=" + ctx.localNode().id());
    spiRsrc.inject(spi);
    lsnr = new MessageListener(spiRsrc.getNodeId());
    spi.setListener(lsnr);
    Map<String, Object> attrs = spi.getNodeAttributes();
    locNode.setAttributes(attrs);
    spi.spiStart(getTestIgniteInstanceName());
    spi.onContextInitialized(ctx);
    IgniteTestResources remoteRsrc = new IgniteTestResources();
    remoteNode = new GridTestNode(remoteRsrc.getNodeId());
    remoteNode.setAttributes(attrs);
    remoteNode.setAttribute(U.spiAttribute(spi, TcpCommunicationSpi.ATTR_ADDRS), Collections.singleton(remoteAddr));
    ctx.remoteNodes().add(remoteNode);
}
Also used : GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) 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 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 Message (org.apache.ignite.plugin.extensions.communication.Message)3 CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)3