| 
19 | 19 | 
 
  | 
20 | 20 | import static org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil.insertData;  | 
21 | 21 | import static org.junit.Assert.assertEquals;  | 
 | 22 | +import static org.junit.Assert.assertNotNull;  | 
22 | 23 | import static org.junit.Assert.assertTrue;  | 
 | 24 | + | 
23 | 25 | import java.util.List;  | 
24 | 26 | import java.util.Map;  | 
25 | 27 | import org.apache.hadoop.conf.Configuration;  | 
 | 
39 | 41 | import org.apache.hadoop.hbase.testclassification.MediumTests;  | 
40 | 42 | import org.apache.hadoop.hbase.util.Bytes;  | 
41 | 43 | import org.apache.hadoop.hbase.util.JVMClusterUtil;  | 
 | 44 | + | 
42 | 45 | import org.junit.After;  | 
43 | 46 | import org.junit.AfterClass;  | 
44 | 47 | import org.junit.Before;  | 
@@ -157,6 +160,54 @@ public void testSplitTableRegion() throws Exception {  | 
157 | 160 |       regionInfoMap.get(tableRegions.get(1).getRegionInfo()));  | 
158 | 161 |   }  | 
159 | 162 | 
 
  | 
 | 163 | +  @Test  | 
 | 164 | +  public void testSplitStoreFiles() throws Exception {  | 
 | 165 | +    final TableName tableName = TableName.valueOf(name.getMethodName());  | 
 | 166 | +    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();  | 
 | 167 | + | 
 | 168 | +    RegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName,  | 
 | 169 | +      null, columnFamilyName);  | 
 | 170 | +    // flush the memstore  | 
 | 171 | +    insertData(UTIL, tableName, rowCount, startRowNum, true, columnFamilyName);  | 
 | 172 | + | 
 | 173 | +    // assert the hfile count of the table  | 
 | 174 | +    int storeFilesCountSum = 0;  | 
 | 175 | +    for(HRegion region : UTIL.getHBaseCluster().getRegions(tableName)){  | 
 | 176 | +      storeFilesCountSum += region.getStore(Bytes.toBytes(columnFamilyName)).getStorefiles().size();  | 
 | 177 | +    }  | 
 | 178 | +    assertEquals(1, storeFilesCountSum);  | 
 | 179 | + | 
 | 180 | +    // split at the start row  | 
 | 181 | +    byte[] splitKey = Bytes.toBytes("" + startRowNum);  | 
 | 182 | + | 
 | 183 | +    assertNotNull("Not able to find a splittable region", regions);  | 
 | 184 | +    assertEquals("Not able to find a splittable region", 1, regions.length);  | 
 | 185 | + | 
 | 186 | +    // Split region of the table  | 
 | 187 | +    long procId = procExec.submitProcedure(  | 
 | 188 | +      new SplitTableRegionProcedure(procExec.getEnvironment(), regions[0], splitKey));  | 
 | 189 | +    // Wait the completion  | 
 | 190 | +    ProcedureTestingUtility.waitProcedure(procExec, procId);  | 
 | 191 | +    ProcedureTestingUtility.assertProcNotFailed(procExec, procId);  | 
 | 192 | + | 
 | 193 | +    assertEquals("Not able to split table",  | 
 | 194 | +      2, UTIL.getHBaseCluster().getRegions(tableName).size());  | 
 | 195 | + | 
 | 196 | +    // assert sum of the hfiles of all regions  | 
 | 197 | +    int childStoreFilesSum = 0;  | 
 | 198 | +    for(HRegion region : UTIL.getHBaseCluster().getRegions(tableName)){  | 
 | 199 | +      childStoreFilesSum += region.getStore(Bytes.toBytes(columnFamilyName)).getStorefiles().size();  | 
 | 200 | +    }  | 
 | 201 | +    assertEquals(1, childStoreFilesSum);  | 
 | 202 | + | 
 | 203 | +    List<HRegion> tableRegions = UTIL.getHBaseCluster().getRegions(tableName);  | 
 | 204 | +    assertEquals("Table region not correct.", 2, tableRegions.size());  | 
 | 205 | +    Map<RegionInfo, ServerName> regionInfoMap = UTIL.getHBaseCluster().getMaster()  | 
 | 206 | +      .getAssignmentManager().getRegionStates().getRegionAssignments();  | 
 | 207 | +    assertEquals(regionInfoMap.get(tableRegions.get(0).getRegionInfo()),  | 
 | 208 | +      regionInfoMap.get(tableRegions.get(1).getRegionInfo()));  | 
 | 209 | +  }  | 
 | 210 | + | 
160 | 211 |   private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {  | 
161 | 212 |     return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();  | 
162 | 213 |   }  | 
 | 
0 commit comments