2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.ipc
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertTrue
;
23 import java
.util
.ArrayList
;
24 import java
.util
.List
;
25 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
26 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
27 import org
.apache
.hadoop
.hbase
.TableName
;
28 import org
.apache
.hadoop
.hbase
.client
.Put
;
29 import org
.apache
.hadoop
.hbase
.client
.Result
;
30 import org
.apache
.hadoop
.hbase
.client
.ResultScanner
;
31 import org
.apache
.hadoop
.hbase
.client
.Scan
;
32 import org
.apache
.hadoop
.hbase
.client
.Table
;
33 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.RPCTests
;
35 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
36 import org
.junit
.AfterClass
;
37 import org
.junit
.Before
;
38 import org
.junit
.BeforeClass
;
39 import org
.junit
.ClassRule
;
40 import org
.junit
.Rule
;
41 import org
.junit
.Test
;
42 import org
.junit
.experimental
.categories
.Category
;
43 import org
.junit
.rules
.TestName
;
45 @Category({ RPCTests
.class, MediumTests
.class })
46 public class TestNettyRpcServer
{
49 public static final HBaseClassTestRule CLASS_RULE
=
50 HBaseClassTestRule
.forClass(TestNettyRpcServer
.class);
53 public TestName name
= new TestName();
54 private static HBaseTestingUtil TEST_UTIL
;
56 private static TableName TABLE
;
57 private static byte[] FAMILY
= Bytes
.toBytes("f1");
58 private static byte[] PRIVATE_COL
= Bytes
.toBytes("private");
59 private static byte[] PUBLIC_COL
= Bytes
.toBytes("public");
63 TABLE
= TableName
.valueOf(name
.getMethodName());
67 public static void setupBeforeClass() throws Exception
{
68 TEST_UTIL
= new HBaseTestingUtil();
69 TEST_UTIL
.getConfiguration().set(
70 RpcServerFactory
.CUSTOM_RPC_SERVER_IMPL_CONF_KEY
,
71 NettyRpcServer
.class.getName());
72 TEST_UTIL
.startMiniCluster();
76 public static void tearDownAfterClass() throws Exception
{
77 TEST_UTIL
.shutdownMiniCluster();
81 public void testNettyRpcServer() throws Exception
{
82 final Table table
= TEST_UTIL
.createTable(TABLE
, FAMILY
);
85 List
<Put
> puts
= new ArrayList
<Put
>(100);
86 for (int i
= 0; i
< 100; i
++) {
87 Put p
= new Put(Bytes
.toBytes(i
));
88 p
.addColumn(FAMILY
, PRIVATE_COL
, Bytes
.toBytes("secret " + i
));
89 p
.addColumn(FAMILY
, PUBLIC_COL
, Bytes
.toBytes("info " + i
));
95 Scan scan
= new Scan();
97 ResultScanner rs
= table
.getScanner(scan
);
101 int rownum
= Bytes
.toInt(r
.getRow());
102 assertTrue(r
.containsColumn(FAMILY
, PRIVATE_COL
));
103 assertEquals("secret " + rownum
,
104 Bytes
.toString(r
.getValue(FAMILY
, PRIVATE_COL
)));
105 assertTrue(r
.containsColumn(FAMILY
, PUBLIC_COL
));
106 assertEquals("info " + rownum
,
107 Bytes
.toString(r
.getValue(FAMILY
, PUBLIC_COL
)));
109 assertEquals("Expected 100 rows returned", 100, rowcnt
);