Search in sources :

Example 16 with IConnection

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!!!!!!!!");
}
Also used : IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 17 with IConnection

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!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 18 with IConnection

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!!!!!!!!!!!!!");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 19 with IConnection

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!!!!!!!!!!!!!");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage)

Example 20 with IConnection

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;
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) DisruptorQueue(backtype.storm.utils.DisruptorQueue) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy) IConnection(backtype.storm.messaging.IConnection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

IConnection (backtype.storm.messaging.IConnection)25 TaskMessage (backtype.storm.messaging.TaskMessage)15 Test (org.junit.Test)12 IContext (backtype.storm.messaging.IContext)8 WorkerSlot (backtype.storm.scheduler.WorkerSlot)6 DisruptorQueue (backtype.storm.utils.DisruptorQueue)3 ITupleExt (backtype.storm.tuple.ITupleExt)2 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)2 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)2 WaitStrategy (com.lmax.disruptor.WaitStrategy)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 Assignment (com.alibaba.jstorm.schedule.Assignment)1 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)1 TaskShutdownDameon (com.alibaba.jstorm.task.TaskShutdownDameon)1 KryoException (com.esotericsoftware.kryo.KryoException)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1