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;
}
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);
}
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!!!!!!!!");
}
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!!!!!!!!");
}
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!!!!!!!!");
}
Aggregations