use of backtype.storm.messaging.TaskMessage 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!!!!!!!!!!!!!");
}
Aggregations