001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import static org.apache.hadoop.hbase.io.ByteBuffAllocator.BUFFER_SIZE_KEY; 021 022import java.io.IOException; 023import java.util.ArrayList; 024import java.util.Collection; 025import java.util.List; 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.hbase.HBaseClassTestRule; 028import org.apache.hadoop.hbase.HBaseConfiguration; 029import org.apache.hadoop.hbase.HBaseTestingUtility; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.ipc.NettyRpcServer; 032import org.apache.hadoop.hbase.ipc.RpcServerFactory; 033import org.apache.hadoop.hbase.ipc.SimpleRpcServer; 034import org.apache.hadoop.hbase.testclassification.ClientTests; 035import org.apache.hadoop.hbase.testclassification.MediumTests; 036import org.apache.hadoop.hbase.util.Bytes; 037import org.junit.After; 038import org.junit.Before; 039import org.junit.ClassRule; 040import org.junit.Rule; 041import org.junit.Test; 042import org.junit.experimental.categories.Category; 043import org.junit.rules.TestName; 044import org.junit.runner.RunWith; 045import org.junit.runners.Parameterized; 046 047/** 048 * HBASE-19496 noticed that the RegionLoad/ServerLoad may be corrupted if rpc server reuses the 049 * bytebuffer backed, so this test call the Admin#getLastMajorCompactionTimestamp() to invoke 050 * HMaster to iterate all stored server/region loads. 051 */ 052@RunWith(Parameterized.class) 053@Category({ MediumTests.class, ClientTests.class }) 054public class TestServerLoadDurability { 055 056 @ClassRule 057 public static final HBaseClassTestRule CLASS_RULE = 058 HBaseClassTestRule.forClass(TestServerLoadDurability.class); 059 060 private static final byte[] FAMILY = Bytes.toBytes("testFamily"); 061 062 @Parameterized.Parameter 063 public Configuration conf; 064 065 @Parameterized.Parameters 066 public static final Collection<Object[]> parameters() { 067 List<Object[]> configurations = new ArrayList<>(); 068 configurations.add(new Object[] { createConfigurationForSimpleRpcServer() }); 069 configurations.add(new Object[] { createConfigurationForNettyRpcServer() }); 070 return configurations; 071 } 072 073 private static Configuration createConfigurationForSimpleRpcServer() { 074 Configuration conf = HBaseConfiguration.create(); 075 conf.set(RpcServerFactory.CUSTOM_RPC_SERVER_IMPL_CONF_KEY, SimpleRpcServer.class.getName()); 076 conf.setInt(BUFFER_SIZE_KEY, 20); 077 return conf; 078 } 079 080 private static Configuration createConfigurationForNettyRpcServer() { 081 Configuration conf = HBaseConfiguration.create(); 082 conf.set(RpcServerFactory.CUSTOM_RPC_SERVER_IMPL_CONF_KEY, NettyRpcServer.class.getName()); 083 return conf; 084 } 085 086 protected HBaseTestingUtility utility; 087 protected Connection conn; 088 protected Admin admin; 089 090 @Rule 091 public TestName testName = new TestName(); 092 protected TableName tableName; 093 094 @Before 095 public void setUp() throws Exception { 096 utility = new HBaseTestingUtility(conf); 097 utility.startMiniCluster(2); 098 conn = ConnectionFactory.createConnection(utility.getConfiguration()); 099 admin = conn.getAdmin(); 100 String methodName = testName.getMethodName(); 101 tableName = TableName.valueOf(methodName.substring(0, methodName.length() - 3)); 102 } 103 104 @After 105 public void tearDown() throws Exception { 106 utility.shutdownMiniCluster(); 107 } 108 109 @Test 110 public void testCompactionTimestamps() throws Exception { 111 createTableWithDefaultConf(tableName); 112 try (Table table = conn.getTable(tableName)) { 113 long ts = admin.getLastMajorCompactionTimestamp(tableName); 114 } 115 } 116 117 private void createTableWithDefaultConf(TableName tableName) throws IOException { 118 TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName); 119 builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)); 120 admin.createTable(builder.build()); 121 } 122 123}