1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import io.netty.channel.epoll.EpollEventLoopGroup;
21 import io.netty.channel.epoll.EpollSocketChannel;
22 import io.netty.channel.nio.NioEventLoopGroup;
23 import io.netty.channel.socket.nio.NioSocketChannel;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.List;
28
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.codec.Codec;
31 import org.apache.hadoop.hbase.testclassification.RPCTests;
32 import org.apache.hadoop.hbase.testclassification.SmallTests;
33 import org.apache.hadoop.hbase.util.JVM;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.experimental.categories.Category;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.junit.runners.Parameterized.Parameter;
40 import org.junit.runners.Parameterized.Parameters;
41
42 @RunWith(Parameterized.class)
43 @Category({ RPCTests.class, SmallTests.class })
44 public class TestNettyIPC extends AbstractTestIPC {
45
46 @Parameters(name = "{index}: EventLoop={0}")
47 public static Collection<Object[]> parameters() {
48 List<Object[]> params = new ArrayList<>();
49 params.add(new Object[] { "nio" });
50 params.add(new Object[] { "perClientNio" });
51 if (JVM.isLinux() && JVM.isAmd64()) {
52 params.add(new Object[] { "epoll" });
53 }
54 return params;
55 }
56
57 @Parameter
58 public String eventLoopType;
59
60 private static NioEventLoopGroup NIO;
61
62 private static EpollEventLoopGroup EPOLL;
63
64 @BeforeClass
65 public static void setUpBeforeClass() {
66 NIO = new NioEventLoopGroup();
67 if (JVM.isLinux() && JVM.isAmd64()) {
68 EPOLL = new EpollEventLoopGroup();
69 }
70 }
71
72 @AfterClass
73 public static void tearDownAfterClass() {
74 if (NIO != null) {
75 NIO.shutdownGracefully();
76 }
77 if (EPOLL != null) {
78 EPOLL.shutdownGracefully();
79 }
80 }
81
82 private void setConf(Configuration conf) {
83 switch (eventLoopType) {
84 case "nio":
85 NettyRpcClientConfigHelper.setEventLoopConfig(conf, NIO, NioSocketChannel.class);
86 break;
87 case "epoll":
88 NettyRpcClientConfigHelper.setEventLoopConfig(conf, EPOLL, EpollSocketChannel.class);
89 break;
90 case "perClientNio":
91 NettyRpcClientConfigHelper.createEventLoopPerClient(conf);
92 break;
93 default:
94 break;
95 }
96 }
97
98 @Override
99 protected NettyRpcClient createRpcClientNoCodec(Configuration conf) {
100 setConf(conf);
101 return new NettyRpcClient(conf) {
102
103 @Override
104 Codec getCodec() {
105 return null;
106 }
107
108 };
109 }
110
111 @Override
112 protected NettyRpcClient createRpcClient(Configuration conf) {
113 setConf(conf);
114 return new NettyRpcClient(conf);
115 }
116
117 @Override
118 protected NettyRpcClient createRpcClientRTEDuringConnectionSetup(Configuration conf) {
119 setConf(conf);
120 return new NettyRpcClient(conf) {
121
122 @Override
123 boolean isTcpNoDelay() {
124 throw new RuntimeException("Injected fault");
125 }
126 };
127 }
128 }