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
.client
;
20 import static org
.apache
.hadoop
.hbase
.io
.ByteBuffAllocator
.BUFFER_SIZE_KEY
;
22 import java
.io
.IOException
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Collection
;
25 import java
.util
.List
;
26 import org
.apache
.hadoop
.conf
.Configuration
;
27 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
28 import org
.apache
.hadoop
.hbase
.HBaseConfiguration
;
29 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
30 import org
.apache
.hadoop
.hbase
.TableName
;
31 import org
.apache
.hadoop
.hbase
.ipc
.NettyRpcServer
;
32 import org
.apache
.hadoop
.hbase
.ipc
.RpcServerFactory
;
33 import org
.apache
.hadoop
.hbase
.ipc
.SimpleRpcServer
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
35 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
36 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
37 import org
.junit
.After
;
38 import org
.junit
.Before
;
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
;
44 import org
.junit
.runner
.RunWith
;
45 import org
.junit
.runners
.Parameterized
;
48 * HBASE-19496 noticed that the RegionLoad/ServerLoad may be corrupted if rpc server
49 * reuses the bytebuffer backed, so this test call the Admin#getLastMajorCompactionTimestamp() to
50 * invoke HMaster to iterate all stored server/region loads.
52 @RunWith(Parameterized
.class)
53 @Category({ MediumTests
.class, ClientTests
.class })
54 public class TestServerLoadDurability
{
57 public static final HBaseClassTestRule CLASS_RULE
=
58 HBaseClassTestRule
.forClass(TestServerLoadDurability
.class);
60 private static final byte[] FAMILY
= Bytes
.toBytes("testFamily");
62 @Parameterized.Parameter
63 public Configuration conf
;
65 @Parameterized.Parameters
66 public static final Collection
<Object
[]> parameters() {
67 List
<Object
[]> configurations
= new ArrayList
<>();
68 configurations
.add(new Object
[] { createConfigurationForSimpleRpcServer() });
69 configurations
.add(new Object
[] { createConfigurationForNettyRpcServer() });
70 return configurations
;
73 private static Configuration
createConfigurationForSimpleRpcServer() {
74 Configuration conf
= HBaseConfiguration
.create();
75 conf
.set(RpcServerFactory
.CUSTOM_RPC_SERVER_IMPL_CONF_KEY
, SimpleRpcServer
.class.getName());
76 conf
.setInt(BUFFER_SIZE_KEY
, 20);
80 private static Configuration
createConfigurationForNettyRpcServer() {
81 Configuration conf
= HBaseConfiguration
.create();
82 conf
.set(RpcServerFactory
.CUSTOM_RPC_SERVER_IMPL_CONF_KEY
,
83 NettyRpcServer
.class.getName());
87 protected HBaseTestingUtility utility
;
88 protected Connection conn
;
89 protected Admin admin
;
92 public TestName testName
= new TestName();
93 protected TableName tableName
;
96 public void setUp() throws Exception
{
97 utility
= new HBaseTestingUtility(conf
);
98 utility
.startMiniCluster(2);
99 conn
= ConnectionFactory
.createConnection(utility
.getConfiguration());
100 admin
= conn
.getAdmin();
101 String methodName
= testName
.getMethodName();
102 tableName
= TableName
.valueOf(methodName
.substring(0, methodName
.length() - 3));
106 public void tearDown() throws Exception
{
107 utility
.shutdownMiniCluster();
111 public void testCompactionTimestamps() throws Exception
{
112 createTableWithDefaultConf(tableName
);
113 try (Table table
= conn
.getTable(tableName
)) {
114 long ts
= admin
.getLastMajorCompactionTimestamp(tableName
);
118 private void createTableWithDefaultConf(TableName tableName
) throws IOException
{
119 TableDescriptorBuilder builder
= TableDescriptorBuilder
.newBuilder(tableName
);
120 builder
.setColumnFamily(ColumnFamilyDescriptorBuilder
.of(FAMILY
));
121 admin
.createTable(builder
.build());