Search in sources :

Example 1 with IContext

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

the class LocalUtils method prepareLocalCluster.

public static LocalClusterMap prepareLocalCluster() {
    LocalClusterMap state = new LocalClusterMap();
    try {
        List<String> tmpDirs = new ArrayList();
        String zkDir = getTmpDir();
        tmpDirs.add(zkDir);
        Factory zookeeper = startLocalZookeeper(zkDir);
        Map conf = getLocalConf(zookeeper.getZooKeeperServer().getClientPort());
        String nimbusDir = getTmpDir();
        tmpDirs.add(nimbusDir);
        Map nimbusConf = deepCopyMap(conf);
        nimbusConf.put(Config.STORM_LOCAL_DIR, nimbusDir);
        NimbusServer instance = new NimbusServer();
        Map supervisorConf = deepCopyMap(conf);
        String supervisorDir = getTmpDir();
        tmpDirs.add(supervisorDir);
        supervisorConf.put(Config.STORM_LOCAL_DIR, supervisorDir);
        Supervisor supervisor = new Supervisor();
        IContext context = getLocalContext(supervisorConf);
        state.setNimbusServer(instance);
        state.setNimbus(instance.launcherLocalServer(nimbusConf, new DefaultInimbus()));
        state.setZookeeper(zookeeper);
        state.setConf(conf);
        state.setTmpDir(tmpDirs);
        state.setSupervisor(supervisor.mkSupervisor(supervisorConf, context));
        return state;
    } catch (Exception e) {
        LOG.error("prepare cluster error!", e);
        state.clean();
    }
    return null;
}
Also used : Supervisor(com.alibaba.jstorm.daemon.supervisor.Supervisor) NimbusServer(com.alibaba.jstorm.daemon.nimbus.NimbusServer) IContext(backtype.storm.messaging.IContext) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) Factory(com.alibaba.jstorm.zk.Factory) HashMap(java.util.HashMap) Map(java.util.Map) DefaultInimbus(com.alibaba.jstorm.daemon.nimbus.DefaultInimbus)

Example 2 with IContext

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

the class ContextTest method test_netty.

@Test
public void test_netty() {
    Map storm_conf = Maps.newHashMap();
    storm_conf.put(Config.STORM_MESSAGING_TRANSPORT, "com.alibaba.jstorm.message.netty.NettyContext");
    storm_conf.put(Config.STORM_MESSAGING_NETTY_BUFFER_SIZE, 1024);
    storm_conf.put(Config.STORM_MESSAGING_NETTY_MAX_RETRIES, 10);
    storm_conf.put(Config.STORM_MESSAGING_NETTY_MIN_SLEEP_MS, 1000);
    storm_conf.put(Config.STORM_MESSAGING_NETTY_MAX_SLEEP_MS, 5000);
    storm_conf.put(Config.STORM_MESSAGING_NETTY_SERVER_WORKER_THREADS, 1);
    storm_conf.put(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS, 1);
    IContext context = TransportFactory.makeContext(storm_conf);
    Assert.assertNotNull(context);
}
Also used : IContext(backtype.storm.messaging.IContext) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with IContext

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

the class NettyUnitTest method test_slow_receive.

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

        @Override
        public void run() {
            lock.lock();
            IConnection client = null;
            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);
                if (i % 1000 == 0) {
                    System.out.println("send " + i);
                    client.send(list);
                    list = new ArrayList<TaskMessage>();
                }
            }
            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();
            lock.unlock();
        }
    }).start();
    for (int i = 1; i < Short.MAX_VALUE; i++) {
        byte[] message = (byte[]) server.recv(task, 0);
        JStormUtils.sleepMs(1);
        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
            e.printStackTrace();
        }
        context.term();
    } finally {
        lock.unlock();
    }
    System.out.println("!!!!!!!!!!End test_slow_receive message test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 4 with IContext

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

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

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