Search in sources :

Example 6 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources 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<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < SPI_CNT; i++) {
        TcpCommunicationSpi spi = getSpi(i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        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 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) 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) 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 7 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources 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();
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        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 8 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources 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 9 with IgniteTestResources

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

the class AbstractDiscoverySelfTest method afterTestsStopped.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTestsStopped() throws Exception {
    assert spis.size() > 1;
    assert spis.size() == spiRsrcs.size();
    for (DiscoverySpi spi : spis) {
        spi.setListener(null);
        spi.spiStop();
    }
    for (IgniteTestResources rscrs : spiRsrcs) {
        MBeanServer mBeanSrv = rscrs.getMBeanServer();
        mBeanSrv.unregisterMBean(new ObjectName(HTTP_ADAPTOR_MBEAN_NAME));
        rscrs.stopThreads();
    }
    for (HttpAdaptor adaptor : httpAdaptors) adaptor.stop();
    // Clear.
    spis.clear();
    spiRsrcs.clear();
    httpAdaptors.clear();
    spiStartTime = 0;
    tearDown();
}
Also used : IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) HttpAdaptor(mx4j.tools.adaptor.http.HttpAdaptor) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 10 with IgniteTestResources

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

the class IpcSharedMemoryBenchmarkReader method main.

/**
 * @param args Args.
 * @throws IgniteCheckedException If failed.
 */
public static void main(String[] args) throws IgniteCheckedException {
    IpcSharedMemoryNativeLoader.load(null);
    int nThreads = (args.length > 0 ? Integer.parseInt(args[0]) : 1);
    final AtomicLong transferCntr = new AtomicLong();
    Thread collector = new Thread(new Runnable() {

        @SuppressWarnings("BusyWait")
        @Override
        public void run() {
            try {
                while (!done) {
                    Thread.sleep(5000);
                    X.println("Transfer rate: " + transferCntr.getAndSet(0) / (1024 * 1024 * 5) + " MB/sec");
                }
            } catch (InterruptedException ignored) {
            // No-op.
            }
        }
    });
    collector.start();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            System.out.println("Shutting down...");
            done = true;
        }
    });
    try (IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory())) {
        new IgniteTestResources().inject(srv);
        srv.start();
        for (int i = 0; i < nThreads; i++) {
            final IpcEndpoint endPnt = srv.accept();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    InputStream space = null;
                    try {
                        space = endPnt.inputStream();
                        byte[] buf = new byte[DST_BUFFER_SIZE];
                        int pos = 0;
                        while (!done) {
                            int maxRead = Math.min(buf.length - pos, DFLT_BUF_SIZE);
                            int read = space.read(buf, pos, maxRead);
                            if (read == -1) {
                                X.println("Space has been closed");
                                return;
                            }
                            transferCntr.addAndGet(read);
                            pos += read;
                            if (pos >= buf.length)
                                pos = 0;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        U.closeQuiet(space);
                    }
                }
            }).start();
        }
    }
    JOptionPane.showMessageDialog(null, "Press OK to stop READER.");
    done = true;
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) InputStream(java.io.InputStream) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)

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