Search in sources :

Example 11 with ClusterGroup

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

the class ClusterGroupSelfTest method testAgeClusterGroupSerialization.

/**
     * @throws Exception If failed.
     */
public void testAgeClusterGroupSerialization() throws Exception {
    Marshaller marshaller = ignite.configuration().getMarshaller();
    ClusterGroup grp = ignite.cluster().forYoungest();
    ClusterNode node = grp.node();
    byte[] arr = marshaller.marshal(grp);
    ClusterGroup obj = marshaller.unmarshal(arr, null);
    assertEquals(node.id(), obj.node().id());
    try (Ignite ignore = startGrid()) {
        obj = marshaller.unmarshal(arr, null);
        assertEquals(grp.node().id(), obj.node().id());
        assertFalse(node.id().equals(obj.node().id()));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Marshaller(org.apache.ignite.marshaller.Marshaller) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 12 with ClusterGroup

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

the class ClusterGroupSelfTest method testNewNodes.

/**
     * @throws Exception If failed.
     */
public void testNewNodes() throws Exception {
    ClusterGroup youngest = ignite.cluster().forYoungest();
    ClusterGroup oldest = ignite.cluster().forOldest();
    ClusterNode old = oldest.node();
    ClusterNode last = youngest.node();
    assertNotNull(last);
    try (Ignite g = startGrid(NODES_CNT)) {
        ClusterNode n = g.cluster().localNode();
        ClusterNode latest = youngest.node();
        assertNotNull(latest);
        assertEquals(latest.id(), n.id());
        assertEquals(oldest.node(), old);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 13 with ClusterGroup

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

the class ClusterGroupSelfTest method testForPredicate.

/**
     * @throws Exception If failed.
     */
public void testForPredicate() throws Exception {
    IgnitePredicate<ClusterNode> evenP = new IgnitePredicate<ClusterNode>() {

        @Override
        public boolean apply(ClusterNode node) {
            return node.order() % 2 == 0;
        }
    };
    IgnitePredicate<ClusterNode> oddP = new IgnitePredicate<ClusterNode>() {

        @Override
        public boolean apply(ClusterNode node) {
            return node.order() % 2 == 1;
        }
    };
    ClusterGroup remotes = ignite.cluster().forRemotes();
    ClusterGroup evenYoungest = remotes.forPredicate(evenP).forYoungest();
    ClusterGroup evenOldest = remotes.forPredicate(evenP).forOldest();
    ClusterGroup oddYoungest = remotes.forPredicate(oddP).forYoungest();
    ClusterGroup oddOldest = remotes.forPredicate(oddP).forOldest();
    int clusterSize = ignite.cluster().nodes().size();
    assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id());
    assertEquals(grid(1).localNode().id(), evenOldest.node().id());
    assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id());
    assertEquals(grid(2).localNode().id(), oddOldest.node().id());
    try (Ignite g4 = startGrid(NODES_CNT);
        Ignite g5 = startGrid(NODES_CNT + 1)) {
        clusterSize = g4.cluster().nodes().size();
        assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id());
        assertEquals(grid(1).localNode().id(), evenOldest.node().id());
        assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id());
        assertEquals(grid(2).localNode().id(), oddOldest.node().id());
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 14 with ClusterGroup

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

the class ClusterGroupSelfTest method testEmptyGroup.

/**
     * @throws Exception If failed.
     */
public void testEmptyGroup() throws Exception {
    ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val");
    assertEquals(0, emptyGrp.forOldest().nodes().size());
    assertEquals(0, emptyGrp.forYoungest().nodes().size());
    assertEquals(0, emptyGrp.forAttribute("nonExistent2", "val").nodes().size());
    assertEquals(0, emptyGrp.forCacheNodes("cacheName").nodes().size());
    assertEquals(0, emptyGrp.forClientNodes("cacheName").nodes().size());
    assertEquals(0, emptyGrp.forClients().nodes().size());
    assertEquals(0, emptyGrp.forDaemons().nodes().size());
    assertEquals(0, emptyGrp.forDataNodes("cacheName").nodes().size());
    assertEquals(0, emptyGrp.forRandom().nodes().size());
    assertEquals(0, emptyGrp.forRemotes().nodes().size());
    assertEquals(0, emptyGrp.forServers().nodes().size());
    assertEquals(0, emptyGrp.forHost(ignite.cluster().localNode()).nodes().size());
    assertEquals(0, emptyGrp.forHost("127.0.0.1").nodes().size());
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 15 with ClusterGroup

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

the class ServicePredicateAccessCacheTest method testPredicateAccessCache.

/**
     * @throws Exception If failed.
     */
public void testPredicateAccessCache() throws Exception {
    final Ignite ignite0 = startGrid(0);
    ignite0.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setName("testCache").setAtomicityMode(ATOMIC).setCacheMode(REPLICATED).setWriteSynchronizationMode(FULL_SYNC));
    latch = new CountDownLatch(1);
    final ClusterGroup grp = ignite0.cluster().forPredicate(new IgnitePredicate<ClusterNode>() {

        @Override
        public boolean apply(ClusterNode node) {
            System.out.println("Predicated started [thread=" + Thread.currentThread().getName() + ']');
            latch.countDown();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException ignore) {
            // No-op.
            }
            System.out.println("Call contains key [thread=" + Thread.currentThread().getName() + ']');
            boolean ret = Ignition.localIgnite().cache("testCache").containsKey(node.id().toString());
            System.out.println("After contains key [ret=" + ret + ", thread=" + Thread.currentThread().getName() + ']');
            return ret;
        }
    });
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            info("Start deploy service.");
            ignite0.services(grp).deployNodeSingleton("testService", new TestService());
            info("Service deployed.");
            return null;
        }
    }, "deploy-thread");
    latch.await();
    startGrid(1);
    fut.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Ignite(org.apache.ignite.Ignite)

Aggregations

ClusterGroup (org.apache.ignite.cluster.ClusterGroup)80 Ignite (org.apache.ignite.Ignite)42 UUID (java.util.UUID)21 CountDownLatch (java.util.concurrent.CountDownLatch)16 ClusterNode (org.apache.ignite.cluster.ClusterNode)14 IgniteException (org.apache.ignite.IgniteException)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IgniteCompute (org.apache.ignite.IgniteCompute)5 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)5 ArrayList (java.util.ArrayList)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 List (java.util.List)2 CacheException (javax.cache.CacheException)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 IgniteCluster (org.apache.ignite.IgniteCluster)2