Search in sources :

Example 1 with GridTestNode

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

the class GridJobStealingCollisionSpiCustomTopologySelfTest method initSpiContext.

/** {@inheritDoc} */
@Override
protected GridSpiTestContext initSpiContext() throws Exception {
    GridSpiTestContext ctx = super.initSpiContext();
    GridTestNode locNode = new GridTestNode(UUID.randomUUID());
    ctx.setLocalNode(locNode);
    rmtNode1 = new GridTestNode(UUID.randomUUID());
    rmtNode2 = new GridTestNode(UUID.randomUUID());
    addSpiDependency(locNode);
    addSpiDependency(rmtNode1);
    addSpiDependency(rmtNode2);
    ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot();
    metrics.setCurrentWaitingJobs(2);
    rmtNode1.setMetrics(metrics);
    rmtNode2.setMetrics(metrics);
    ctx.addNode(rmtNode1);
    ctx.addNode(rmtNode2);
    return ctx;
}
Also used : ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 2 with GridTestNode

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testSameAttribute.

/**
     * @throws Exception If test failed.
     */
public void testSameAttribute() throws Exception {
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    GridTestNode rmtNode = (GridTestNode) getSpiContext().remoteNodes().iterator().next();
    rmtNode.setAttribute("useCollision", true);
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(F.asMap("useCollision", true));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Cleanup
    rmtNode.removeAttribute("useCollision");
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(Collections.<String, Serializable>emptyMap());
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    // attributes.
    assert msg != null;
}
Also used : Serializable(java.io.Serializable) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 3 with GridTestNode

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testEmptyLocalAttribute.

/**
     * @throws Exception If test failed.
     */
public void testEmptyLocalAttribute() throws Exception {
    // Collision SPI does not allow to send more than 1 message in a
    // certain period of time (see getMessageExpireTime() method).
    // Thus we have to wait for the message to be expired.
    Thread.sleep(50);
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
    rmtNode.setAttribute("useCollision", true);
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Cleanup.
    rmtNode.removeAttribute("useCollision");
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    // attributes.
    assert msg != null;
}
Also used : Serializable(java.io.Serializable) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 4 with GridTestNode

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

the class GridJobStealingCollisionSpiAttributesSelfTest method initSpiContext.

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

Example 5 with GridTestNode

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

the class GridTcpCommunicationSpiConcurrentConnectSelfTest method startSpis.

/**
     * @param lsnr Message listener.
     * @throws Exception If failed.
     */
private void startSpis(MessageListener lsnr) throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    for (int i = 0; i < SPI_CNT; i++) {
        CommunicationSpi<Message> spi = createSpi();
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i + 1);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(lsnr);
        node.setAttributes(spi.getNodeAttributes());
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.add(spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

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