Search in sources :

Example 16 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.

the class AbstractDiscoverySelfTest method testDiscovery.

/**
 * Checks that each started discovery spi found all other SPI's.
 * @throws Exception If failed.
 */
@SuppressWarnings({ "UnconditionalWait" })
public void testDiscovery() throws Exception {
    assert spis.size() > 1;
    assert spiStartTime > 0;
    assert spiRsrcs.size() == getSpiCount();
    boolean isAllDiscovered = false;
    while (!isAllDiscovered) {
        for (DiscoverySpi spi : spis) {
            if (spi.getRemoteNodes().size() < (getSpiCount() - 1)) {
                isAllDiscovered = false;
                break;
            }
            isAllDiscovered = true;
            for (IgniteTestResources rscrs : spiRsrcs) {
                UUID nodeId = rscrs.getNodeId();
                if (!nodeId.equals(spi.getLocalNode().id())) {
                    if (!isContainsNodeId(spi.getRemoteNodes(), nodeId)) {
                        isAllDiscovered = false;
                        break;
                    }
                }
            }
        }
        if (isAllDiscovered)
            info("All nodes discovered.");
        else {
            if (System.currentTimeMillis() > spiStartTime + getMaxDiscoveryTime()) {
                for (int i = 0; i < getSpiCount(); i++) {
                    DiscoverySpi spi = spis.get(i);
                    info("Remote nodes [spiIdx=" + i + ", nodes=" + spi.getRemoteNodes() + ']');
                }
                fail("Nodes were not discovered.");
            } else {
                synchronized (mux) {
                    mux.wait(getMaxDiscoveryTime());
                }
            }
        }
    }
}
Also used : IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) UUID(java.util.UUID)

Example 17 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest method startSpis.

/**
 * @param ackCnt Recovery acknowledgement count.
 * @param idleTimeout Idle connection timeout.
 * @param queueLimit Message queue limit.
 * @throws Exception If failed.
 */
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < SPI_CNT; i++) {
        TcpCommunicationSpi spi = getSpi(ackCnt, idleTimeout, queueLimit);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        spi.setListener(new TestListener());
        node.setAttributes(spi.getNodeAttributes());
        node.order(i);
        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) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest method stopSpis.

/**
 * @throws Exception If failed.
 */
private void stopSpis() throws Exception {
    if (timeoutProcessor != null) {
        timeoutProcessor.onKernalStop(true);
        timeoutProcessor.stop(true);
        timeoutProcessor = null;
    }
    for (CommunicationSpi<Message> spi : spis) {
        spi.onContextDestroyed();
        spi.setListener(null);
        spi.spiStop();
    }
    for (IgniteTestResources rsrcs : spiRsrcs) rsrcs.stopThreads();
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
}
Also used : GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources)

Example 19 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.

the class GridAbstractCommunicationSelfTest method startSpis.

/**
 * @throws Exception If failed.
 */
private void startSpis() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < getSpiCount(); i++) {
        CommunicationSpi<Message> spi = getSpi(i);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(new MessageListener(rsrcs.getNodeId()));
        node.setAttributes(spi.getNodeAttributes());
        node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        node.order(i + 1);
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.put(rsrcs.getNodeId(), spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (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) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) 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)

Example 20 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.

the class GridAbstractCommunicationSelfTest method afterTestsStopped.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTestsStopped() throws Exception {
    if (timeoutProcessor != null) {
        timeoutProcessor.onKernalStop(true);
        timeoutProcessor.stop(true);
        timeoutProcessor = null;
    }
    for (CommunicationSpi<Message> spi : spis.values()) {
        spi.onContextDestroyed();
        spi.setListener(null);
        spi.spiStop();
    }
    for (IgniteTestResources rsrcs : spiRsrcs) rsrcs.stopThreads();
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources)

Aggregations

IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)20 Message (org.apache.ignite.plugin.extensions.communication.Message)9 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)8 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)7 GridTestNode (org.apache.ignite.testframework.GridTestNode)7 HashMap (java.util.HashMap)6 GridTimeoutProcessor (org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 Map (java.util.Map)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 IgniteMock (org.apache.ignite.testframework.junits.IgniteMock)4 InputStream (java.io.InputStream)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)2 Collection (java.util.Collection)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1