Search in sources :

Example 6 with IConnection

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

the class TaskTransfer method serialize.

protected void serialize(KryoTupleSerializer serializer, Object event) {
    long start = serializeTimer.getTime();
    try {
        ITupleExt tuple = (ITupleExt) event;
        int targetTaskId = tuple.getTargetTaskId();
        IConnection conn = getConnection(targetTaskId);
        if (conn != null) {
            byte[] tupleMessage = serializer.serialize((TupleExt) tuple);
            // LOG.info("Task-{} sent msg to task-{}, data={}", task.getTaskId(), taskid,
            // JStormUtils.toPrintableString(tupleMessage));
            TaskMessage taskMessage = new TaskMessage(taskId, targetTaskId, tupleMessage);
            conn.send(taskMessage);
        } else {
            LOG.error("Can not find connection for task-{}", targetTaskId);
        }
    } finally {
        if (MetricUtils.metricAccurateCal) {
            serializeTimer.updateTime(start);
        }
    }
}
Also used : IConnection(backtype.storm.messaging.IConnection) ITupleExt(backtype.storm.tuple.ITupleExt) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 7 with IConnection

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

the class NettyUnitTest method test_slow_receive_big.

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

        @Override
        public void run() {
            final IConnection client = context.connect(null, "localhost", port);
            lock.lock();
            for (int i = 1; i < base; i++) {
                TaskMessage message = new TaskMessage(task, req_msg.getBytes());
                System.out.println("send " + i);
                client.send(message);
            }
            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();
            lock.unlock();
        }
    }).start();
    for (int i = 1; i < base; i++) {
        byte[] message = (byte[]) server.recv(task, 0);
        JStormUtils.sleepMs(100);
        Assert.assertEquals(req_msg, new String(message));
        System.out.println("receive msg-" + i);
    }
    System.out.println("Finish Receive ");
    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_slow_receive_big message test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 8 with IConnection

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

the class NettyUnitTest method test_small_message.

@Test
public void test_small_message() {
    System.out.println("!!!!!!!!Start test_small_message !!!!!!!!!!!");
    String req_msg = "Aloha is the most Hawaiian word.";
    IConnection server = null;
    IConnection client = null;
    server = initNettyServer();
    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);
    byte[] recv = (byte[]) server.recv(task, 0);
    Assert.assertEquals(req_msg, new String(recv));
    System.out.println("!!!!!!!!!!!!!!!!!!Test one time!!!!!!!!!!!!!!!!!");
    server.close();
    client.close();
    System.out.println("!!!!!!!!!!!!End test_small_message!!!!!!!!!!!!!");
}
Also used : IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 9 with IConnection

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

the class NettyUnitTest method test_server_reboot.

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

        @Override
        public void run() {
            final IConnection client = context.connect(null, "localhost", port);
            lock.lock();
            List<TaskMessage> list = new ArrayList<TaskMessage>();
            TaskMessage message = new TaskMessage(task, req_msg.getBytes());
            list.add(message);
            client.send(message);
            System.out.println("Send first");
            JStormUtils.sleepMs(10000);
            System.out.println("Begin to Send second");
            client.send(message);
            System.out.println("Send second");
            JStormUtils.sleepMs(15000);
            client.send(message);
            System.out.println("Send third time");
            try {
                clientClose.await();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            client.close();
            contextClose.signal();
            lock.unlock();
        }
    }).start();
    server = initNettyServer();
    byte[] recv = (byte[]) server.recv(task, 0);
    System.out.println("Receive first");
    Assert.assertEquals(req_msg, new String(recv));
    server.close();
    System.out.println("!!shutdow server and sleep 30s, please wait!!");
    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    IConnection server2 = server = initNettyServer();
    System.out.println("!!!!!!!!!!!!!!!!!!!! restart server !!!!!!!!!!!");
    byte[] recv2 = (byte[]) server2.recv(task, 0);
    Assert.assertEquals(req_msg, new String(recv2));
    lock.lock();
    try {
        clientClose.signal();
        server2.close();
        try {
            contextClose.await();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        context.term();
    } finally {
        lock.unlock();
    }
    System.out.println("!!!!!!!!!!End server reboot test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 10 with IConnection

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

the class NettyUnitTest method test_msg_buffer_timeout.

@Test
public void test_msg_buffer_timeout() {
    System.out.println("!!!!!!!!Start test_msg_buffer_timeout !!!!!!!!!!!");
    final String req_msg = setupLargMsg();
    ConfigExtension.setNettyPendingBufferTimeout(storm_conf, 5 * 1000l);
    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(15000);
    System.out.println("!!server begin start!!!!!");
    server = initNettyServer();
    JStormUtils.sleepMs(5000);
    byte[] recv = (byte[]) server.recv(task, 1);
    System.out.println("Begin to receive message. recv message size: " + (recv == null ? 0 : recv.length));
    Assert.assertEquals(null, recv);
    System.out.println("Pending message was timouout:" + (recv == null));
    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();
    }
    ConfigExtension.setNettyPendingBufferTimeout(storm_conf, 60 * 1000l);
    System.out.println("!!!!!!!!!!!!End test_msg_buffer_timeout!!!!!!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Aggregations

IConnection (backtype.storm.messaging.IConnection)25 TaskMessage (backtype.storm.messaging.TaskMessage)15 Test (org.junit.Test)12 IContext (backtype.storm.messaging.IContext)8 WorkerSlot (backtype.storm.scheduler.WorkerSlot)6 DisruptorQueue (backtype.storm.utils.DisruptorQueue)3 ITupleExt (backtype.storm.tuple.ITupleExt)2 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)2 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)2 WaitStrategy (com.lmax.disruptor.WaitStrategy)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 Assignment (com.alibaba.jstorm.schedule.Assignment)1 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)1 TaskShutdownDameon (com.alibaba.jstorm.task.TaskShutdownDameon)1 KryoException (com.esotericsoftware.kryo.KryoException)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1