Search in sources :

Example 1 with GridSpiTestContext

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

Example 2 with GridSpiTestContext

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

the class GridSpiAbstractTest method initSpiContext.

/**
 * @return SPI context.
 * @throws Exception If anything failed.
 */
protected GridSpiTestContext initSpiContext() throws Exception {
    GridSpiTestContext spiCtx = new GridSpiTestContext();
    if (getTestData().getDiscoverySpi() != null) {
        spiCtx.setLocalNode(getTestData().getDiscoverySpi().getLocalNode());
        for (ClusterNode node : getTestData().getDiscoverySpi().getRemoteNodes()) spiCtx.addNode(node);
    } else {
        GridTestNode node = new GridTestNode(UUID.randomUUID());
        spiCtx.setLocalNode(node);
        if (getSpi() != null) {
            // Set up SPI class name and SPI version.
            Map<String, Serializable> attrs = initSpiClassAndVersionAttributes(getSpi());
            for (Map.Entry<String, Serializable> entry : attrs.entrySet()) node.addAttribute(entry.getKey(), entry.getValue());
        }
    }
    return spiCtx;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) Serializable(java.io.Serializable) IgniteProductVersion.fromString(org.apache.ignite.lang.IgniteProductVersion.fromString) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 3 with GridSpiTestContext

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

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest 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);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        GridSpiTestContext ctx = initSpiContext();
        MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {

            @Override
            public void registerAll(IgniteMessageFactory factory) {
                factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
            }
        };
        ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        spi.setListener(new TestListener());
        node.order(i);
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        node.setAttributes(spi.getNodeAttributes());
        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) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with GridSpiTestContext

use of org.apache.ignite.testframework.GridSpiTestContext 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 IgniteFuture<?> onDiscovery(DiscoveryNotification notification) {
                    info("Discovery event [type=" + notification.type() + ", node=" + notification.getNode() + ']');
                    synchronized (mux) {
                        mux.notifyAll();
                    }
                    return new IgniteFinishedFutureImpl<>();
                }
            });
            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) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Example 5 with GridSpiTestContext

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

Aggregations

GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)25 GridTestNode (org.apache.ignite.testframework.GridTestNode)20 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 HashMap (java.util.HashMap)7 GridIoMessageFactory (org.apache.ignite.internal.managers.communication.GridIoMessageFactory)7 IgniteMessageFactoryImpl (org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl)7 MessageFactory (org.apache.ignite.plugin.extensions.communication.MessageFactory)7 MessageFactoryProvider (org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider)7 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)7 Map (java.util.Map)6 GridTimeoutProcessor (org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor)6 Message (org.apache.ignite.plugin.extensions.communication.Message)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 IgniteMessageFactory (org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3