Madan Jampani | f1d425a | 2014-10-07 09:52:36 -0700 | [diff] [blame] | 1 | package org.onlab.netty; |
| 2 | |
| 3 | import java.util.concurrent.TimeUnit; |
| 4 | |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 5 | import org.apache.commons.lang3.RandomUtils; |
| 6 | import static org.junit.Assert.*; |
Madan Jampani | f1d425a | 2014-10-07 09:52:36 -0700 | [diff] [blame] | 7 | import org.junit.Test; |
| 8 | |
| 9 | /** |
| 10 | * Simple ping-pong test that exercises NettyMessagingService. |
| 11 | */ |
| 12 | public class PingPongTest { |
| 13 | |
| 14 | @Test |
| 15 | public void testPingPong() throws Exception { |
| 16 | NettyMessagingService pinger = new NettyMessagingService(8085); |
| 17 | NettyMessagingService ponger = new NettyMessagingService(9086); |
| 18 | try { |
| 19 | pinger.activate(); |
| 20 | ponger.activate(); |
Madan Jampani | f1d425a | 2014-10-07 09:52:36 -0700 | [diff] [blame] | 21 | ponger.registerHandler("echo", new EchoHandler()); |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 22 | byte[] payload = RandomUtils.nextBytes(100); |
| 23 | Response response = pinger.sendAndReceive(new Endpoint("localhost", 9086), "echo", payload); |
| 24 | assertArrayEquals(payload, response.get(10000, TimeUnit.MILLISECONDS)); |
Madan Jampani | f1d425a | 2014-10-07 09:52:36 -0700 | [diff] [blame] | 25 | } finally { |
| 26 | pinger.deactivate(); |
| 27 | ponger.deactivate(); |
| 28 | } |
| 29 | } |
| 30 | } |