Search in sources :

Example 61 with ClusterGroup

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

the class GridProjectionForCachesOnDaemonNodeSelfTest method testForClientNodes.

/**
 * @throws Exception If failed.
 */
@Test
public void testForClientNodes() throws Exception {
    ClusterGroup grp = ignite.cluster().forClientNodes(DEFAULT_CACHE_NAME);
    assertTrue(grp.nodes().isEmpty());
    try {
        daemon.cluster().forClientNodes(DEFAULT_CACHE_NAME);
    } catch (IllegalStateException ignored) {
        return;
    }
    fail();
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 62 with ClusterGroup

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

the class IgniteUtils method broadcastToNodesWithFilterAsync.

/**
 * Broadcasts given job to nodes that match filter.
 *
 * @param kctx Kernal context.
 * @param job Ignite job.
 * @param srvrsOnly Broadcast only on server nodes.
 * @param nodeFilter Node filter.
 */
public static IgniteFuture<Void> broadcastToNodesWithFilterAsync(GridKernalContext kctx, IgniteRunnable job, boolean srvrsOnly, IgnitePredicate<ClusterNode> nodeFilter) {
    ClusterGroup cl = kctx.grid().cluster();
    if (srvrsOnly)
        cl = cl.forServers();
    ClusterGroup grp = nodeFilter != null ? cl.forPredicate(nodeFilter) : cl;
    if (grp.nodes().isEmpty())
        return new IgniteFinishedFutureImpl<>();
    IgniteCompute compute = kctx.grid().compute(grp);
    return compute.broadcastAsync(job);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 63 with ClusterGroup

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

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method testClientRequestsUpToDateMetadata.

/**
 * Verifies that client is able to detect obsolete metadata situation and request up-to-date from the cluster.
 */
@Test
public void testClientRequestsUpToDateMetadata() throws Exception {
    final IgniteEx ignite0 = startGrid(0);
    final IgniteEx ignite1 = startGrid(1);
    ignite0.executorService().submit(new Runnable() {

        @Override
        public void run() {
            addIntField(ignite0, "f1", 101, 1);
        }
    }).get();
    final Ignite client = startDeafClient("client");
    ClusterGroup clientGrp = client.cluster().forClients();
    final String strVal = "strVal101";
    ignite1.executorService().submit(new Runnable() {

        @Override
        public void run() {
            addStringField(ignite1, "f2", strVal, 1);
        }
    }).get();
    String res = client.compute(clientGrp).call(new IgniteCallable<String>() {

        @Override
        public String call() throws Exception {
            return ((BinaryObject) client.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(1)).field("f2");
        }
    });
    assertEquals(strVal, res);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 64 with ClusterGroup

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

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method testClientRequestsUpToDateMetadataOneNodeDies.

/**
 * Verifies that client resends request for up-to-date metadata in case of failure on server received first request.
 */
@Test
public void testClientRequestsUpToDateMetadataOneNodeDies() throws Exception {
    final Ignite srv0 = startGrid(0);
    replaceWithStoppingMappingRequestListener(((GridKernalContext) U.field(srv0, "ctx")).io(), 0);
    final Ignite srv1 = startGrid(1);
    replaceWithCountingMappingRequestListener(((GridKernalContext) U.field(srv1, "ctx")).io());
    final Ignite srv2 = startGrid(2);
    replaceWithCountingMappingRequestListener(((GridKernalContext) U.field(srv2, "ctx")).io());
    final Ignite client = startDeafClient("client");
    ClusterGroup clientGrp = client.cluster().forClients();
    srv0.executorService().submit(new Runnable() {

        @Override
        public void run() {
            addStringField(srv0, "f2", "strVal101", 0);
        }
    }).get();
    client.compute(clientGrp).call(new IgniteCallable<String>() {

        @Override
        public String call() throws Exception {
            return ((BinaryObject) client.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(0)).field("f2");
        }
    });
    assertEquals(metadataReqsCounter.get(), 2);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 65 with ClusterGroup

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

the class BinaryMetadataUpdatesFlowTest method startComputation.

/**
 * Starts computation job.
 *
 * @param idx Grid index on which computation job should start.
 * @param restartIdx The index of the node to be restarted.
 * @param workersCntr The current number of computation threads.
 */
private void startComputation(int idx, AtomicInteger restartIdx, AtomicInteger workersCntr) {
    Ignite ignite = grid(idx);
    ClusterGroup cg = ignite.cluster().forLocal();
    ignite.compute(cg).callAsync(new BinaryObjectAdder(startLatch, idx, updatesQueue, restartIdx, workersCntr));
}
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