Search in sources :

Example 66 with ClusterGroup

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

the class IgniteRejectConnectOnNodeStopTest method testNodeStop.

/**
 * @throws Exception If failed.
 */
@Test
public void testNodeStop() throws Exception {
    Ignite srv = startGrid(0);
    final Ignite c = startClientGrid(1);
    ClusterGroup grp = srv.cluster().forClients();
    IgniteCompute srvCompute = srv.compute(grp);
    srvCompute.call(new DummyClosure());
    IgniteInternalFuture fut = GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            IgniteCache cache = c.cache(DEFAULT_CACHE_NAME);
            for (int i = 0; i < 100_000; i++) {
                try {
                    cache.put(1, 1);
                } catch (Exception ignore) {
                    break;
                }
            }
        }
    }, "cache-put");
    U.sleep(100);
    final CountDownLatch stopStartLatch = new CountDownLatch(1);
    IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            stopStartLatch.countDown();
            c.close();
        }
    });
    boolean err = false;
    try {
        stopStartLatch.await();
        IgniteCacheMessageRecoveryAbstractTest.closeSessions(srv);
        long stopTime = U.currentTimeMillis() + 10_000;
        while (U.currentTimeMillis() < stopTime) {
            try {
                srvCompute.call(new DummyClosure());
            } catch (ClusterTopologyException e) {
                err = true;
                assertFalse(fut2.isDone());
                break;
            }
        }
    } finally {
        stopLatch.countDown();
    }
    fut.get();
    fut2.get();
    assertTrue("Failed to get excpected error", err);
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) Ignite(org.apache.ignite.Ignite) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteCompute(org.apache.ignite.IgniteCompute) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 67 with ClusterGroup

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

the class IgniteMessagingConfigVariationFullApiTest method orderedMessage.

/**
 * @throws Exception If fail.
 */
private void orderedMessage() throws Exception {
    Ignite ignite = grid(SERVER_NODE_IDX);
    ClusterGroup grp = gridCount() > 1 ? ignite.cluster().forRemotes() : ignite.cluster().forLocal();
    assert !grp.nodes().isEmpty();
    registerListenerAndSendOrderedMessages(ignite, grp);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 68 with ClusterGroup

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

the class IgniteMessagingConfigVariationFullApiTest method localServerInternal.

/**
 * Single server test.
 *
 * @param async Async message send flag.
 * @throws Exception If failed.
 */
private void localServerInternal(boolean async) throws Exception {
    int messages = MSGS;
    Ignite ignite = grid(SERVER_NODE_IDX);
    LATCH = new CountDownLatch(messages);
    ClusterGroup grp = grid(SERVER_NODE_IDX).cluster().forLocal();
    UUID opId = registerListener(grp);
    try {
        for (int i = 0; i < messages; i++) sendMessage(ignite, grp, value(i), async);
        assertTrue(LATCH.await(10, TimeUnit.SECONDS));
    } finally {
        ignite.message().stopRemoteListen(opId);
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Example 69 with ClusterGroup

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

the class IgniteMessagingConfigVariationFullApiTest method clientServerMessage.

/**
 * Client sends a message and client receives it.
 *
 * @param async Async message send flag.
 * @throws Exception If failed.
 */
private void clientServerMessage(boolean async) throws Exception {
    Ignite ignite = grid(CLIENT_NODE_IDX);
    ClusterGroup grp = ignite.cluster().forServers();
    assert !grp.nodes().isEmpty();
    registerListenerAndSendMessages(ignite, grp, async);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 70 with ClusterGroup

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

the class IgniteMessagingConfigVariationFullApiTest method clientClientMessage.

/**
 * Client sends a message and client receives it.
 *
 * @param async Async message send flag.
 * @throws Exception If failed.
 */
private void clientClientMessage(boolean async) throws Exception {
    Ignite ignite = grid(CLIENT_NODE_IDX);
    ClusterGroup grp = ignite.cluster().forClients();
    assert !grp.nodes().isEmpty();
    registerListenerAndSendMessages(ignite, grp, async);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Aggregations

ClusterGroup (org.apache.ignite.cluster.ClusterGroup)99 Ignite (org.apache.ignite.Ignite)51 Test (org.junit.Test)49 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)36 UUID (java.util.UUID)26 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)16 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)14 IgniteException (org.apache.ignite.IgniteException)12 ArrayList (java.util.ArrayList)9 IgniteCompute (org.apache.ignite.IgniteCompute)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IgniteCluster (org.apache.ignite.IgniteCluster)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)5 IgniteFuture (org.apache.ignite.lang.IgniteFuture)5 Map (java.util.Map)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)4 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)4