Search in sources :

Example 6 with IgniteMessageFactoryImpl

use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.

the class GridTcpCommunicationSpiConfigSelfTest method initializeSpi.

/**
 * Initializes TcpCommunicationSpi with given context, node, logger and clientMode flag.
 */
private TcpCommunicationSpi initializeSpi(GridSpiTestContext ctx, GridTestNode node, IgniteLogger log, boolean clientMode) throws Exception {
    TcpCommunicationSpi spi = new TcpCommunicationSpi();
    spi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));
    spi.setIdleConnectionTimeout(2000);
    IgniteConfiguration cfg = new IgniteConfiguration().setGridLogger(log).setClientMode(clientMode);
    IgniteTestResources rsrcs = new IgniteTestResources(cfg);
    resourcesToClean.add(rsrcs);
    cfg.setMBeanServer(rsrcs.getMBeanServer());
    node.setId(rsrcs.getNodeId());
    MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
    ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
    ctx.setLocalNode(node);
    rsrcs.inject(spi);
    spi.spiStart(getTestIgniteInstanceName() + node.order());
    node.setAttributes(spi.getNodeAttributes());
    node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
    return spi;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteEx(org.apache.ignite.internal.IgniteEx) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) ArrayList(java.util.ArrayList) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) InetAddress(java.net.InetAddress) IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES(org.apache.ignite.IgniteSystemProperties.IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) IgniteUtils.spiAttribute(org.apache.ignite.internal.util.IgniteUtils.spiAttribute) NullLogger(org.apache.ignite.logger.NullLogger) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Objects.requireNonNull(java.util.Objects.requireNonNull) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) Objects.isNull(java.util.Objects.isNull) ATTR_HOST_NAMES(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.ATTR_HOST_NAMES) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) F(org.apache.ignite.internal.util.typedef.F) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Test(org.junit.Test) GridTestUtils.getFreeCommPort(org.apache.ignite.testframework.GridTestUtils.getFreeCommPort) InetSocketAddress(java.net.InetSocketAddress) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridSpiAbstractConfigTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory)

Example 7 with IgniteMessageFactoryImpl

use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest 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);
        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);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        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 8 with IgniteMessageFactoryImpl

use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl 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();
        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);
        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.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        node.order(i + 1);
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        node.setAttributes(spi.getNodeAttributes());
        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) 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) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Example 9 with IgniteMessageFactoryImpl

use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.

the class GridTcpCommunicationSpiMultithreadedSelfTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    lsnrs.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 = newCommunicationSpi();
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
        ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
        ctx.timeoutProcessor(timeoutProcessor);
        ctx.setLocalNode(node);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        MessageListener lsnr = new MessageListener(rsrcs.getNodeId());
        spi.setListener(lsnr);
        lsnrs.put(rsrcs.getNodeId(), lsnr);
        info("Lsnrs: " + lsnrs);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        nodes.add(node);
        node.setAttributes(spi.getNodeAttributes());
        node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        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) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) CommunicationListener(org.apache.ignite.spi.communication.CommunicationListener) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Random(java.util.Random) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) Deque(java.util.Deque) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Map(java.util.Map) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) F(org.apache.ignite.internal.util.typedef.F) CyclicBarrier(java.util.concurrent.CyclicBarrier) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) UUID(java.util.UUID) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) List(java.util.List) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) Entry(java.util.Map.Entry) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) 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)

Example 10 with IgniteMessageFactoryImpl

use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl 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);
    IgniteMessageFactory msgFactory = new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory() });
    Message mx = msgFactory.create(type);
    mx.readFrom(buf, reader(msgFactory, proto));
    assertEquals(m, mx);
}
Also used : IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) 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)

Aggregations

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