public void test_slow_receive() throws InterruptedException {
System.out
.println("!!!!!!!!!!Start test_slow_receive message test!!!!!!!!");
final int base = 100000;
final IContext context = TransportFactory.makeContext(storm_conf);
final IConnection server = context.bind(null, port);
WaitStrategy waitStrategy = (WaitStrategy) Utils
.newInstance((String) storm_conf
.get(Config.TOPOLOGY_DISRUPTOR_WAIT_STRATEGY));
DisruptorQueue recvQueue = new DisruptorQueue(
"NettyJunitTest", ProducerType.SINGLE, 4, waitStrategy);
server.registerQueue(recvQueue);
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(i, 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++) {
TaskMessage message = server.recv(0);
JStormUtils.sleepMs(1);
Assert.assertEquals(String.valueOf(i + base),
new String(message.message()));
if (i % 1000 == 0) {
System.out.println("Receive " + message.task());
}
}
System.out.println("Finish Receive ");
lock.lock();
clientClose.signal();
server.close();
contextClose.await();
context.term();
lock.unlock();
System.out
.println("!!!!!!!!!!End test_slow_receive message test!!!!!!!!");
}