*/
package org.opendaylight.ovsdb.lib.jsonrpc;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.concurrent.TimeUnit;
+
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
-
-import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang3.NotImplementedException;
public class NettyBootStrapper {
}
}
+ public int getServerPort() {
+ SocketAddress socketAddress = f.channel().localAddress();
+ if (socketAddress instanceof InetSocketAddress) {
+ InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
+ return inetSocketAddress.getPort();
+ } else {
+ throw new NotImplementedException("Please implement how to obtain port from a " + socketAddress.toString());
+ }
+ }
+
}
public class TestClient extends TestCase {
String serverurl = "127.0.0.1";
- int serverport = 12345;
-
NettyBootStrapper bootstrapper = new NettyBootStrapper();
JsonRpcDecoder jsonRpcDecoder = new JsonRpcDecoder(100000);
public void setupServer() throws Exception {
- bootstrapper.startServer(serverport,
+ bootstrapper.startServer(0,
jsonRpcDecoder,
new LoggingHandler(LogLevel.DEBUG));
}
/**
* Testing appropriate ChannelHandler integration for
- * JsonRpcDecoder, so that Json strings written using an
+ * JsonRpcDecoder, so that JSON strings written using an
* OutputStream connected to a ServerSocket of a Netty
- * ServerBootstrap can be decoder properly.
+ * ServerBootstrap can be decoded properly.
*/
-
@Test
public void testBasicFlow() throws Exception {
setupServer();
- Socket socket = new Socket(serverurl, serverport);
+ Socket socket = new Socket(serverurl, bootstrapper.getServerPort());
OutputStream outputStream = socket.getOutputStream();
int records = 20;