1717 */
1818package org .apache .hadoop .hbase .ipc ;
1919
20- import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertNotNull ;
2121import static org .junit .Assert .assertTrue ;
2222
23- import java .util .ArrayList ;
2423import java .util .Arrays ;
2524import java .util .Collection ;
26- import java .util .List ;
2725import org .apache .hadoop .hbase .HBaseClassTestRule ;
2826import org .apache .hadoop .hbase .HBaseTestingUtility ;
2927import org .apache .hadoop .hbase .TableName ;
28+ import org .apache .hadoop .hbase .TableNameTestRule ;
29+ import org .apache .hadoop .hbase .client .Get ;
3030import org .apache .hadoop .hbase .client .Put ;
3131import org .apache .hadoop .hbase .client .Result ;
32- import org .apache .hadoop .hbase .client .ResultScanner ;
33- import org .apache .hadoop .hbase .client .Scan ;
3432import org .apache .hadoop .hbase .client .Table ;
33+ import org .apache .hadoop .hbase .client .TableDescriptor ;
34+ import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
35+ import org .apache .hadoop .hbase .regionserver .DisabledRegionSplitPolicy ;
3536import org .apache .hadoop .hbase .testclassification .MediumTests ;
3637import org .apache .hadoop .hbase .testclassification .RPCTests ;
3738import org .apache .hadoop .hbase .util .Bytes ;
39+ import org .apache .hadoop .hbase .util .LoadTestKVGenerator ;
3840import org .junit .After ;
3941import org .junit .Before ;
4042import org .junit .ClassRule ;
4143import org .junit .Rule ;
4244import org .junit .Test ;
4345import org .junit .experimental .categories .Category ;
44- import org .junit .rules .TestName ;
4546import org .junit .runner .RunWith ;
4647import org .junit .runners .Parameterized ;
4748import org .junit .runners .Parameterized .Parameters ;
@@ -54,14 +55,17 @@ public class TestNettyRpcServer {
5455 public static final HBaseClassTestRule CLASS_RULE =
5556 HBaseClassTestRule .forClass (TestNettyRpcServer .class );
5657
58+ private static final byte [] FAMILY = Bytes .toBytes ("f" );
59+ private static final byte [] QUALIFIER = Bytes .toBytes ("q" );
60+ private static final int NUM_ROWS = 100 ;
61+ private static final int MIN_LEN = 1000 ;
62+ private static final int MAX_LEN = 1000000 ;
63+ protected static final LoadTestKVGenerator GENERATOR = new LoadTestKVGenerator (MIN_LEN , MAX_LEN );
64+ protected static HBaseTestingUtility TEST_UTIL ;
65+
5766 @ Rule
58- public TestName name = new TestName ();
59- private static HBaseTestingUtility TEST_UTIL ;
67+ public TableNameTestRule name = new TableNameTestRule ();
6068
61- private static TableName TABLE ;
62- private static byte [] FAMILY = Bytes .toBytes ("f1" );
63- private static byte [] PRIVATE_COL = Bytes .toBytes ("private" );
64- private static byte [] PUBLIC_COL = Bytes .toBytes ("public" );
6569 @ Parameterized .Parameter
6670 public String allocatorType ;
6771
@@ -74,8 +78,10 @@ public static Collection<Object[]> parameters() {
7478
7579 @ Before
7680 public void setup () throws Exception {
77- TABLE = TableName .valueOf (name .getMethodName ().replace ('[' , '_' ).replace (']' , '_' ));
78- TEST_UTIL = new HBaseTestingUtility ();
81+ // A subclass may have already created TEST_UTIL and is now upcalling to us
82+ if (TEST_UTIL == null ) {
83+ TEST_UTIL = new HBaseTestingUtility ();
84+ }
7985 TEST_UTIL .getConfiguration ().set (RpcServerFactory .CUSTOM_RPC_SERVER_IMPL_CONF_KEY ,
8086 NettyRpcServer .class .getName ());
8187 TEST_UTIL .getConfiguration ().set (NettyRpcServer .HBASE_NETTY_ALLOCATOR_KEY , allocatorType );
@@ -89,34 +95,30 @@ public void tearDown() throws Exception {
8995
9096 @ Test
9197 public void testNettyRpcServer () throws Exception {
92- final Table table = TEST_UTIL .createTable (TABLE , FAMILY );
93- try {
98+ doTest (name .getTableName ());
99+ }
100+
101+ protected void doTest (TableName tableName ) throws Exception {
102+ // Splitting just complicates the test scenario, disable it
103+ final TableDescriptor desc = TableDescriptorBuilder .newBuilder (tableName )
104+ .setRegionSplitPolicyClassName (DisabledRegionSplitPolicy .class .getName ()).build ();
105+ try (Table table =
106+ TEST_UTIL .createTable (desc , new byte [][] { FAMILY }, TEST_UTIL .getConfiguration ())) {
94107 // put some test data
95- List <Put > puts = new ArrayList <Put >(100 );
96- for (int i = 0 ; i < 100 ; i ++) {
97- Put p = new Put (Bytes .toBytes (i ));
98- p .addColumn (FAMILY , PRIVATE_COL , Bytes .toBytes ("secret " + i ));
99- p .addColumn (FAMILY , PUBLIC_COL , Bytes .toBytes ("info " + i ));
100- puts .add (p );
108+ for (int i = 0 ; i < NUM_ROWS ; i ++) {
109+ final byte [] rowKey = Bytes .toBytes (LoadTestKVGenerator .md5PrefixedKey (i ));
110+ final byte [] v = GENERATOR .generateRandomSizeValue (rowKey , QUALIFIER );
111+ table .put (new Put (rowKey ).addColumn (FAMILY , QUALIFIER , v ));
101112 }
102- table .put (puts );
103-
104113 // read to verify it.
105- Scan scan = new Scan ();
106- scan .setCaching (16 );
107- ResultScanner rs = table .getScanner (scan );
108- int rowcnt = 0 ;
109- for (Result r : rs ) {
110- rowcnt ++;
111- int rownum = Bytes .toInt (r .getRow ());
112- assertTrue (r .containsColumn (FAMILY , PRIVATE_COL ));
113- assertEquals ("secret " + rownum , Bytes .toString (r .getValue (FAMILY , PRIVATE_COL )));
114- assertTrue (r .containsColumn (FAMILY , PUBLIC_COL ));
115- assertEquals ("info " + rownum , Bytes .toString (r .getValue (FAMILY , PUBLIC_COL )));
114+ for (int i = 0 ; i < NUM_ROWS ; i ++) {
115+ final byte [] rowKey = Bytes .toBytes (LoadTestKVGenerator .md5PrefixedKey (i ));
116+ final Result r = table .get (new Get (rowKey ).addColumn (FAMILY , QUALIFIER ));
117+ assertNotNull ("Result was empty" , r );
118+ final byte [] v = r .getValue (FAMILY , QUALIFIER );
119+ assertNotNull ("Result did not contain expected value" , v );
120+ assertTrue ("Value was not verified" , LoadTestKVGenerator .verify (v , rowKey , QUALIFIER ));
116121 }
117- assertEquals ("Expected 100 rows returned" , 100 , rowcnt );
118- } finally {
119- table .close ();
120122 }
121123 }
122124
0 commit comments