use of backtype.storm.messaging.IConnection in project jstorm by alibaba.
the class NettyUnitTest method test_large_msg.
@Test
public void test_large_msg() {
System.out.println("!!!!!!!!!!start large message test!!!!!!!!");
String req_msg = setupLargMsg();
System.out.println("!!!!Finish batch data, size:" + req_msg.length() + "!!!!");
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);
byte[] recv = (byte[]) server.recv(task, 0);
Assert.assertEquals(req_msg, new String(recv));
client.close();
server.close();
System.out.println("!!!!!!!!!!End larget message test!!!!!!!!");
}
use of backtype.storm.messaging.IConnection 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!!!!!!!!");
}
use of backtype.storm.messaging.IConnection in project jstorm by alibaba.
the class NettyUnitTest method test_multiple_server.
@Test
public void test_multiple_server() {
System.out.println("!!!!!!!!Start test_multiple_server !!!!!!!!!!!");
final String req_msg = setupLargMsg();
final int clientNum = 3;
final AtomicLong received = new AtomicLong(clientNum);
for (int i = 0; i < clientNum; i++) {
final int realPort = port + i;
new Thread(new Runnable() {
@Override
public void run() {
IConnection server = null;
JStormUtils.sleepMs(1000);
System.out.println("!!server begin start!!!!!");
server = initNettyServer(realPort);
byte[] recv = (byte[]) server.recv(task, 0);
Assert.assertEquals(req_msg, new String(recv));
received.decrementAndGet();
System.out.println("!!server received !!!!!" + realPort);
server.close();
}
}).start();
}
List<TaskMessage> list = new ArrayList<TaskMessage>();
TaskMessage message = new TaskMessage(task, req_msg.getBytes());
list.add(message);
List<IConnection> clients = new ArrayList<IConnection>();
for (int i = 0; i < clientNum; i++) {
final int realPort = port + i;
IConnection client = context.connect(null, "localhost", realPort);
clients.add(client);
client.send(message);
System.out.println("!!Client has sent data to " + realPort);
}
while (received.get() != 0) {
JStormUtils.sleepMs(1000);
}
for (int i = 0; i < clientNum; i++) {
clients.get(i).close();
}
System.out.println("!!!!!!!!!!!!End test_multiple_server!!!!!!!!!!!!!");
}
use of backtype.storm.messaging.IConnection in project jstorm by alibaba.
the class NettyUnitTest method test_multiple_client.
/**
* Due to there is only one client to one server in one jvm It can't do this test
*
* @throws InterruptedException
*/
public void test_multiple_client() {
System.out.println("!!!!!!!!Start test_multiple_client !!!!!!!!!!!");
final String req_msg = setupLargMsg();
final int clientNum = 3;
final AtomicLong received = new AtomicLong(clientNum);
for (int i = 0; i < clientNum; i++) {
new Thread(new Runnable() {
@Override
public void run() {
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");
while (received.get() != 0) {
JStormUtils.sleepMs(1000);
}
client.close();
}
}).start();
}
IConnection server = null;
JStormUtils.sleepMs(1000);
System.out.println("!!server begin start!!!!!");
server = initNettyServer();
for (int i = 0; i < clientNum; i++) {
byte[] recv = (byte[]) server.recv(task, 0);
Assert.assertEquals(req_msg, new String(recv));
received.decrementAndGet();
}
server.close();
System.out.println("!!!!!!!!!!!!End test_multiple_client!!!!!!!!!!!!!");
}
use of backtype.storm.messaging.IConnection in project jstorm by alibaba.
the class NettyUnitTest method initNettyServer.
private IConnection initNettyServer(int port) {
ConcurrentHashMap<Integer, DisruptorQueue> deserializeQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
// ConcurrentHashMap<Integer, DisruptorQueue> deserializeCtrlQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
WaitStrategy wait = (WaitStrategy) Utils.newInstance("com.lmax.disruptor.TimeoutBlockingWaitStrategy", 5, TimeUnit.MILLISECONDS);
DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, 256, wait, false, 0, 0);
Set<Integer> taskSet = new HashSet<Integer>();
taskSet.add(1);
IConnection server = context.bind(null, port, deserializeQueues, recvControlQueue, true, taskSet);
WaitStrategy waitStrategy = new BlockingWaitStrategy();
DisruptorQueue recvQueue = DisruptorQueue.mkInstance("NettyUnitTest", ProducerType.SINGLE, 1024, waitStrategy, false, 0, 0);
server.registerQueue(task, recvQueue);
return server;
}
Aggregations