Search in sources :

Example 91 with ClusterGroup

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

the class GridProjectionForCachesSelfTest method testProjectionForClientCaches.

/**
 * @throws Exception If failed.
 */
@Test
public void testProjectionForClientCaches() throws Exception {
    ClusterGroup prj = ignite.cluster().forClientNodes(CACHE_NAME);
    assert prj != null;
    assertEquals("Invalid projection: " + prj.nodes(), 1, prj.nodes().size());
    assert prj.nodes().contains(grid(1).localNode());
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 92 with ClusterGroup

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

the class ClusterGroupAbstractTest method testInvalidProjection.

/**
 * Test for projection on not existing node IDs.
 */
@Test
public void testInvalidProjection() {
    Collection<UUID> ids = new HashSet<>();
    ids.add(UUID.randomUUID());
    ids.add(UUID.randomUUID());
    ClusterGroup invalidPrj = prj.forNodeIds(ids);
    assertEquals(0, invalidPrj.nodes().size());
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) UUID(java.util.UUID) HashSet(java.util.HashSet) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 93 with ClusterGroup

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

the class ClusterGroupAbstractTest method testRemoteProjection.

/**
 * @throws Exception If test failed.
 */
@Test
public void testRemoteProjection() throws Exception {
    Collection<UUID> remoteNodeIds = remoteNodeIds();
    ClusterGroup remotePrj = projection().forRemotes();
    Collection<UUID> prjNodeIds = F.nodeIds(remotePrj.nodes());
    assert prjNodeIds.size() == remoteNodeIds.size();
    assert prjNodeIds.containsAll(remoteNodeIds());
    assert !prjNodeIds.contains(localNodeId());
    String name = "oneMoreGrid";
    try {
        Ignite g = startGrid(name);
        UUID excludedId = g.cluster().localNode().id();
        assert !F.nodeIds(remotePrj.nodes()).contains(excludedId);
    } finally {
        stopGrid(name);
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 94 with ClusterGroup

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

the class ClusterGroupSelfTest method testYoungest.

/**
 * @throws Exception If failed.
 */
@Test
public void testYoungest() throws Exception {
    IgniteCluster cluster = ignite.cluster();
    ClusterGroup youngest = cluster.forYoungest();
    ClusterNode youngestNode = grid(NODES_CNT - 1).localNode();
    assertEquals(cluster.forNode(youngestNode).node(), youngest.node());
    assertEqualsCollections(singleton(cluster.forNode(youngestNode).node()), cluster.nodes().stream().filter(youngest.predicate()::apply).collect(Collectors.toSet()));
    stopGrid(NODES_CNT - 1);
    try {
        ClusterNode newYoungestNode = grid(NODES_CNT - 2).localNode();
        assertEquals(cluster.forNode(newYoungestNode).node(), youngest.node());
        assertEqualsCollections(singleton(cluster.forNode(newYoungestNode).node()), cluster.nodes().stream().filter(youngest.predicate()::apply).collect(Collectors.toSet()));
    } finally {
        startClientGrid(NODES_CNT - 1);
    }
    ClusterGroup emptyGrp = cluster.forAttribute("nonExistent", "val");
    assertEquals(0, emptyGrp.forYoungest().nodes().size());
    try (Ignite ignore = startGrid(NODES_CNT)) {
        ClusterNode newYoungestNode = grid(NODES_CNT).localNode();
        assertEquals(cluster.forNode(newYoungestNode).node(), youngest.node());
        assertEqualsCollections(singleton(cluster.forNode(newYoungestNode).node()), cluster.nodes().stream().filter(youngest.predicate()::apply).collect(Collectors.toSet()));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCluster(org.apache.ignite.IgniteCluster) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Example 95 with ClusterGroup

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

the class ClusterNodeMetricsUpdateTest method checkMetrics0.

/**
 * @param expNodes Expected nodes.
 * @param expJobs Expected jobs number per node.
 */
private void checkMetrics0(int expNodes, Map<UUID, Integer> expJobs) {
    List<Ignite> nodes = Ignition.allGrids();
    assertEquals(expNodes, nodes.size());
    assertEquals(expNodes, expJobs.size());
    int totalJobs = 0;
    for (Integer c : expJobs.values()) totalJobs += c;
    for (final Ignite ignite : nodes) {
        ClusterMetrics m = ignite.cluster().metrics();
        assertEquals(expNodes, m.getTotalNodes());
        assertEquals(totalJobs, m.getTotalExecutedJobs());
        for (Map.Entry<UUID, Integer> e : expJobs.entrySet()) {
            UUID nodeId = e.getKey();
            ClusterGroup g = ignite.cluster().forNodeId(nodeId);
            ClusterMetrics nodeM = g.metrics();
            assertEquals(e.getValue(), (Integer) nodeM.getTotalExecutedJobs());
        }
    }
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

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