Search in sources :

Example 6 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging 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 7 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging 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 8 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method testDataExchangeFromServer2.

/**
 * @throws Exception If failed.
 */
@Test
public void testDataExchangeFromServer2() throws Exception {
    startServerNodes(2);
    IgniteMessaging msg = grid("server-1").message();
    UUID id = msg.remoteListen(null, new MessageListener());
    try {
        startClientNodes(1);
        assertEquals(G.ignite("server-0").cluster().localNode().id(), ((TcpDiscoveryNode) G.ignite("client-0").cluster().localNode()).clientRouterNodeId());
        checkNodes(2, 1);
        msgLatch = new CountDownLatch(3);
        msg.send(null, "Message");
        await(msgLatch);
    } finally {
        msg.stopRemoteListen(id);
    }
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method testDataExchange.

/**
 * @param masterName Node name
 * @throws Exception If failed.
 */
private void testDataExchange(String masterName) throws Exception {
    startServerNodes(2);
    startClientNodes(2);
    checkNodes(2, 2);
    IgniteMessaging msg = grid(masterName).message();
    UUID id = msg.remoteListen(null, new MessageListener());
    try {
        msgLatch = new CountDownLatch(2);
        msg.send(null, "Message 1");
        await(msgLatch);
        startServerNodes(1);
        startClientNodes(1);
        checkNodes(3, 3);
        msgLatch = new CountDownLatch(3);
        msg.send(null, "Message 2");
        await(msgLatch);
    } finally {
        msg.stopRemoteListen(id);
    }
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project ignite by apache.

the class GridCacheReplicatedPreloadSelfTest method testExternalClassesAtMessage.

/**
 * @throws Exception If test failed.
 */
@Test
public void testExternalClassesAtMessage() throws Exception {
    try {
        useExtClassLoader = true;
        disableP2p = true;
        final Class cls = (Class) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentExternalizableTestValue");
        Ignite g1 = startGrid(1);
        startGrid(2);
        IgniteMessaging rmtMsg = g1.message();
        latch = new CountDownLatch(2);
        rmtMsg.remoteListen("MyOrderedTopic", new MessageListener());
        Object o = cls.newInstance();
        o.toString();
        rmtMsg.send("MyOrderedTopic", o);
        rmtMsg.sendOrdered("MyOrderedTopic", o, 0);
        latch.await();
        // Custom topic.
        final Class cls2 = (Class) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestEnumValue");
        Object topic = cls2.getEnumConstants()[0];
        latch = new CountDownLatch(2);
        rmtMsg.remoteListen(topic, new MessageListener());
        rmtMsg.send(topic, topic);
        rmtMsg.sendOrdered(topic, topic, 0);
        latch.await();
    } finally {
        useExtClassLoader = false;
        disableP2p = false;
    }
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteMessaging (org.apache.ignite.IgniteMessaging)12 UUID (java.util.UUID)7 Ignite (org.apache.ignite.Ignite)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)3 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 Externalizable (java.io.Externalizable)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 AccessControlException (java.security.AccessControlException)1 Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1