Search in sources :

Example 11 with IContext

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

the class NettyUnitTest method test_batch.

@Test
public void test_batch() {
    System.out.println("!!!!!!!!!!Start batch message test!!!!!!!!");
    final int base = 100000;
    final IContext context = TransportFactory.makeContext(storm_conf);
    final IConnection server = initNettyServer();
    new Thread(new Runnable() {

        public void send() {
            final IConnection client = context.connect(null, "localhost", port);
            List<TaskMessage> list = new ArrayList<TaskMessage>();
            for (int i = 1; i < Short.MAX_VALUE; i++) {
                String req_msg = String.valueOf(i + base);
                TaskMessage message = new TaskMessage(task, req_msg.getBytes());
                list.add(message);
            }
            client.send(list);
            System.out.println("Finish Send ");
            JStormUtils.sleepMs(1000);
            try {
                clientClose.await();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            client.close();
            contextClose.signal();
        }

        @Override
        public void run() {
            lock.lock();
            try {
                send();
            } finally {
                lock.unlock();
            }
        }
    }).start();
    for (int i = 1; i < Short.MAX_VALUE; i++) {
        byte[] message = (byte[]) server.recv(task, 0);
        Assert.assertEquals(String.valueOf(i + base), new String(message));
        if (i % 1000 == 0) {
        // System.out.println("Receive " + new String(message));
        }
    }
    System.out.println("Finish Receive ");
    lock.lock();
    try {
        clientClose.signal();
        server.close();
        try {
            contextClose.await();
        } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        }
        context.term();
    } finally {
        lock.unlock();
    }
    System.out.println("!!!!!!!!!!End batch message test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Aggregations

IContext (backtype.storm.messaging.IContext)11 IConnection (backtype.storm.messaging.IConnection)8 Test (org.junit.Test)8 TaskMessage (backtype.storm.messaging.TaskMessage)7 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DisruptorQueue (backtype.storm.utils.DisruptorQueue)1 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 DefaultInimbus (com.alibaba.jstorm.daemon.nimbus.DefaultInimbus)1 NimbusServer (com.alibaba.jstorm.daemon.nimbus.NimbusServer)1 Supervisor (com.alibaba.jstorm.daemon.supervisor.Supervisor)1 NettyContext (com.alibaba.jstorm.message.netty.NettyContext)1 Factory (com.alibaba.jstorm.zk.Factory)1 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)1 WaitStrategy (com.lmax.disruptor.WaitStrategy)1 ArrayList (java.util.ArrayList)1 LoggerFactory (org.slf4j.LoggerFactory)1