HBASE-26416 Implement a new method for region replication instead of using replay...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / ipc / TestNettyRpcServer.java
blob85e3ab292267fe4bc74d63f2cc471a41c5cf5606
1 /**
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 {
48 @ClassRule
49 public static final HBaseClassTestRule CLASS_RULE =
50 HBaseClassTestRule.forClass(TestNettyRpcServer.class);
52 @Rule
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");
61 @Before
62 public void setup() {
63 TABLE = TableName.valueOf(name.getMethodName());
66 @BeforeClass
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();
75 @AfterClass
76 public static void tearDownAfterClass() throws Exception {
77 TEST_UTIL.shutdownMiniCluster();
80 @Test
81 public void testNettyRpcServer() throws Exception {
82 final Table table = TEST_UTIL.createTable(TABLE, FAMILY);
83 try {
84 // put some test data
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));
90 puts.add(p);
92 table.put(puts);
94 // read to verify it.
95 Scan scan = new Scan();
96 scan.setCaching(16);
97 ResultScanner rs = table.getScanner(scan);
98 int rowcnt = 0;
99 for (Result r : rs) {
100 rowcnt++;
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);
110 } finally {
111 table.close();