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