Search in sources :

Example 21 with IConnection

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

the class NettyUnitTest method test_pending_read_server.

@Test
public void test_pending_read_server() {
    System.out.println("!!!!!!!! Start test_pending_read_server !!!!!!!!!!!");
    final String req_msg = "Aloha is the most Hawaiian word.";
    final IConnection server;
    final IConnection client;
    server = initNettyServer();
    client = context.connect(null, "localhost", port);
    JStormUtils.sleepMs(1000);
    List<TaskMessage> list = new ArrayList<TaskMessage>();
    TaskMessage message = new TaskMessage(task, req_msg.getBytes());
    list.add(message);
    NettyServer nServer = (NettyServer) server;
    StormChannelGroup channleGroup = nServer.getChannelGroup();
    String remoteAddress = channleGroup.getAllRemoteAddress().iterator().next();
    System.out.println("!!!!!!!!!!!!!!!!!! All remoteAddress: " + channleGroup.getAllRemoteAddress() + " !!!!!!!!!!!!!!!!!!");
    channleGroup.suspendChannel(remoteAddress);
    System.out.println("!!!!!!!!!!!!!!!!!! Suspend netty channel=" + remoteAddress + " !!!!!!!!!!!!!!!!!!");
    client.send(message);
    final List<String> recvMsg = new ArrayList<String>();
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            System.out.println("!!!!!!!!!!!!!!!!!! Start to receive msg !!!!!!!!!!!!!!!!!");
            byte[] recv = (byte[]) server.recv(task, 0);
            Assert.assertEquals(req_msg, new String(recv));
            recvMsg.add(new String(recv));
            System.out.println("!!!!!!!!!!!!!!!!!! Finish to receive msg !!!!!!!!!!!!!!!!!!");
        }
    });
    thread.start();
    JStormUtils.sleepMs(1000);
    Assert.assertEquals(true, recvMsg.size() == 0);
    System.out.println("!!!!!!!!!!!!!!!!!! Resume channel=" + remoteAddress + " !!!!!!!!!!!!!!!!!!");
    channleGroup.resumeChannel(remoteAddress);
    JStormUtils.sleepMs(1000);
    try {
        thread.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("!!!!!!!!!!!!!!!!!! Recv Msg=" + recvMsg + " !!!!!!!!!!!!!!!!!!");
    Assert.assertEquals(true, recvMsg.size() == 1);
    Assert.assertEquals(req_msg, recvMsg.get(0));
    server.close();
    client.close();
    System.out.println("!!!!!!!!!!!! End test_pending_read_server !!!!!!!!!!!!!");
}
Also used : IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 22 with IConnection

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

the class NettyUnitTest method test_server_delay.

@Test
public void test_server_delay() {
    System.out.println("!!!!!!!!!!Start delay message test!!!!!!!!");
    String req_msg = setupLargMsg();
    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);
    LOG.info("Client send data");
    client.send(message);
    JStormUtils.sleepMs(1000);
    byte[] recv = (byte[]) server.recv(task, 0);
    Assert.assertEquals(req_msg, new String(recv));
    server.close();
    client.close();
    System.out.println("!!!!!!!!!!End delay message test!!!!!!!!");
}
Also used : IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 23 with IConnection

use of backtype.storm.messaging.IConnection 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)

Example 24 with IConnection

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

the class TaskTransfer method getConnection.

protected IConnection getConnection(int taskId) {
    IConnection conn = null;
    WorkerSlot nodePort = taskToNodePort.get(taskId);
    if (nodePort == null) {
        String errorMsg = "IConnection to task-" + taskId + " can't be found";
        LOG.warn("Internal transfer error: {}", errorMsg);
    } else {
        conn = nodePortToSocket.get(nodePort);
        if (conn == null) {
            String errorMsg = "NodePort to" + nodePort + " can't be found";
            LOG.warn("Internal transfer error: {}", errorMsg);
        }
    }
    return conn;
}
Also used : WorkerSlot(backtype.storm.scheduler.WorkerSlot) IConnection(backtype.storm.messaging.IConnection)

Example 25 with IConnection

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

the class BaseExecutors method getConnection.

protected IConnection getConnection(int taskId) {
    IConnection conn = null;
    WorkerSlot nodePort = task.getTaskToNodePort().get(taskId);
    if (nodePort != null) {
        conn = task.getNodePortToSocket().get(nodePort);
    }
    return conn;
}
Also used : WorkerSlot(backtype.storm.scheduler.WorkerSlot) IConnection(backtype.storm.messaging.IConnection)

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