Search in sources :

Example 1 with IgniteMock

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

Example 2 with IgniteMock

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

the class AbstractDiscoverySelfTest method beforeTestsStarted.

/** {@inheritDoc} */
@Override
protected void beforeTestsStarted() throws Exception {
    try {
        for (int i = 0; i < getSpiCount(); i++) {
            DiscoverySpi spi = getSpi(i);
            IgniteTestResources rsrcMgr = new IgniteTestResources(getMBeanServer(i));
            rsrcMgr.inject(spi);
            spi.setNodeAttributes(Collections.<String, Object>singletonMap(TEST_ATTRIBUTE_NAME, "true"), fromString("99.99.99"));
            spi.setListener(new DiscoverySpiListener() {

                /** {@inheritDoc} */
                @Override
                public void onLocalNodeInitialized(ClusterNode locNode) {
                // No-op.
                }

                @SuppressWarnings({ "NakedNotify" })
                @Override
                public void onDiscovery(int type, long topVer, ClusterNode node, Collection<ClusterNode> topSnapshot, Map<Long, Collection<ClusterNode>> topHist, @Nullable DiscoverySpiCustomMessage data) {
                    info("Discovery event [type=" + type + ", node=" + node + ']');
                    synchronized (mux) {
                        mux.notifyAll();
                    }
                }
            });
            spi.setDataExchange(new DiscoverySpiDataExchange() {

                @Override
                public DiscoveryDataBag collect(DiscoveryDataBag dataBag) {
                    return dataBag;
                }

                @Override
                public void onExchange(DiscoveryDataBag dataBag) {
                // No-op.
                }
            });
            GridSpiTestContext ctx = initSpiContext();
            GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "spiCtx", ctx);
            if (useSsl) {
                IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
                IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
                ignite.setStaticCfg(cfg);
            }
            spi.spiStart(getTestIgniteInstanceName() + i);
            spis.add(spi);
            spiRsrcs.add(rsrcMgr);
            // Force to use test context instead of default dummy context.
            spi.onContextInitialized(ctx);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    spiStartTime = System.currentTimeMillis();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) Collection(java.util.Collection) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Example 3 with IgniteMock

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

the class GridTcpCommunicationSpiRecoverySelfTest method startSpis.

/**
     * @throws Exception If failed.
     */
private void startSpis() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    for (int i = 0; i < SPI_CNT; i++) {
        TcpCommunicationSpi spi = getSpi(i);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        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(new TestListener());
        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) 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) Map(java.util.Map)

Example 4 with IgniteMock

use of org.apache.ignite.testframework.junits.IgniteMock 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<>();
    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());
        node.order(i);
        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(new MessageListener(rsrcs.getNodeId()));
        node.setAttributes(spi.getNodeAttributes());
        node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        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) 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)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)4 IgniteMock (org.apache.ignite.testframework.junits.IgniteMock)4 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)4 HashMap (java.util.HashMap)3 GridTestNode (org.apache.ignite.testframework.GridTestNode)3 Map (java.util.Map)2 Message (org.apache.ignite.plugin.extensions.communication.Message)2 Collection (java.util.Collection)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)1