Search in sources :

Example 16 with CommunicationSpi

use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.

the class GridTcpCommunicationSpiAbstractTest method testCheckConnection2.

/**
 * @throws Exception If failed.
 */
@Test
public void testCheckConnection2() throws Exception {
    final int THREADS = spis.size();
    final CyclicBarrier b = new CyclicBarrier(THREADS);
    List<IgniteInternalFuture<?>> futs = new ArrayList<>();
    for (Map.Entry<UUID, CommunicationSpi<Message>> entry : spis.entrySet()) {
        final TcpCommunicationSpi spi = (TcpCommunicationSpi) entry.getValue();
        futs.add(GridTestUtils.runAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                List<ClusterNode> checkNodes = new ArrayList<>(nodes);
                assert checkNodes.size() > 1;
                b.await();
                for (int i = 0; i < 100; i++) {
                    IgniteFuture<BitSet> fut = spi.checkConnection(checkNodes);
                    BitSet res = fut.get();
                    for (int n = 0; n < checkNodes.size(); n++) assertTrue(res.get(n));
                }
                return null;
            }
        }));
    }
    for (IgniteInternalFuture<?> f : futs) f.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) CyclicBarrier(java.util.concurrent.CyclicBarrier) UUID(java.util.UUID) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) Test(org.junit.Test) GridAbstractCommunicationSelfTest(org.apache.ignite.spi.communication.GridAbstractCommunicationSelfTest)

Example 17 with CommunicationSpi

use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.

the class ZookeeperDiscoverySpi method consistentId.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public Serializable consistentId() throws IgniteSpiException {
    if (consistentId == null) {
        consistentId = ignite.configuration().getConsistentId();
        if (consistentId == null) {
            initAddresses();
            final List<String> sortedAddrs = new ArrayList<>(addrs.get1());
            Collections.sort(sortedAddrs);
            if (getBoolean(IGNITE_CONSISTENT_ID_BY_HOST_WITHOUT_PORT))
                consistentId = U.consistentId(sortedAddrs);
            else {
                Integer commPort = null;
                if (locNodeAttrs != null) {
                    commPort = (Integer) locNodeAttrs.get(TcpCommunicationSpi.class.getSimpleName() + "." + TcpCommunicationSpi.ATTR_PORT);
                } else {
                    CommunicationSpi commSpi = ignite.configuration().getCommunicationSpi();
                    if (commSpi instanceof TcpCommunicationSpi) {
                        commPort = ((TcpCommunicationSpi) commSpi).boundPort();
                        if (commPort == -1)
                            commPort = null;
                    }
                }
                if (commPort == null) {
                    U.warn(log, "Can not initialize default consistentId, TcpCommunicationSpi port is not initialized.");
                    consistentId = ignite.configuration().getNodeId();
                } else
                    consistentId = U.consistentId(sortedAddrs, commPort);
            }
        }
    }
    return consistentId;
}
Also used : CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) ArrayList(java.util.ArrayList) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with CommunicationSpi

use of org.apache.ignite.spi.communication.CommunicationSpi 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 19 with CommunicationSpi

use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.

the class IgniteCachePartitionedQuerySelfTest method testScanQueryPagination.

/**
 * @throws Exception If failed.
 */
@Test
public void testScanQueryPagination() throws Exception {
    final int pageSize = 5;
    final AtomicInteger pages = new AtomicInteger(0);
    IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
    for (int i = 0; i < 50; i++) cache.put(i, i);
    CommunicationSpi spi = ignite().configuration().getCommunicationSpi();
    assert spi instanceof TestTcpCommunicationSpi;
    TestTcpCommunicationSpi commSpi = (TestTcpCommunicationSpi) spi;
    commSpi.filter = new IgniteInClosure<Message>() {

        @Override
        public void apply(Message msg) {
            if (!(msg instanceof GridIoMessage))
                return;
            Message msg0 = ((GridIoMessage) msg).message();
            if (msg0 instanceof GridCacheQueryRequest) {
                assertEquals(pageSize, ((GridCacheQueryRequest) msg0).pageSize());
                pages.incrementAndGet();
            } else if (msg0 instanceof GridCacheQueryResponse)
                assertTrue(((GridCacheQueryResponse) msg0).data().size() <= pageSize);
        }
    };
    try {
        ScanQuery<Integer, Integer> qry = new ScanQuery<Integer, Integer>();
        qry.setPageSize(pageSize);
        List<Cache.Entry<Integer, Integer>> all = cache.query(qry).getAll();
        assertTrue(pages.get() > ignite().cluster().forDataNodes(DEFAULT_CACHE_NAME).nodes().size());
        assertEquals(50, all.size());
    } finally {
        commSpi.filter = null;
    }
}
Also used : GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ScanQuery(org.apache.ignite.cache.query.ScanQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryResponse(org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryRequest(org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest) IgniteCacheAbstractQuerySelfTest(org.apache.ignite.internal.processors.cache.IgniteCacheAbstractQuerySelfTest) Test(org.junit.Test)

Aggregations

CommunicationSpi (org.apache.ignite.spi.communication.CommunicationSpi)19 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)9 UUID (java.util.UUID)7 Test (org.junit.Test)6 GridCommunicationClient (org.apache.ignite.internal.util.nio.GridCommunicationClient)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 DiscoverySpi (org.apache.ignite.spi.discovery.DiscoverySpi)4 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3 BitSet (java.util.BitSet)2 HashMap (java.util.HashMap)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 ConnectionClientPool (org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool)2