1717 */
1818package org .apache .hadoop .hbase .regionserver ;
1919
20- import static org .apache .hadoop .hbase .regionserver .storefiletracker .StoreFileTrackerFactory .
21- TRACKER_IMPL ;
20+ import static org .apache .hadoop .hbase .regionserver .storefiletracker .StoreFileTrackerFactory .TRACKER_IMPL ;
2221import static org .junit .Assert .assertTrue ;
2322import static org .junit .Assert .fail ;
2423
2524import java .io .IOException ;
2625import java .util .ArrayList ;
27- import java .util .HashMap ;
2826import java .util .List ;
2927import java .util .UUID ;
3028import java .util .concurrent .TimeUnit ;
3634import org .apache .hadoop .hbase .HBaseClassTestRule ;
3735import org .apache .hadoop .hbase .HBaseTestingUtility ;
3836import org .apache .hadoop .hbase .TableName ;
37+ import org .apache .hadoop .hbase .TableNameTestRule ;
38+ import org .apache .hadoop .hbase .client .ColumnFamilyDescriptorBuilder ;
3939import org .apache .hadoop .hbase .client .Put ;
4040import org .apache .hadoop .hbase .client .RegionInfo ;
4141import org .apache .hadoop .hbase .client .RegionInfoBuilder ;
4242import org .apache .hadoop .hbase .client .Table ;
43+ import org .apache .hadoop .hbase .client .TableDescriptor ;
44+ import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
4345import org .apache .hadoop .hbase .master .procedure .MasterProcedureEnv ;
4446import org .apache .hadoop .hbase .regionserver .storefiletracker .TestStoreFileTracker ;
4547import org .apache .hadoop .hbase .testclassification .LargeTests ;
5456import org .junit .Rule ;
5557import org .junit .Test ;
5658import org .junit .experimental .categories .Category ;
57- import org .junit .rules .TestName ;
5859
5960
6061@ Category ({RegionServerTests .class , LargeTests .class })
@@ -66,14 +67,15 @@ public class TestMergesSplitsAddToTracker {
6667
6768 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility ();
6869
69- public static final byte [] FAMILY_NAME = Bytes .toBytes ("info" );
70+ private static final String FAMILY_NAME_STR = "info" ;
71+
72+ private static final byte [] FAMILY_NAME = Bytes .toBytes (FAMILY_NAME_STR );
7073
7174 @ Rule
72- public TestName name = new TestName ();
75+ public TableNameTestRule name = new TableNameTestRule ();
7376
7477 @ BeforeClass
7578 public static void setupClass () throws Exception {
76- TEST_UTIL .getConfiguration ().set (TRACKER_IMPL , TestStoreFileTracker .class .getName ());
7779 TEST_UTIL .startMiniCluster ();
7880 }
7981
@@ -84,13 +86,24 @@ public static void afterClass() throws Exception {
8486
8587 @ Before
8688 public void setup (){
87- TestStoreFileTracker .trackedFiles = new HashMap <>();
89+ TestStoreFileTracker .clear ();
90+ }
91+
92+ private TableName createTable (byte [] splitKey ) throws IOException {
93+ TableDescriptor td = TableDescriptorBuilder .newBuilder (name .getTableName ())
94+ .setColumnFamily (ColumnFamilyDescriptorBuilder .of (FAMILY_NAME ))
95+ .setValue (TRACKER_IMPL , TestStoreFileTracker .class .getName ()).build ();
96+ if (splitKey != null ) {
97+ TEST_UTIL .getAdmin ().createTable (td , new byte [][] { splitKey });
98+ } else {
99+ TEST_UTIL .getAdmin ().createTable (td );
100+ }
101+ return td .getTableName ();
88102 }
89103
90104 @ Test
91105 public void testCommitDaughterRegion () throws Exception {
92- TableName table = TableName .valueOf (name .getMethodName ());
93- TEST_UTIL .createTable (table , FAMILY_NAME );
106+ TableName table = createTable (null );
94107 //first put some data in order to have a store file created
95108 putThreeRowsAndFlush (table );
96109 HRegion region = TEST_UTIL .getHBaseCluster ().getRegions (table ).get (0 );
@@ -124,8 +137,7 @@ public void testCommitDaughterRegion() throws Exception {
124137
125138 @ Test
126139 public void testCommitMergedRegion () throws Exception {
127- TableName table = TableName .valueOf (name .getMethodName ());
128- TEST_UTIL .createTable (table , FAMILY_NAME );
140+ TableName table = createTable (null );
129141 //splitting the table first
130142 split (table , Bytes .toBytes ("002" ));
131143 //Add data and flush to create files in the two different regions
@@ -162,8 +174,7 @@ public void testCommitMergedRegion() throws Exception {
162174
163175 @ Test
164176 public void testSplitLoadsFromTracker () throws Exception {
165- TableName table = TableName .valueOf (name .getMethodName ());
166- TEST_UTIL .createTable (table , FAMILY_NAME );
177+ TableName table = createTable (null );
167178 //Add data and flush to create files in the two different regions
168179 putThreeRowsAndFlush (table );
169180 HRegion region = TEST_UTIL .getHBaseCluster ().getRegions (table ).get (0 );
@@ -187,9 +198,7 @@ private void split(TableName table, byte[] splitKey) throws IOException {
187198
188199 @ Test
189200 public void testMergeLoadsFromTracker () throws Exception {
190- TableName table = TableName .valueOf (name .getMethodName ());
191- TEST_UTIL .createTable (table , new byte [][]{FAMILY_NAME },
192- new byte [][]{Bytes .toBytes ("002" )});
201+ TableName table = createTable (Bytes .toBytes ("002" ));
193202 //Add data and flush to create files in the two different regions
194203 putThreeRowsAndFlush (table );
195204 List <HRegion > regions = TEST_UTIL .getHBaseCluster ().getRegions (table );
@@ -237,10 +246,8 @@ private void validateDaughterRegionsFiles(HRegion region, String orignalFileName
237246 }
238247
239248 private void verifyFilesAreTracked (Path regionDir , FileSystem fs ) throws Exception {
240- String storeId = regionDir .getName () + "-info" ;
241- for (FileStatus f : fs .listStatus (new Path (regionDir , Bytes .toString (FAMILY_NAME )))){
242- assertTrue (TestStoreFileTracker .trackedFiles .get (storeId ).stream ().filter (s ->
243- s .getPath ().equals (f .getPath ())).findFirst ().isPresent ());
249+ for (FileStatus f : fs .listStatus (new Path (regionDir , FAMILY_NAME_STR ))) {
250+ assertTrue (TestStoreFileTracker .tracked (regionDir .getName (), FAMILY_NAME_STR , f .getPath ()));
244251 }
245252 }
246253
0 commit comments