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