Search in sources :

Example 41 with GridConcurrentHashSet

use of org.apache.ignite.internal.util.GridConcurrentHashSet in project ignite by apache.

the class TcpDiscoveryPendingMessageDeliveryTest method testDeliveryAllFailedMessagesInCorrectOrder.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeliveryAllFailedMessagesInCorrectOrder() throws Exception {
    IgniteEx coord = startGrid("coordinator");
    TcpDiscoverySpi coordDisco = (TcpDiscoverySpi) coord.configuration().getDiscoverySpi();
    Set<TcpDiscoveryAbstractMessage> sentEnsuredMsgs = new GridConcurrentHashSet<>();
    coordDisco.addSendMessageListener(msg -> {
        if (coordDisco.ensured(msg))
            sentEnsuredMsgs.add(msg);
    });
    // Node which receive message but will not send it further around the ring.
    IgniteEx receiver = startGrid("receiver");
    // Node which will be failed first.
    IgniteEx dummy = startGrid("dummy");
    // Node which should received all fail message in any way.
    startGrid("listener");
    sentEnsuredMsgs.clear();
    receivedEnsuredMsgs.clear();
    blockMsgs = true;
    log.info("Sending fail node messages");
    coord.context().discovery().failNode(dummy.localNode().id(), "Dummy node failed");
    coord.context().discovery().failNode(receiver.localNode().id(), "Receiver node failed");
    boolean delivered = GridTestUtils.waitForCondition(() -> {
        log.info("Waiting for messages delivery");
        return receivedEnsuredMsgs.equals(sentEnsuredMsgs);
    }, 5000);
    assertTrue("Sent: " + sentEnsuredMsgs + "; received: " + receivedEnsuredMsgs, delivered);
}
Also used : GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 42 with GridConcurrentHashSet

use of org.apache.ignite.internal.util.GridConcurrentHashSet in project ignite by apache.

the class TcpDiscoveryRestartTest method testRestart.

/**
 * @throws Exception If failed.
 */
@Test
public void testRestart() throws Exception {
    err = new AtomicReference<>();
    final int NODE_CNT = 3;
    startGrids(NODE_CNT);
    final GridConcurrentHashSet<UUID> nodeIds = new GridConcurrentHashSet<>();
    final AtomicInteger id = new AtomicInteger(NODE_CNT);
    final IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            int nodeIdx = id.getAndIncrement();
            for (int i = 0; i < 10 && err.get() == null; i++) {
                Ignite ignite = startGrid(nodeIdx);
                UUID nodeId = ignite.cluster().localNode().id();
                if (!nodeIds.add(nodeId))
                    failed("Duplicated node ID: " + nodeId);
                stopGrid(nodeIdx);
            }
            return null;
        }
    }, 5, "restart-thread");
    IgniteInternalFuture<?> loadFut = GridTestUtils.runMultiThreadedAsync(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            long dummyRes = 0;
            List<String> list = new ArrayList<>();
            while (!fut.isDone()) {
                for (int i = 0; i < 100; i++) {
                    String str = new String(new byte[i]);
                    list.add(str);
                    dummyRes += str.hashCode();
                }
                if (list.size() > 1000_000) {
                    list = new ArrayList<>();
                    System.gc();
                }
            }
            return dummyRes;
        }
    }, 2, "test-load");
    fut.get();
    loadFut.get();
    assertNull(err.get());
    for (int i = 0; i < NODE_CNT; i++) {
        Ignite ignite = ignite(i);
        TestEventListener lsnr = (TestEventListener) F.firstKey(ignite.configuration().getLocalEventListeners());
        assertNotNull(lsnr);
        for (UUID nodeId : nodeIds) lsnr.checkEvents(nodeId);
    }
}
Also used : ArrayList(java.util.ArrayList) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)42 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 Ignite (org.apache.ignite.Ignite)21 Test (org.junit.Test)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)16 IgniteException (org.apache.ignite.IgniteException)15 IOException (java.io.IOException)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 UUID (java.util.UUID)9 IgniteCache (org.apache.ignite.IgniteCache)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)8 IgniteLock (org.apache.ignite.IgniteLock)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 ExpectedException (org.junit.rules.ExpectedException)8 Transaction (org.apache.ignite.transactions.Transaction)7