2828import org .apache .hadoop .conf .Configuration ;
2929import org .apache .hadoop .fs .Path ;
3030import org .apache .hadoop .hbase .HBaseTestingUtility ;
31+ import org .apache .hadoop .hbase .HColumnDescriptor ;
3132import org .apache .hadoop .hbase .HConstants ;
33+ import org .apache .hadoop .hbase .HTableDescriptor ;
3234import org .apache .hadoop .hbase .TableName ;
3335import org .apache .hadoop .hbase .client .ColumnFamilyDescriptor ;
3436import org .apache .hadoop .hbase .client .ColumnFamilyDescriptorBuilder ;
@@ -63,7 +65,7 @@ public class TestHBaseFsckEncryption {
6365 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility ();
6466
6567 private Configuration conf ;
66- private TableDescriptor tableDescriptor ;
68+ private HTableDescriptor htd ;
6769 private Key cfKey ;
6870
6971 @ BeforeEach
@@ -83,18 +85,15 @@ public void setUp() throws Exception {
8385 TEST_UTIL .startMiniCluster (3 );
8486
8587 // Create the table
86- TableDescriptorBuilder tableDescriptorBuilder =
87- TableDescriptorBuilder .newBuilder (TableName .valueOf ("default" , "TestHBaseFsckEncryption" ));
88- ColumnFamilyDescriptor columnFamilyDescriptor =
89- ColumnFamilyDescriptorBuilder .newBuilder (Bytes .toBytes ("cf" )).setEncryptionType (algorithm )
90- .setEncryptionKey (EncryptionUtil .wrapKey (conf ,
91- conf .get (HConstants .CRYPTO_MASTERKEY_NAME_CONF_KEY , User .getCurrent ().getShortName ()),
92- cfKey ))
93- .build ();
94- tableDescriptorBuilder .setColumnFamily (columnFamilyDescriptor );
95- tableDescriptor = tableDescriptorBuilder .build ();
96- TEST_UTIL .getAdmin ().createTable (tableDescriptor );
97- TEST_UTIL .waitTableAvailable (tableDescriptor .getTableName (), 5000 );
88+ htd = new HTableDescriptor (TableName .valueOf ("default" , "TestHBaseFsckEncryption" ));
89+ HColumnDescriptor hcd = new HColumnDescriptor ("cf" );
90+ hcd .setEncryptionType (algorithm );
91+ hcd .setEncryptionKey (EncryptionUtil .wrapKey (conf ,
92+ conf .get (HConstants .CRYPTO_MASTERKEY_NAME_CONF_KEY , User .getCurrent ().getShortName ()),
93+ cfKey ));
94+ htd .addFamily (hcd );
95+ TEST_UTIL .getAdmin ().createTable (htd );
96+ TEST_UTIL .waitTableAvailable (htd .getTableName (), 5000 );
9897 }
9998
10099 @ AfterEach
@@ -105,7 +104,7 @@ public void tearDown() throws Exception {
105104 @ Test
106105 public void testFsckWithEncryption () throws Exception {
107106 // Populate the table with some data
108- Table table = TEST_UTIL .getConnection ().getTable (tableDescriptor .getTableName ());
107+ Table table = TEST_UTIL .getConnection ().getTable (htd .getTableName ());
109108 try {
110109 byte [] values = { 'A' , 'B' , 'C' , 'D' };
111110 for (int i = 0 ; i < values .length ; i ++) {
@@ -119,18 +118,18 @@ public void testFsckWithEncryption() throws Exception {
119118 table .close ();
120119 }
121120 // Flush it
122- TEST_UTIL .getAdmin ().flush (tableDescriptor .getTableName ());
121+ TEST_UTIL .getAdmin ().flush (htd .getTableName ());
123122
124123 // Verify we have encrypted store files on disk
125- final List <Path > paths = findStorefilePaths (tableDescriptor .getTableName ());
124+ final List <Path > paths = findStorefilePaths (htd .getTableName ());
126125 assertTrue (paths .size () > 0 );
127126 for (Path path : paths ) {
128127 assertTrue (Bytes .equals (cfKey .getEncoded (), extractHFileKey (path )),
129128 "Store file " + path + " has incorrect key" );
130129 }
131130
132131 // Insure HBck doesn't consider them corrupt
133- HBaseFsck res = HbckTestingUtil .doHFileQuarantine (conf , tableDescriptor .getTableName ());
132+ HBaseFsck res = HbckTestingUtil .doHFileQuarantine (conf , htd .getTableName ());
134133 assertEquals (0 , res .getRetCode ());
135134 HFileCorruptionChecker hfcc = res .getHFilecorruptionChecker ();
136135 assertEquals (0 , hfcc .getCorrupted ().size ());
@@ -142,7 +141,7 @@ public void testFsckWithEncryption() throws Exception {
142141 private List <Path > findStorefilePaths (TableName tableName ) throws Exception {
143142 List <Path > paths = new ArrayList <>();
144143 for (Region region : TEST_UTIL .getRSForFirstRegionInTable (tableName )
145- .getRegions (tableDescriptor .getTableName ())) {
144+ .getRegions (htd .getTableName ())) {
146145 for (HStore store : ((HRegion ) region ).getStores ()) {
147146 for (HStoreFile storefile : store .getStorefiles ()) {
148147 paths .add (storefile .getPath ());
0 commit comments