Search in sources :

Example 41 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest method checkOverflow.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void checkOverflow() throws Exception {
    TcpCommunicationSpi spi0 = spis.get(0);
    TcpCommunicationSpi spi1 = spis.get(1);
    ClusterNode node0 = nodes.get(0);
    ClusterNode node1 = nodes.get(1);
    final GridNioServer srv1 = U.field(spi1, "nioSrvr");
    int msgId = 0;
    // Send message to establish connection.
    spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
    // Prevent node1 from send
    GridTestUtils.setFieldValue(srv1, "skipWrite", true);
    final GridNioSession ses0 = communicationSession(spi0);
    int sentMsgs = 1;
    for (int i = 0; i < 1280; i++) {
        try {
            spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
            sentMsgs++;
        } catch (IgniteSpiException e) {
            log.info("Send error [err=" + e + ", sentMsgs=" + sentMsgs + ']');
            break;
        }
    }
    // Wait when session is closed because of queue overflow.
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return ses0.closeTime() != 0;
        }
    }, 5000);
    assertTrue("Failed to wait for session close", ses0.closeTime() != 0);
    GridTestUtils.setFieldValue(srv1, "skipWrite", false);
    for (int i = 0; i < 100; i++) spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
    final int expMsgs = sentMsgs + 100;
    final TestListener lsnr = (TestListener) spi1.getListener();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return lsnr.rcvCnt.get() >= expMsgs;
        }
    }, 5000);
    assertEquals(expMsgs, lsnr.rcvCnt.get());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer)

Example 42 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridTcpCommunicationSpiRecoveryAckSelfTest method checkAck.

/**
 * @param ackCnt Recovery acknowledgement count.
 * @param idleTimeout Idle connection timeout.
 * @param msgPerIter Messages per iteration.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void checkAck(int ackCnt, int idleTimeout, int msgPerIter) throws Exception {
    createSpis(ackCnt, idleTimeout, TcpCommunicationSpi.DFLT_MSG_QUEUE_LIMIT);
    try {
        TcpCommunicationSpi spi0 = spis.get(0);
        TcpCommunicationSpi spi1 = spis.get(1);
        ClusterNode node0 = nodes.get(0);
        ClusterNode node1 = nodes.get(1);
        int msgId = 0;
        int expMsgs = 0;
        long totAcked = 0;
        for (int i = 0; i < 5; i++) {
            info("Iteration: " + i);
            for (int j = 0; j < msgPerIter; j++) {
                spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
                spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0));
            }
            U.sleep(500);
            expMsgs += msgPerIter;
            final long totAcked0 = totAcked;
            for (TcpCommunicationSpi spi : spis) {
                GridNioServer srv = U.field(spi, "nioSrvr");
                final Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
                GridTestUtils.waitForCondition(new GridAbsPredicate() {

                    @Override
                    public boolean apply() {
                        return !sessions.isEmpty();
                    }
                }, 5_000);
                boolean found = false;
                for (GridNioSession ses : sessions) {
                    final GridNioRecoveryDescriptor recoveryDesc = ses.outRecoveryDescriptor();
                    if (recoveryDesc != null) {
                        found = true;
                        GridTestUtils.waitForCondition(new GridAbsPredicate() {

                            @Override
                            public boolean apply() {
                                long acked = GridTestUtils.getFieldValue(recoveryDesc, "acked");
                                return acked > totAcked0;
                            }
                        }, 5000);
                        GridTestUtils.waitForCondition(new GridAbsPredicate() {

                            @Override
                            public boolean apply() {
                                return recoveryDesc.messagesRequests().isEmpty();
                            }
                        }, 10_000);
                        assertEquals("Unexpected messages: " + recoveryDesc.messagesRequests(), 0, recoveryDesc.messagesRequests().size());
                        break;
                    }
                }
                assertTrue(found);
            }
            final int expMsgs0 = expMsgs;
            for (TcpCommunicationSpi spi : spis) {
                final TestListener lsnr = (TestListener) spi.getListener();
                GridTestUtils.waitForCondition(new GridAbsPredicate() {

                    @Override
                    public boolean apply() {
                        return lsnr.rcvCnt.get() >= expMsgs0;
                    }
                }, 5000);
                assertEquals(expMsgs, lsnr.rcvCnt.get());
            }
            totAcked += msgPerIter;
        }
    } finally {
        stopSpis();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)

Example 43 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class ComputeUtilsTest method testGetData.

/**
 * Tests {@code getData()} method.
 */
