Search in sources :

Example 6 with IContext

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

the class NettyUnitTest method test_client_reboot.

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

        @Override
        public void run() {
            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");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            client.close();
            IConnection client2 = context.connect(null, "localhost", port);
            System.out.println("!!!!!!! restart client !!!!!!!!!!");
            client2.send(message);
            System.out.println("Send second");
            JStormUtils.sleepMs(1000);
            try {
                clientClose.await();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            client2.close();
            contextClose.signal();
            lock.unlock();
        }
    }).start();
    IConnection server = initNettyServer();
    byte[] recv = (byte[]) server.recv(task, 0);
    System.out.println("Sever receive first");
    Assert.assertEquals(req_msg, new String(recv));
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    byte[] recv2 = (byte[]) server.recv(task, 0);
    System.out.println("Sever receive second");
    Assert.assertEquals(req_msg, new String(recv2));
    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 client reboot test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 7 with IContext

use of backtype.storm.messaging.IContext 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(7000);
    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)

Example 8 with IContext

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

the class LocalUtils method getLocalContext.

private static IContext getLocalContext(Map conf) {
    if (!(Boolean) conf.get(Config.STORM_LOCAL_MODE_ZMQ)) {
        IContext result = new NettyContext();
        ConfigExtension.setLocalWorkerPort(conf, 6800);
        result.prepare(conf);
        return result;
    }
    return null;
}
Also used : IContext(backtype.storm.messaging.IContext) NettyContext(com.alibaba.jstorm.message.netty.NettyContext)

Example 9 with IContext

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

the class Worker method startDispatchThread.

private AsyncLoopThread startDispatchThread() {
    // send tuple directly from netty server
    // send control tuple to dispatch thread
    // startDispatchDisruptor();
    IContext context = workerData.getContext();
    String topologyId = workerData.getTopologyId();
    //create recv connection
    Map stormConf = workerData.getStormConf();
    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
    //metric for recvControlQueue
    QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
    IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskids());
    workerData.setRecvConnection(recvConnection);
    // create recvice control messages's thread
    RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
    return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
Also used : IContext(backtype.storm.messaging.IContext) DisruptorQueue(backtype.storm.utils.DisruptorQueue) IConnection(backtype.storm.messaging.IConnection) RunnableCallback(com.alibaba.jstorm.callback.RunnableCallback) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy)

Example 10 with IContext

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

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