Search in sources :

Example 1 with IgniteTestResources

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

the class IgfsSharedMemoryTestServer method main.

@SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
public static void main(String[] args) throws IgniteCheckedException {
    System.out.println("Starting server ...");
    // Tell our process PID to the wrapper.
    X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
    InputStream is = null;
    try {
        IpcServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
        new IgniteTestResources().inject(srv);
        srv.start();
        System.out.println("IPC shared memory server endpoint started");
        IpcEndpoint clientEndpoint = srv.accept();
        is = clientEndpoint.inputStream();
        for (; ; ) {
            X.println("Before read.");
            is.read();
            Thread.sleep(IpcSharedMemoryCrashDetectionSelfTest.RW_SLEEP_TIMEOUT);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        U.closeQuiet(is);
    }
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcServerEndpoint(org.apache.ignite.internal.util.ipc.IpcServerEndpoint) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) InputStream(java.io.InputStream) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 2 with IgniteTestResources

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

the class IpcSharedMemoryCrashDetectionSelfTest method afterTestsStopped.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTestsStopped() throws Exception {
    // Start and stop server endpoint to let GC worker
    // make a run and cleanup resources.
    IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
    new IgniteTestResources().inject(srv);
    try {
        srv.start();
    } finally {
        srv.close();
    }
}
Also used : IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources)

Example 3 with IgniteTestResources

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

the class IpcSharedMemoryCrashDetectionSelfTest method testIgfsServerClientInteractionsUponClientKilling.

/**
 * @throws Exception If failed.
 */
public void testIgfsServerClientInteractionsUponClientKilling() throws Exception {
    // Run server endpoint.
    IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
    new IgniteTestResources().inject(srv);
    try {
        srv.start();
        info("Check that server gets correct exception upon client's killing.");
        info("Shared memory IDs before starting client endpoint: " + IpcSharedMemoryUtils.sharedMemoryIds());
        Collection<Integer> shmemIdsWithinInteractions = interactWithClient(srv, true);
        Collection<Integer> shmemIdsAfterInteractions = null;
        // Give server endpoint some time to make resource clean up. See IpcSharedMemoryServerEndpoint.GC_FREQ.
        for (int i = 0; i < 12; i++) {
            shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds();
            info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions);
            info("Shared memory IDs after killing client endpoint: " + shmemIdsAfterInteractions);
            if (CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions))
                U.sleep(1000);
            else
                break;
        }
        assertFalse("List of shared memory IDs after killing client endpoint should not include IDs created " + "within server-client interactions.", CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions));
    } finally {
        srv.close();
    }
}
Also used : IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources)

Example 4 with IgniteTestResources

use of org.apache.ignite.testframework.junits.IgniteTestResources 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 5 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();
        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)

Aggregations

IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)24 Message (org.apache.ignite.plugin.extensions.communication.Message)11 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)11 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)10 GridTestNode (org.apache.ignite.testframework.GridTestNode)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)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 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)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 Test (org.junit.Test)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteMessageFactory (org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory)4 CommunicationSpi (org.apache.ignite.spi.communication.CommunicationSpi)4 ArrayList (java.util.ArrayList)3