use of backtype.storm.messaging.IContext in project jstorm by alibaba.
the class NettyUnitTest method test_batch.
@Test
public void test_batch() {
System.out.println("!!!!!!!!!!Start batch message test!!!!!!!!");
final int base = 100000;
final IContext context = TransportFactory.makeContext(storm_conf);
final IConnection server = initNettyServer();
new Thread(new Runnable() {
public void send() {
final IConnection 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);
}
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();
}
@Override
public void run() {
lock.lock();
try {
send();
} finally {
lock.unlock();
}
}
}).start();
for (int i = 1; i < Short.MAX_VALUE; i++) {
byte[] message = (byte[]) server.recv(task, 0);
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
}
context.term();
} finally {
lock.unlock();
}
System.out.println("!!!!!!!!!!End batch message test!!!!!!!!");
}
Aggregations