Search in sources :

Example 31 with TaskMessage

use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.

the class NettyUnitTest method test_first_client.

@Test
public void test_first_client() {
    System.out.println("!!!!!!!!Start test_first_client !!!!!!!!!!!");
    final String req_msg = setupLargMsg();
    final IContext context = TransportFactory.makeContext(storm_conf);
    new Thread(new Runnable() {

        @Override
        public void run() {
            lock.lock();
            IConnection client = context.connect(null, "localhost", port);
            List<TaskMessage> list = new ArrayList<TaskMessage>();
            TaskMessage message = new TaskMessage(task, req_msg.getBytes());
            list.add(message);
            client.send(message);
            System.out.println("!!Client has sent data");
            JStormUtils.sleepMs(1000);
            try {
                clientClose.await();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            client.close();
            contextClose.signal();
            lock.unlock();
        }
    }).start();
    IConnection server = null;
    JStormUtils.sleepMs(1000);
    System.out.println("!!server begin start!!!!!");
    server = initNettyServer();
    JStormUtils.sleepMs(5000);
    System.out.println("Begin to receive message");
    byte[] recv = (byte[]) server.recv(task, 1);
    Assert.assertEquals(req_msg, new String(recv));
    System.out.println("Finished to receive message");
    lock.lock();
    try {
        clientClose.signal();
        server.close();
        try {
            contextClose.await();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        context.term();
    } finally {
        lock.unlock();
    }
    System.out.println("!!!!!!!!!!!!End test_first_client!!!!!!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Aggregations

TaskMessage (backtype.storm.messaging.TaskMessage)31 IConnection (backtype.storm.messaging.IConnection)15 Test (org.junit.Test)12 IContext (backtype.storm.messaging.IContext)7 ControlMessage (backtype.storm.messaging.ControlMessage)4 ByteBuffer (java.nio.ByteBuffer)4 ITupleExt (backtype.storm.tuple.ITupleExt)2 KryoException (com.esotericsoftware.kryo.KryoException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 ChannelBufferOutputStream (org.jboss.netty.buffer.ChannelBufferOutputStream)2 DisruptorQueue (backtype.storm.utils.DisruptorQueue)1 AsmHistogram (com.alibaba.jstorm.common.metric.AsmHistogram)1 Iterator (java.util.Iterator)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Channel (org.jboss.netty.channel.Channel)1