You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2020/10/01 14:00:04 UTC
[hbase] 01/01: HBASE-25139 add test for netty binding
This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch HBASE-25139
in repository https://gitbox.apache.org/repos/asf/hbase.git
commit 94e9044d714907baa6c3aafefc55a255289c8f34
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Thu Oct 1 21:59:35 2020 +0800
HBASE-25139 add test for netty binding
---
.../java/org/apache/hadoop/hbase/TestNetty.java | 72 ++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestNetty.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestNetty.java
new file mode 100644
index 0000000..4c8fc0c
--- /dev/null
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestNetty.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.net.InetSocketAddress;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.DNS;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hbase.thirdparty.io.netty.bootstrap.ServerBootstrap;
+import org.apache.hbase.thirdparty.io.netty.channel.Channel;
+import org.apache.hbase.thirdparty.io.netty.channel.ChannelInitializer;
+import org.apache.hbase.thirdparty.io.netty.channel.epoll.EpollEventLoopGroup;
+import org.apache.hbase.thirdparty.io.netty.channel.epoll.EpollServerSocketChannel;
+
+@Category({ ClientTests.class, SmallTests.class })
+public class TestNetty {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestNetty.class);
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestNetty.class);
+
+ @Test
+ public void test() throws Exception {
+ Configuration conf = HBaseConfiguration.create();
+ String hostname = DNS.getHostname(conf, DNS.ServerType.MASTER);
+ LOG.info("hostname is {}", hostname);
+ int port = 0;
+ LOG.info("port is {}", port);
+ InetSocketAddress initialIsa = new InetSocketAddress(hostname, port);
+ LOG.info("initial isa is {}", initialIsa);
+ InetSocketAddress bindAddress =
+ new InetSocketAddress(conf.get("hbase.master.ipc.address", hostname), port);
+ LOG.info("bind address is {}", bindAddress);
+ EpollEventLoopGroup group = new EpollEventLoopGroup();
+ Channel serverChannel = new ServerBootstrap().group(group)
+ .channel(EpollServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() {
+
+ @Override
+ protected void initChannel(Channel ch) throws Exception {
+ LOG.info("connected {}", ch);
+ ch.close();
+ }
+ }).bind(bindAddress).sync().channel();
+ LOG.info("server channel is {}", serverChannel);
+ Thread.sleep(1000);
+ serverChannel.close();
+ group.shutdownGracefully();
+ }
+}