Search in sources :

Example 51 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridMessageCollectionTest method doTestMarshal.

/**
 * @param m Message.
 */
private void doTestMarshal(Message m) {
    ByteBuffer buf = ByteBuffer.allocate(8 * 1024);
    m.writeTo(buf, writer(proto));
    buf.flip();
    byte b0 = buf.get();
    byte b1 = buf.get();
    short type = (short) ((b1 & 0xFF) << 8 | b0 & 0xFF);
    assertEquals(m.directType(), type);
    GridIoMessageFactory msgFactory = new GridIoMessageFactory(null);
    Message mx = msgFactory.create(type);
    mx.readFrom(buf, reader(msgFactory, proto));
    assertEquals(m, mx);
}
Also used : UUIDCollectionMessage(org.apache.ignite.internal.util.UUIDCollectionMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) ByteBuffer(java.nio.ByteBuffer)

Example 52 with Message

use of org.apache.ignite.plugin.extensions.communication.Message 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 53 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridAbstractCommunicationSelfTest method testSendToManyNodes.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("WaitWithoutCorrespondingNotify")
public void testSendToManyNodes() throws Exception {
    msgDestMap.clear();
    // Send message from each SPI to all SPI's, including itself.
    for (Entry<UUID, CommunicationSpi<Message>> entry : spis.entrySet()) {
        UUID sndId = entry.getKey();
        CommunicationSpi<Message> commSpi = entry.getValue();
        for (ClusterNode node : nodes) {
            synchronized (mux) {
                if (!msgDestMap.containsKey(sndId))
                    msgDestMap.put(sndId, new HashSet<UUID>());
                msgDestMap.get(sndId).add(node.id());
            }
            commSpi.sendMessage(node, new GridTestMessage(sndId, msgId++, 0));
        }
    }
    long now = System.currentTimeMillis();
    long endTime = now + getMaxTransmitMessagesTime();
    synchronized (mux) {
        while (now < endTime && !msgDestMap.isEmpty()) {
            mux.wait(endTime - now);
            now = System.currentTimeMillis();
        }
        if (!msgDestMap.isEmpty()) {
            for (Entry<UUID, Set<UUID>> entry : msgDestMap.entrySet()) {
                error("Failed to receive all messages [sender=" + entry.getKey() + ", dest=" + entry.getValue() + ']');
            }
        }
        assert msgDestMap.isEmpty() : "Some messages were not received.";
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashSet(java.util.HashSet) Set(java.util.Set) Message(org.apache.ignite.plugin.extensions.communication.Message) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 54 with Message

use of org.apache.ignite.plugin.extensions.communication.Message 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 55 with Message

use of org.apache.ignite.plugin.extensions.communication.Message 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

Message (org.apache.ignite.plugin.extensions.communication.Message)56 ClusterNode (org.apache.ignite.cluster.ClusterNode)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)14 IgniteException (org.apache.ignite.IgniteException)11 UUID (java.util.UUID)9 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)9 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)9 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)8 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)8 ArrayList (java.util.ArrayList)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)7 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)7 HashMap (java.util.HashMap)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 Collection (java.util.Collection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5