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.regionserver;
019
020import static org.junit.Assert.assertArrayEquals;
021import static org.junit.Assert.assertEquals;
022import static org.junit.Assert.assertFalse;
023import static org.junit.Assert.assertNotEquals;
024import static org.junit.Assert.assertTrue;
025import static org.junit.Assert.fail;
026
027import java.io.IOException;
028import org.apache.hadoop.conf.Configuration;
029import org.apache.hadoop.fs.FileStatus;
030import org.apache.hadoop.fs.Path;
031import org.apache.hadoop.hbase.HBaseClassTestRule;
032import org.apache.hadoop.hbase.HBaseTestingUtility;
033import org.apache.hadoop.hbase.HConstants;
034import org.apache.hadoop.hbase.HRegionInfo;
035import org.apache.hadoop.hbase.HTableDescriptor;
036import org.apache.hadoop.hbase.TableName;
037import org.apache.hadoop.hbase.client.RegionInfo;
038import org.apache.hadoop.hbase.client.RegionInfoBuilder;
039import org.apache.hadoop.hbase.exceptions.DeserializationException;
040import org.apache.hadoop.hbase.master.RegionState;
041import org.apache.hadoop.hbase.testclassification.RegionServerTests;
042import org.apache.hadoop.hbase.testclassification.SmallTests;
043import org.apache.hadoop.hbase.util.Bytes;
044import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
045import org.apache.hadoop.hbase.util.FSTableDescriptors;
046import org.apache.hadoop.hbase.util.MD5Hash;
047import org.junit.Assert;
048import org.junit.ClassRule;
049import org.junit.Rule;
050import org.junit.Test;
051import org.junit.experimental.categories.Category;
052import org.junit.rules.TestName;
053
054import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
055
056import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
057
058@Category({ RegionServerTests.class, SmallTests.class })
059public class TestHRegionInfo {
060
061  @ClassRule
062  public static final HBaseClassTestRule CLASS_RULE =
063    HBaseClassTestRule.forClass(TestHRegionInfo.class);
064
065  @Rule
066  public TestName name = new TestName();
067
068  @Test
069  public void testIsStart() {
070    assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isFirst());
071    org.apache.hadoop.hbase.client.RegionInfo ri = org.apache.hadoop.hbase.client.RegionInfoBuilder
072      .newBuilder(TableName.META_TABLE_NAME).setStartKey(Bytes.toBytes("not_start")).build();
073    assertFalse(ri.isFirst());
074  }
075
076  @Test
077  public void testIsEnd() {
078    assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isFirst());
079    org.apache.hadoop.hbase.client.RegionInfo ri = org.apache.hadoop.hbase.client.RegionInfoBuilder
080      .newBuilder(TableName.META_TABLE_NAME).setEndKey(Bytes.toBytes("not_end")).build();
081    assertFalse(ri.isLast());
082  }
083
084  @Test
085  public void testIsNext() {
086    byte[] bytes = Bytes.toBytes("row");
087    org.apache.hadoop.hbase.client.RegionInfo ri = org.apache.hadoop.hbase.client.RegionInfoBuilder
088      .newBuilder(TableName.META_TABLE_NAME).setEndKey(bytes).build();
089    org.apache.hadoop.hbase.client.RegionInfo ri2 = org.apache.hadoop.hbase.client.RegionInfoBuilder
090      .newBuilder(TableName.META_TABLE_NAME).setStartKey(bytes).build();
091    assertFalse(ri.isNext(RegionInfoBuilder.FIRST_META_REGIONINFO));
092    assertTrue(ri.isNext(ri2));
093  }
094
095  @Test
096  public void testIsOverlap() {
097    byte[] a = Bytes.toBytes("a");
098    byte[] b = Bytes.toBytes("b");
099    byte[] c = Bytes.toBytes("c");
100    byte[] d = Bytes.toBytes("d");
101    org.apache.hadoop.hbase.client.RegionInfo all = RegionInfoBuilder.FIRST_META_REGIONINFO;
102    org.apache.hadoop.hbase.client.RegionInfo ari = org.apache.hadoop.hbase.client.RegionInfoBuilder
103      .newBuilder(TableName.META_TABLE_NAME).setEndKey(a).build();
104    org.apache.hadoop.hbase.client.RegionInfo abri =
105      org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
106        .setStartKey(a).setEndKey(b).build();
107    org.apache.hadoop.hbase.client.RegionInfo adri =
108      org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
109        .setStartKey(a).setEndKey(d).build();
110    org.apache.hadoop.hbase.client.RegionInfo cdri =
111      org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
112        .setStartKey(c).setEndKey(d).build();
113    org.apache.hadoop.hbase.client.RegionInfo dri = org.apache.hadoop.hbase.client.RegionInfoBuilder
114      .newBuilder(TableName.META_TABLE_NAME).setStartKey(d).build();
115    assertTrue(all.isOverlap(all));
116    assertTrue(all.isOverlap(abri));
117    assertFalse(abri.isOverlap(cdri));
118    assertTrue(all.isOverlap(ari));
119    assertFalse(ari.isOverlap(abri));
120    assertFalse(ari.isOverlap(abri));
121    assertTrue(ari.isOverlap(all));
122    assertTrue(dri.isOverlap(all));
123    assertTrue(abri.isOverlap(adri));
124    assertFalse(dri.isOverlap(ari));
125    assertTrue(abri.isOverlap(adri));
126    assertTrue(adri.isOverlap(abri));
127  }
128
129  /**
130   * Tests {@link RegionInfo#isOverlap(RegionInfo[])}
131   */
132  @Test
133  public void testIsOverlaps() {
134    byte[] a = Bytes.toBytes("a");
135    byte[] b = Bytes.toBytes("b");
136    byte[] c = Bytes.toBytes("c");
137    byte[] d = Bytes.toBytes("d");
138    byte[] e = Bytes.toBytes("e");
139    byte[] f = Bytes.toBytes("f");
140    org.apache.hadoop.hbase.client.RegionInfo ari = org.apache.hadoop.hbase.client.RegionInfoBuilder
141      .newBuilder(TableName.META_TABLE_NAME).setEndKey(a).build();
142    org.apache.hadoop.hbase.client.RegionInfo abri =
143      org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
144        .setStartKey(a).setEndKey(b).build();
145    org.apache.hadoop.hbase.client.RegionInfo eri = org.apache.hadoop.hbase.client.RegionInfoBuilder
146      .newBuilder(TableName.META_TABLE_NAME).setEndKey(e).build();
147    org.apache.hadoop.hbase.client.RegionInfo cdri =
148      org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
149        .setStartKey(c).setEndKey(d).build();
150    org.apache.hadoop.hbase.client.RegionInfo efri =
151      org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME)
152        .setStartKey(e).setEndKey(f).build();
153  }
154
155  @Test
156  public void testPb() throws DeserializationException {
157    HRegionInfo hri = HRegionInfo.FIRST_META_REGIONINFO;
158    byte[] bytes = hri.toByteArray();
159    HRegionInfo pbhri = HRegionInfo.parseFrom(bytes);
160    assertTrue(hri.equals(pbhri));
161  }
162
163  @Test
164  public void testReadAndWriteHRegionInfoFile() throws IOException, InterruptedException {
165    HBaseTestingUtility htu = new HBaseTestingUtility();
166    HRegionInfo hri = HRegionInfo.FIRST_META_REGIONINFO;
167    Path basedir = htu.getDataTestDir();
168    // Create a region. That'll write the .regioninfo file.
169    FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(htu.getConfiguration());
170    FSTableDescriptors.tryUpdateMetaTableDescriptor(htu.getConfiguration());
171    HRegion r = HBaseTestingUtility.createRegionAndWAL(hri, basedir, htu.getConfiguration(),
172      fsTableDescriptors.get(TableName.META_TABLE_NAME));
173    // Get modtime on the file.
174    long modtime = getModTime(r);
175    HBaseTestingUtility.closeRegionAndWAL(r);
176    Thread.sleep(1001);
177    r = HRegion.openHRegion(basedir, hri, fsTableDescriptors.get(TableName.META_TABLE_NAME), null,
178      htu.getConfiguration());
179    // Ensure the file is not written for a second time.
180    long modtime2 = getModTime(r);
181    assertEquals(modtime, modtime2);
182    // Now load the file.
183    org.apache.hadoop.hbase.client.RegionInfo deserializedHri =
184      HRegionFileSystem.loadRegionInfoFileContent(r.getRegionFileSystem().getFileSystem(),
185        r.getRegionFileSystem().getRegionDir());
186    assertEquals(0,
187      org.apache.hadoop.hbase.client.RegionInfo.COMPARATOR.compare(hri, deserializedHri));
188    HBaseTestingUtility.closeRegionAndWAL(r);
189  }
190
191  long getModTime(final HRegion r) throws IOException {
192    FileStatus[] statuses = r.getRegionFileSystem().getFileSystem().listStatus(
193      new Path(r.getRegionFileSystem().getRegionDir(), HRegionFileSystem.REGION_INFO_FILE));
194    assertTrue(statuses != null && statuses.length == 1);
195    return statuses[0].getModificationTime();
196  }
197
198  @Test
199  public void testCreateHRegionInfoName() throws Exception {
200    final String tableName = name.getMethodName();
201    final TableName tn = TableName.valueOf(tableName);
202    String startKey = "startkey";
203    final byte[] sk = Bytes.toBytes(startKey);
204    String id = "id";
205
206    // old format region name
207    byte[] name = HRegionInfo.createRegionName(tn, sk, id, false);
208    String nameStr = Bytes.toString(name);
209    assertEquals(tableName + "," + startKey + "," + id, nameStr);
210
211    // new format region name.
212    String md5HashInHex = MD5Hash.getMD5AsHex(name);
213    assertEquals(HRegionInfo.MD5_HEX_LENGTH, md5HashInHex.length());
214    name = HRegionInfo.createRegionName(tn, sk, id, true);
215    nameStr = Bytes.toString(name);
216    assertEquals(tableName + "," + startKey + "," + id + "." + md5HashInHex + ".", nameStr);
217  }
218
219  @Test
220  public void testContainsRange() {
221    HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
222    HRegionInfo hri =
223      new HRegionInfo(tableDesc.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("g"));
224    // Single row range at start of region
225    assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("a")));
226    // Fully contained range
227    assertTrue(hri.containsRange(Bytes.toBytes("b"), Bytes.toBytes("c")));
228    // Range overlapping start of region
229    assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("c")));
230    // Fully contained single-row range
231    assertTrue(hri.containsRange(Bytes.toBytes("c"), Bytes.toBytes("c")));
232    // Range that overlaps end key and hence doesn't fit
233    assertFalse(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("g")));
234    // Single row range on end key
235    assertFalse(hri.containsRange(Bytes.toBytes("g"), Bytes.toBytes("g")));
236    // Single row range entirely outside
237    assertFalse(hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("z")));
238
239    // Degenerate range
240    try {
241      hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("a"));
242      fail("Invalid range did not throw IAE");
243    } catch (IllegalArgumentException iae) {
244    }
245  }
246
247  @Test
248  public void testContainsRangeForMetaTable() {
249    HTableDescriptor tableDesc = new HTableDescriptor(TableName.META_TABLE_NAME);
250    RegionInfo hri = RegionInfoBuilder.newBuilder(tableDesc.getTableName()).build();
251    byte[] startRow = HConstants.EMPTY_START_ROW;
252    byte[] row1 = Bytes.toBytes("a,a,0");
253    byte[] row2 = Bytes.toBytes("aaaaa,,1");
254    byte[] row3 = Bytes.toBytes("aaaaa,\u0000\u0000,2");
255    byte[] row4 = Bytes.toBytes("aaaaa,\u0001,3");
256    byte[] row5 = Bytes.toBytes("aaaaa,a,4");
257    byte[] row6 = Bytes.toBytes("aaaaa,\u1000,5");
258
259    // Single row range at start of region
260    assertTrue(hri.containsRange(startRow, startRow));
261    // Fully contained range
262    assertTrue(hri.containsRange(row1, row2));
263    assertTrue(hri.containsRange(row2, row3));
264    assertTrue(hri.containsRange(row3, row4));
265    assertTrue(hri.containsRange(row4, row5));
266    assertTrue(hri.containsRange(row5, row6));
267    // Range overlapping start of region
268    assertTrue(hri.containsRange(startRow, row2));
269    // Fully contained single-row range
270    assertTrue(hri.containsRange(row1, row1));
271    // Degenerate range
272    try {
273      hri.containsRange(row3, row2);
274      fail("Invalid range did not throw IAE");
275    } catch (IllegalArgumentException iae) {
276    }
277  }
278
279  @Test
280  public void testLastRegionCompare() {
281    HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
282    HRegionInfo hrip = new HRegionInfo(tableDesc.getTableName(), Bytes.toBytes("a"), new byte[0]);
283    HRegionInfo hric =
284      new HRegionInfo(tableDesc.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("b"));
285    assertTrue(hrip.compareTo(hric) > 0);
286  }
287
288  @Test
289  public void testMetaTables() {
290    assertTrue(HRegionInfo.FIRST_META_REGIONINFO.isMetaRegion());
291  }
292
293  @SuppressWarnings("SelfComparison")
294  @Test
295  public void testComparator() {
296    final TableName tableName = TableName.valueOf(name.getMethodName());
297    byte[] empty = new byte[0];
298    HRegionInfo older = new HRegionInfo(tableName, empty, empty, false, 0L);
299    HRegionInfo newer = new HRegionInfo(tableName, empty, empty, false, 1L);
300    assertTrue(older.compareTo(newer) < 0);
301    assertTrue(newer.compareTo(older) > 0);
302    assertEquals(0, older.compareTo(older));
303    assertEquals(0, newer.compareTo(newer));
304
305    HRegionInfo a = new HRegionInfo(TableName.valueOf("a"), null, null);
306    HRegionInfo b = new HRegionInfo(TableName.valueOf("b"), null, null);
307    assertNotEquals(0, a.compareTo(b));
308    HTableDescriptor t = new HTableDescriptor(TableName.valueOf("t"));
309    byte[] midway = Bytes.toBytes("midway");
310    a = new HRegionInfo(t.getTableName(), null, midway);
311    b = new HRegionInfo(t.getTableName(), midway, null);
312    assertTrue(a.compareTo(b) < 0);
313    assertTrue(b.compareTo(a) > 0);
314    assertTrue(a.equals(a));
315    assertEquals(0, a.compareTo(a));
316    a = new HRegionInfo(t.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("d"));
317    b = new HRegionInfo(t.getTableName(), Bytes.toBytes("e"), Bytes.toBytes("g"));
318    assertTrue(a.compareTo(b) < 0);
319    a = new HRegionInfo(t.getTableName(), Bytes.toBytes("aaaa"), Bytes.toBytes("dddd"));
320    b = new HRegionInfo(t.getTableName(), Bytes.toBytes("e"), Bytes.toBytes("g"));
321    assertTrue(a.compareTo(b) < 0);
322    a = new HRegionInfo(t.getTableName(), Bytes.toBytes("aaaa"), Bytes.toBytes("dddd"));
323    b = new HRegionInfo(t.getTableName(), Bytes.toBytes("aaaa"), Bytes.toBytes("eeee"));
324    assertTrue(a.compareTo(b) < 0);
325
326  }
327
328  @Test
329  public void testRegionNameForRegionReplicas() throws Exception {
330    String tableName = name.getMethodName();
331    final TableName tn = TableName.valueOf(tableName);
332    String startKey = "startkey";
333    final byte[] sk = Bytes.toBytes(startKey);
334    String id = "id";
335
336    // assert with only the region name without encoding
337
338    // primary, replicaId = 0
339    byte[] name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0, false);
340    String nameStr = Bytes.toString(name);
341    assertEquals(tableName + "," + startKey + "," + id, nameStr);
342
343    // replicaId = 1
344    name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 1, false);
345    nameStr = Bytes.toString(name);
346    assertEquals(
347      tableName + "," + startKey + "," + id + "_" + String.format(HRegionInfo.REPLICA_ID_FORMAT, 1),
348      nameStr);
349
350    // replicaId = max
351    name = HRegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0xFFFF, false);
352    nameStr = Bytes.toString(name);
353    assertEquals(tableName + "," + startKey + "," + id + "_"
354      + String.format(HRegionInfo.REPLICA_ID_FORMAT, 0xFFFF), nameStr);
355  }
356
357  @Test
358  public void testParseName() throws IOException {
359    final TableName tableName = TableName.valueOf(name.getMethodName());
360    byte[] startKey = Bytes.toBytes("startKey");
361    long regionId = EnvironmentEdgeManager.currentTime();
362    int replicaId = 42;
363
364    // test without replicaId
365    byte[] regionName = HRegionInfo.createRegionName(tableName, startKey, regionId, false);
366
367    byte[][] fields = HRegionInfo.parseRegionName(regionName);
368    assertArrayEquals(Bytes.toString(fields[0]), tableName.getName(), fields[0]);
369    assertArrayEquals(Bytes.toString(fields[1]), startKey, fields[1]);
370    assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)), fields[2]);
371    assertEquals(3, fields.length);
372
373    // test with replicaId
374    regionName = HRegionInfo.createRegionName(tableName, startKey, regionId, replicaId, false);
375
376    fields = HRegionInfo.parseRegionName(regionName);
377    assertArrayEquals(Bytes.toString(fields[0]), tableName.getName(), fields[0]);
378    assertArrayEquals(Bytes.toString(fields[1]), startKey, fields[1]);
379    assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)), fields[2]);
380    assertArrayEquals(Bytes.toString(fields[3]),
381      Bytes.toBytes(String.format(HRegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]);
382  }
383
384  @Test
385  public void testConvert() {
386    final TableName tableName = TableName.valueOf("ns1:" + name.getMethodName());
387    byte[] startKey = Bytes.toBytes("startKey");
388    byte[] endKey = Bytes.toBytes("endKey");
389    boolean split = false;
390    long regionId = EnvironmentEdgeManager.currentTime();
391    int replicaId = 42;
392
393    HRegionInfo hri = new HRegionInfo(tableName, startKey, endKey, split, regionId, replicaId);
394
395    // convert two times, compare
396    HRegionInfo convertedHri = HRegionInfo.convert(HRegionInfo.convert(hri));
397
398    assertEquals(hri, convertedHri);
399
400    // test convert RegionInfo without replicaId
401    HBaseProtos.RegionInfo info = HBaseProtos.RegionInfo.newBuilder()
402      .setTableName(HBaseProtos.TableName.newBuilder()
403        .setQualifier(UnsafeByteOperations.unsafeWrap(tableName.getQualifier()))
404        .setNamespace(UnsafeByteOperations.unsafeWrap(tableName.getNamespace())).build())
405      .setStartKey(UnsafeByteOperations.unsafeWrap(startKey))
406      .setEndKey(UnsafeByteOperations.unsafeWrap(endKey)).setSplit(split).setRegionId(regionId)
407      .build();
408
409    convertedHri = HRegionInfo.convert(info);
410    HRegionInfo expectedHri = new HRegionInfo(tableName, startKey, endKey, split, regionId, 0); // expecting
411                                                                                                // default
412                                                                                                // replicaId
413
414    assertEquals(expectedHri, convertedHri);
415  }
416
417  @Test
418  public void testRegionDetailsForDisplay() throws IOException {
419    byte[] startKey = new byte[] { 0x01, 0x01, 0x02, 0x03 };
420    byte[] endKey = new byte[] { 0x01, 0x01, 0x02, 0x04 };
421    Configuration conf = new Configuration();
422    conf.setBoolean("hbase.display.keys", false);
423    HRegionInfo h = new HRegionInfo(TableName.valueOf(name.getMethodName()), startKey, endKey);
424    checkEquality(h, conf);
425    // check HRIs with non-default replicaId
426    h = new HRegionInfo(TableName.valueOf(name.getMethodName()), startKey, endKey, false,
427      EnvironmentEdgeManager.currentTime(), 1);
428    checkEquality(h, conf);
429    Assert.assertArrayEquals(HRegionInfo.HIDDEN_END_KEY, HRegionInfo.getEndKeyForDisplay(h, conf));
430    Assert.assertArrayEquals(HRegionInfo.HIDDEN_START_KEY,
431      HRegionInfo.getStartKeyForDisplay(h, conf));
432
433    RegionState state = RegionState.createForTesting(h, RegionState.State.OPEN);
434    String descriptiveNameForDisplay =
435      HRegionInfo.getDescriptiveNameFromRegionStateForDisplay(state, conf);
436    checkDescriptiveNameEquality(descriptiveNameForDisplay, state.toDescriptiveString(), startKey);
437
438    conf.setBoolean("hbase.display.keys", true);
439    Assert.assertArrayEquals(endKey, HRegionInfo.getEndKeyForDisplay(h, conf));
440    Assert.assertArrayEquals(startKey, HRegionInfo.getStartKeyForDisplay(h, conf));
441    Assert.assertEquals(state.toDescriptiveString(),
442      HRegionInfo.getDescriptiveNameFromRegionStateForDisplay(state, conf));
443  }
444
445  private void checkDescriptiveNameEquality(String descriptiveNameForDisplay, String origDesc,
446    byte[] startKey) {
447    // except for the "hidden-start-key" substring everything else should exactly match
448    String firstPart = descriptiveNameForDisplay.substring(0,
449      descriptiveNameForDisplay.indexOf(new String(HRegionInfo.HIDDEN_START_KEY)));
450    String secondPart = descriptiveNameForDisplay
451      .substring(descriptiveNameForDisplay.indexOf(new String(HRegionInfo.HIDDEN_START_KEY))
452        + HRegionInfo.HIDDEN_START_KEY.length);
453    String firstPartOrig = origDesc.substring(0, origDesc.indexOf(Bytes.toStringBinary(startKey)));
454    String secondPartOrig = origDesc.substring(
455      origDesc.indexOf(Bytes.toStringBinary(startKey)) + Bytes.toStringBinary(startKey).length());
456    assert (firstPart.equals(firstPartOrig));
457    assert (secondPart.equals(secondPartOrig));
458  }
459
460  private void checkEquality(HRegionInfo h, Configuration conf) throws IOException {
461    byte[] modifiedRegionName = HRegionInfo.getRegionNameForDisplay(h, conf);
462    byte[][] modifiedRegionNameParts = HRegionInfo.parseRegionName(modifiedRegionName);
463    byte[][] regionNameParts = HRegionInfo.parseRegionName(h.getRegionName());
464
465    // same number of parts
466    assert (modifiedRegionNameParts.length == regionNameParts.length);
467
468    for (int i = 0; i < regionNameParts.length; i++) {
469      // all parts should match except for [1] where in the modified one,
470      // we should have "hidden_start_key"
471      if (i != 1) {
472        Assert.assertArrayEquals(regionNameParts[i], modifiedRegionNameParts[i]);
473      } else {
474        assertNotEquals(regionNameParts[i][0], modifiedRegionNameParts[i][0]);
475        Assert.assertArrayEquals(modifiedRegionNameParts[1],
476          HRegionInfo.getStartKeyForDisplay(h, conf));
477      }
478    }
479  }
480}