blob: ab816b2aed841e615ff25080893bfcdf4e56a085 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
Madan Jampanif1d425a2014-10-07 09:52:36 -070016package org.onlab.netty;
17
Madan Jampani24f9efb2014-10-24 18:56:23 -070018import java.util.concurrent.Future;
Madan Jampanif1d425a2014-10-07 09:52:36 -070019import java.util.concurrent.TimeUnit;
20
Madan Jampani53e44e62014-10-07 12:39:51 -070021import org.apache.commons.lang3.RandomUtils;
Madan Jampani24f9efb2014-10-24 18:56:23 -070022
Madan Jampani53e44e62014-10-07 12:39:51 -070023import static org.junit.Assert.*;
Madan Jampani24f9efb2014-10-24 18:56:23 -070024
Yuta HIGUCHI3e51ea42014-11-24 18:12:54 -080025import org.junit.Ignore;
Madan Jampanif1d425a2014-10-07 09:52:36 -070026import org.junit.Test;
27
28/**
29 * Simple ping-pong test that exercises NettyMessagingService.
30 */
31public class PingPongTest {
32
Yuta HIGUCHI3e51ea42014-11-24 18:12:54 -080033 @Ignore("Turning off fragile test")
Madan Jampanif1d425a2014-10-07 09:52:36 -070034 @Test
35 public void testPingPong() throws Exception {
36 NettyMessagingService pinger = new NettyMessagingService(8085);
37 NettyMessagingService ponger = new NettyMessagingService(9086);
38 try {
39 pinger.activate();
40 ponger.activate();
Madan Jampanif1d425a2014-10-07 09:52:36 -070041 ponger.registerHandler("echo", new EchoHandler());
Madan Jampani53e44e62014-10-07 12:39:51 -070042 byte[] payload = RandomUtils.nextBytes(100);
Madan Jampani24f9efb2014-10-24 18:56:23 -070043 Future<byte[]> responseFuture = pinger.sendAndReceive(new Endpoint("localhost", 9086), "echo", payload);
44 assertArrayEquals(payload, responseFuture.get(10000, TimeUnit.MILLISECONDS));
Madan Jampanif1d425a2014-10-07 09:52:36 -070045 } finally {
46 pinger.deactivate();
47 ponger.deactivate();
48 }
49 }
50}