public void testGetData() {
    ClusterNode node = grid(1).cluster().localNode();
    String upstreamCacheName = "CACHE_1_" + UUID.randomUUID();
    String datasetCacheName = "CACHE_2_" + UUID.randomUUID();
    CacheConfiguration<Integer, Integer> upstreamCacheConfiguration = new CacheConfiguration<>();
    upstreamCacheConfiguration.setName(upstreamCacheName);
    upstreamCacheConfiguration.setAffinity(new TestAffinityFunction(node));
    IgniteCache<Integer, Integer> upstreamCache = ignite.createCache(upstreamCacheConfiguration);
    CacheConfiguration<Integer, Integer> datasetCacheConfiguration = new CacheConfiguration<>();
    datasetCacheConfiguration.setName(datasetCacheName);
    datasetCacheConfiguration.setAffinity(new TestAffinityFunction(node));
    IgniteCache<Integer, Integer> datasetCache = ignite.createCache(datasetCacheConfiguration);
    upstreamCache.put(42, 42);
    datasetCache.put(0, 0);
    UUID datasetId = UUID.randomUUID();
    IgniteAtomicLong cnt = ignite.atomicLong("CNT_" + datasetId, 0, true);
    for (int i = 0; i < 10; i++) {
        Collection<TestPartitionData> data = ComputeUtils.affinityCallWithRetries(ignite, Arrays.asList(datasetCacheName, upstreamCacheName), part -> ComputeUtils.<Integer, Integer, Serializable, TestPartitionData>getData(ignite, upstreamCacheName, datasetCacheName, datasetId, 0, (upstream, upstreamSize, ctx) -> {
            cnt.incrementAndGet();
            assertEquals(1, upstreamSize);
            UpstreamEntry<Integer, Integer> e = upstream.next();
            return new TestPartitionData(e.getKey() + e.getValue());
        }), 0);
        assertEquals(1, data.size());
        TestPartitionData dataElement = data.iterator().next();
        assertEquals(84, dataElement.val.intValue());
    }
    assertEquals(1, cnt.get());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Arrays(java.util.Arrays) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Collection(java.util.Collection) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) List(java.util.List) Ignition(org.apache.ignite.Ignition) ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Collections(java.util.Collections) UpstreamEntry(org.apache.ignite.ml.dataset.UpstreamEntry) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) UpstreamEntry(org.apache.ignite.ml.dataset.UpstreamEntry)

Example 44 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class ComputeUtilsTest method testAffinityCallWithRetriesNegative.

/**
 * Tests that in case two caches maintain their partitions on different nodes, affinity call won't be completed.
 */
public void testAffinityCallWithRetriesNegative() {
    ClusterNode node1 = grid(1).cluster().localNode();
    ClusterNode node2 = grid(2).cluster().localNode();
    String firstCacheName = "CACHE_1_" + UUID.randomUUID();
    String secondCacheName = "CACHE_2_" + UUID.randomUUID();
    CacheConfiguration<Integer, Integer> cacheConfiguration1 = new CacheConfiguration<>();
    cacheConfiguration1.setName(firstCacheName);
    cacheConfiguration1.setAffinity(new TestAffinityFunction(node1));
    IgniteCache<Integer, Integer> cache1 = ignite.createCache(cacheConfiguration1);
    CacheConfiguration<Integer, Integer> cacheConfiguration2 = new CacheConfiguration<>();
    cacheConfiguration2.setName(secondCacheName);
    cacheConfiguration2.setAffinity(new TestAffinityFunction(node2));
    IgniteCache<Integer, Integer> cache2 = ignite.createCache(cacheConfiguration2);
    try {
        try {
            ComputeUtils.affinityCallWithRetries(ignite, Arrays.asList(firstCacheName, secondCacheName), part -> part, 0);
        } catch (IllegalStateException expectedException) {
            return;
        }
        fail("Missing IllegalStateException");
    } finally {
        cache1.destroy();
        cache2.destroy();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 45 with ClusterNode

use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.

the class GridMarshallerAbstractTest method testMarshallingAnonymousClassInstance.

/**
 * Tests marshal anonymous class instance.
 *
 * @throws Exception If test failed.
 */
public void testMarshallingAnonymousClassInstance() throws Exception {
    final Ignite g = grid();
    GridMarshallerTestBean inBean = newTestBean(new IgniteClosure() {

        /**
         */
        private Iterable<ClusterNode> nodes = g.cluster().nodes();

        /**
         * {@inheritDoc}
         */
        @Override
        public Object apply(Object o) {
            return nodes;
        }
    });
    byte[] buf = marshal(inBean);
    GridMarshallerTestBean outBean = unmarshal(buf);
    assert inBean.getObjectField() != null;
    assert outBean.getObjectField() != null;
    assert IgniteClosure.class.isAssignableFrom(inBean.getObjectField().getClass());
    assert IgniteClosure.class.isAssignableFrom(outBean.getObjectField().getClass());
    assert inBean.getObjectField() != outBean.getObjectField();
    assert inBean != outBean;
    assert inBean.equals(outBean);
    outBean.checkNullResources();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClosure(org.apache.ignite.lang.IgniteClosure) Ignite(org.apache.ignite.Ignite)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)738 UUID (java.util.UUID)185 ArrayList (java.util.ArrayList)180 Ignite (org.apache.ignite.Ignite)151 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)150 HashMap (java.util.HashMap)104 Map (java.util.Map)89 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)86 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)80 List (java.util.List)79 IgniteException (org.apache.ignite.IgniteException)68 Collection (java.util.Collection)67 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)58 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)52 HashSet (java.util.HashSet)39 CountDownLatch (java.util.concurrent.CountDownLatch)38 Event (org.apache.ignite.events.Event)38 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)36 IgniteKernal (org.apache.ignite.internal.IgniteKernal)35 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)34