Search in sources :

Example 76 with ClusterGroup

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

the class GridMessagingSelfTest method testRemoteListenOrderedMessages.

/**
 * Tests simple message sending-receiving with the use of
 * remoteListen() method.
 *
 * @throws Exception If error occurs.
 */
@Test
public void testRemoteListenOrderedMessages() throws Exception {
    List<TestMessage> msgs = Arrays.asList(new TestMessage(MSG_1), new TestMessage(MSG_2, 3000), new TestMessage(MSG_3));
    final Collection<Object> rcvMsgs = new ConcurrentLinkedDeque<>();
    // to make it modifiable
    final AtomicBoolean error = new AtomicBoolean(false);
    rcvLatch = new CountDownLatch(3);
    ignite2.message().remoteListen(S_TOPIC_1, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            try {
                log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
                if (!nodeId.equals(ignite1.cluster().localNode().id())) {
                    log.error("Unexpected sender node: " + nodeId);
                    error.set(true);
                    return false;
                }
                rcvMsgs.add(msg);
                return true;
            } finally {
                rcvLatch.countDown();
            }
        }
    });
    // Includes node from grid2.
    ClusterGroup prj2 = ignite1.cluster().forRemotes();
    for (TestMessage msg : msgs) message(prj2).sendOrdered(S_TOPIC_1, msg, 15000);
    assertTrue(rcvLatch.await(6, TimeUnit.SECONDS));
    assertFalse(error.get());
    assertEquals(msgs, Arrays.asList(rcvMsgs.toArray()));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 77 with ClusterGroup

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

the class IgniteMessagingWithClientTest method testMessageSendWithClientJoin.

/**
 * @throws Exception If failed.
 */
@Test
public void testMessageSendWithClientJoin() throws Exception {
    startGrid(0);
    Ignite ignite1 = startGrid(1);
    ClusterGroup rmts = ignite1.cluster().forRemotes();
    IgniteMessaging msg = ignite1.message(rmts);
    msg.localListen(TOPIC.ORDERED, new LocalListener());
    msg.remoteListen(TOPIC.ORDERED, new RemoteListener());
    final AtomicBoolean stop = new AtomicBoolean();
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            int iter = 0;
            while (!stop.get()) {
                if (iter % 10 == 0)
                    log.info("Client start/stop iteration: " + iter);
                iter++;
                try (Ignite ignite = startClientGrid(2)) {
                    assertTrue(ignite.configuration().isClientMode());
                }
            }
            return null;
        }
    }, 1, "client-start-stop");
    try {
        long stopTime = U.currentTimeMillis() + 30_000;
        int iter = 0;
        while (System.currentTimeMillis() < stopTime) {
            try {
                ignite1.message(rmts).sendOrdered(TOPIC.ORDERED, Integer.toString(iter), 0);
            } catch (IgniteException e) {
                log.info("Message send failed: " + e);
            }
            iter++;
            if (iter % 100 == 0)
                Thread.sleep(5);
        }
    } finally {
        stop.set(true);
    }
    fut.get();
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteMessaging(org.apache.ignite.IgniteMessaging) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 78 with ClusterGroup

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

the class GridMarshallerAbstractTest method testMessaging.

/**
 * @throws Exception If failed.
 */
@Test
public void testMessaging() throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration("g1"));
    try (Ignite g1 = G.start(cfg)) {
        IgniteMessaging messaging = message(grid().cluster().forNode(g1.cluster().localNode()));
        messaging.send(null, "test");
        GridMarshallerTestBean inBean = newTestBean(messaging);
        byte[] buf = marshal(inBean);
        GridMarshallerTestBean outBean = unmarshal(buf);
        assert inBean.getObjectField() != null;
        assert outBean.getObjectField() != null;
        assert inBean.getObjectField().getClass().equals(IgniteMessagingImpl.class);
        assert outBean.getObjectField().getClass().equals(IgniteMessagingImpl.class);
        assert inBean != outBean;
        assert inBean.equals(outBean);
        ClusterGroup inPrj = messaging.clusterGroup();
        ClusterGroup outPrj = ((IgniteMessaging) outBean.getObjectField()).clusterGroup();
        assert inPrj.getClass().equals(outPrj.getClass());
        assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
        outBean.checkNullResources();
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteMessaging(org.apache.ignite.IgniteMessaging) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 79 with ClusterGroup

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

the class GridMarshallerAbstractTest method testEvents.

/**
 * @throws Exception If failed.
 */
@Test
public void testEvents() throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration("g1"));
    try (Ignite g1 = G.start(cfg)) {
        IgniteEvents evts = events(grid().cluster().forNode(g1.cluster().localNode()));
        evts.localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event gridEvt) {
                return true;
            }
        }, EVTS_CACHE);
        grid().cache(DEFAULT_CACHE_NAME).put(1, 1);
        GridMarshallerTestBean inBean = newTestBean(evts);
        byte[] buf = marshal(inBean);
        GridMarshallerTestBean outBean = unmarshal(buf);
        assert inBean.getObjectField() != null;
        assert outBean.getObjectField() != null;
        assert inBean.getObjectField().getClass().equals(IgniteEventsImpl.class);
        assert outBean.getObjectField().getClass().equals(IgniteEventsImpl.class);
        assert inBean != outBean;
        assert inBean.equals(outBean);
        ClusterGroup inPrj = evts.clusterGroup();
        ClusterGroup outPrj = ((IgniteEvents) outBean.getObjectField()).clusterGroup();
        assert inPrj.getClass().equals(outPrj.getClass());
        assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
        outBean.checkNullResources();
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEvents(org.apache.ignite.IgniteEvents) Event(org.apache.ignite.events.Event) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 80 with ClusterGroup

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

the class GridMarshallerAbstractTest method testCompute.

/**
 * @throws Exception If failed.
 */
@Test
public void testCompute() throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration("g1"));
    try (Ignite g1 = G.start(cfg)) {
        IgniteCompute compute = compute(grid().cluster().forNode(g1.cluster().localNode()));
        compute.run(new IgniteRunnable() {

            @Override
            public void run() {
            // No-op.
            }
        });
        GridMarshallerTestBean inBean = newTestBean(compute);
        byte[] buf = marshal(inBean);
        GridMarshallerTestBean outBean = unmarshal(buf);
        assert inBean.getObjectField() != null;
        assert outBean.getObjectField() != null;
        assert inBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
        assert outBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
        assert inBean != outBean;
        assert inBean.equals(outBean);
        ClusterGroup inPrj = compute.clusterGroup();
        ClusterGroup outPrj = ((IgniteCompute) outBean.getObjectField()).clusterGroup();
        assert inPrj.getClass().equals(outPrj.getClass());
        assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
        outBean.checkNullResources();
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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