HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestRegionInfo.java
blob56a8ea061e0af1c04f8d10cb7e566cfc094f7352
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.regionserver;
20 import static org.junit.Assert.assertArrayEquals;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertNotEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import java.io.IOException;
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.fs.FileStatus;
30 import org.apache.hadoop.fs.Path;
31 import org.apache.hadoop.hbase.HBaseClassTestRule;
32 import org.apache.hadoop.hbase.HBaseTestingUtil;
33 import org.apache.hadoop.hbase.HConstants;
34 import org.apache.hadoop.hbase.TableName;
35 import org.apache.hadoop.hbase.client.RegionInfo;
36 import org.apache.hadoop.hbase.client.RegionInfoBuilder;
37 import org.apache.hadoop.hbase.client.RegionInfoDisplay;
38 import org.apache.hadoop.hbase.client.TableDescriptor;
39 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
40 import org.apache.hadoop.hbase.exceptions.DeserializationException;
41 import org.apache.hadoop.hbase.master.RegionState;
42 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
43 import org.apache.hadoop.hbase.testclassification.SmallTests;
44 import org.apache.hadoop.hbase.util.Bytes;
45 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
46 import org.apache.hadoop.hbase.util.FSTableDescriptors;
47 import org.apache.hadoop.hbase.util.MD5Hash;
48 import org.junit.Assert;
49 import org.junit.ClassRule;
50 import org.junit.Rule;
51 import org.junit.Test;
52 import org.junit.experimental.categories.Category;
53 import org.junit.rules.TestName;
55 import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
57 import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
58 import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
60 @Category({RegionServerTests.class, SmallTests.class})
61 public class TestRegionInfo {
63 @ClassRule
64 public static final HBaseClassTestRule CLASS_RULE =
65 HBaseClassTestRule.forClass(TestRegionInfo.class);
67 @Rule
68 public TestName name = new TestName();
70 @Test
71 public void testIsStart() {
72 assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isFirst());
73 org.apache.hadoop.hbase.client.RegionInfo ri =
74 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
75 setStartKey(Bytes.toBytes("not_start")).build();
76 assertFalse(ri.isFirst());
79 @Test
80 public void testIsEnd() {
81 assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isFirst());
82 org.apache.hadoop.hbase.client.RegionInfo ri =
83 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
84 setEndKey(Bytes.toBytes("not_end")).build();
85 assertFalse(ri.isLast());
88 @Test
89 public void testIsNext() {
90 byte [] bytes = Bytes.toBytes("row");
91 org.apache.hadoop.hbase.client.RegionInfo ri =
92 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
93 setEndKey(bytes).build();
94 org.apache.hadoop.hbase.client.RegionInfo ri2 =
95 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
96 setStartKey(bytes).build();
97 assertFalse(ri.isNext(RegionInfoBuilder.FIRST_META_REGIONINFO));
98 assertTrue(ri.isNext(ri2));
101 @Test
102 public void testIsOverlap() {
103 byte [] a = Bytes.toBytes("a");
104 byte [] b = Bytes.toBytes("b");
105 byte [] c = Bytes.toBytes("c");
106 byte [] d = Bytes.toBytes("d");
107 org.apache.hadoop.hbase.client.RegionInfo all =
108 RegionInfoBuilder.FIRST_META_REGIONINFO;
109 org.apache.hadoop.hbase.client.RegionInfo ari =
110 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
111 setEndKey(a).build();
112 org.apache.hadoop.hbase.client.RegionInfo abri =
113 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
114 setStartKey(a).setEndKey(b).build();
115 org.apache.hadoop.hbase.client.RegionInfo adri =
116 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
117 setStartKey(a).setEndKey(d).build();
118 org.apache.hadoop.hbase.client.RegionInfo cdri =
119 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
120 setStartKey(c).setEndKey(d).build();
121 org.apache.hadoop.hbase.client.RegionInfo dri =
122 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
123 setStartKey(d).build();
124 assertTrue(all.isOverlap(all));
125 assertTrue(all.isOverlap(abri));
126 assertFalse(abri.isOverlap(cdri));
127 assertTrue(all.isOverlap(ari));
128 assertFalse(ari.isOverlap(abri));
129 assertFalse(ari.isOverlap(abri));
130 assertTrue(ari.isOverlap(all));
131 assertTrue(dri.isOverlap(all));
132 assertTrue(abri.isOverlap(adri));
133 assertFalse(dri.isOverlap(ari));
134 assertTrue(abri.isOverlap(adri));
135 assertTrue(adri.isOverlap(abri));
139 * Tests {@link RegionInfo#isOverlap(RegionInfo)}
141 @Test
142 public void testIsOverlaps() {
143 byte[] a = Bytes.toBytes("a");
144 byte[] b = Bytes.toBytes("b");
145 byte[] c = Bytes.toBytes("c");
146 byte[] d = Bytes.toBytes("d");
147 byte[] e = Bytes.toBytes("e");
148 byte[] f = Bytes.toBytes("f");
149 org.apache.hadoop.hbase.client.RegionInfo ari =
150 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
151 setEndKey(a).build();
152 org.apache.hadoop.hbase.client.RegionInfo abri =
153 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
154 setStartKey(a).setEndKey(b).build();
155 org.apache.hadoop.hbase.client.RegionInfo eri =
156 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
157 setEndKey(e).build();
158 org.apache.hadoop.hbase.client.RegionInfo cdri =
159 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
160 setStartKey(c).setEndKey(d).build();
161 org.apache.hadoop.hbase.client.RegionInfo efri =
162 org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).
163 setStartKey(e).setEndKey(f).build();
164 assertFalse(ari.isOverlap(abri));
165 assertTrue(abri.isOverlap(eri));
166 assertFalse(cdri.isOverlap(efri));
167 assertTrue(eri.isOverlap(ari));
170 @Test
171 public void testPb() throws DeserializationException {
172 RegionInfo hri = RegionInfoBuilder.FIRST_META_REGIONINFO;
173 byte [] bytes = RegionInfo.toByteArray(hri);
174 RegionInfo pbhri = RegionInfo.parseFrom(bytes);
175 assertTrue(hri.equals(pbhri));
178 @Test
179 public void testReadAndWriteHRegionInfoFile() throws IOException, InterruptedException {
180 HBaseTestingUtil htu = new HBaseTestingUtil();
181 RegionInfo hri = RegionInfoBuilder.FIRST_META_REGIONINFO;
182 Path basedir = htu.getDataTestDir();
183 // Create a region. That'll write the .regioninfo file.
184 FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(htu.getConfiguration());
185 FSTableDescriptors.tryUpdateMetaTableDescriptor(htu.getConfiguration());
186 HRegion r = HBaseTestingUtil.createRegionAndWAL(hri, basedir, htu.getConfiguration(),
187 fsTableDescriptors.get(TableName.META_TABLE_NAME));
188 // Get modtime on the file.
189 long modtime = getModTime(r);
190 HBaseTestingUtil.closeRegionAndWAL(r);
191 Thread.sleep(1001);
192 r = HRegion.openHRegion(basedir, hri, fsTableDescriptors.get(TableName.META_TABLE_NAME),
193 null, htu.getConfiguration());
194 // Ensure the file is not written for a second time.
195 long modtime2 = getModTime(r);
196 assertEquals(modtime, modtime2);
197 // Now load the file.
198 org.apache.hadoop.hbase.client.RegionInfo deserializedHri =
199 HRegionFileSystem.loadRegionInfoFileContent(
200 r.getRegionFileSystem().getFileSystem(), r.getRegionFileSystem().getRegionDir());
201 assertEquals(0,
202 org.apache.hadoop.hbase.client.RegionInfo.COMPARATOR.compare(hri, deserializedHri));
203 HBaseTestingUtil.closeRegionAndWAL(r);
206 long getModTime(final HRegion r) throws IOException {
207 FileStatus[] statuses = r.getRegionFileSystem().getFileSystem().listStatus(
208 new Path(r.getRegionFileSystem().getRegionDir(), HRegionFileSystem.REGION_INFO_FILE));
209 assertTrue(statuses != null && statuses.length == 1);
210 return statuses[0].getModificationTime();
213 @Test
214 public void testCreateHRegionInfoName() throws Exception {
215 final String tableName = name.getMethodName();
216 final TableName tn = TableName.valueOf(tableName);
217 String startKey = "startkey";
218 final byte[] sk = Bytes.toBytes(startKey);
219 String id = "id";
221 // old format region name
222 byte [] name = RegionInfo.createRegionName(tn, sk, id, false);
223 String nameStr = Bytes.toString(name);
224 assertEquals(tableName + "," + startKey + "," + id, nameStr);
227 // new format region name.
228 String md5HashInHex = MD5Hash.getMD5AsHex(name);
229 assertEquals(RegionInfo.MD5_HEX_LENGTH, md5HashInHex.length());
230 name = RegionInfo.createRegionName(tn, sk, id, true);
231 nameStr = Bytes.toString(name);
232 assertEquals(tableName + "," + startKey + ","
233 + id + "." + md5HashInHex + ".",
234 nameStr);
237 @Test
238 public void testContainsRange() {
239 TableDescriptor tableDesc =
240 TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
241 RegionInfo hri = RegionInfoBuilder.newBuilder(tableDesc.getTableName())
242 .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("g")).build();
243 // Single row range at start of region
244 assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("a")));
245 // Fully contained range
246 assertTrue(hri.containsRange(Bytes.toBytes("b"), Bytes.toBytes("c")));
247 // Range overlapping start of region
248 assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("c")));
249 // Fully contained single-row range
250 assertTrue(hri.containsRange(Bytes.toBytes("c"), Bytes.toBytes("c")));
251 // Range that overlaps end key and hence doesn't fit
252 assertFalse(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("g")));
253 // Single row range on end key
254 assertFalse(hri.containsRange(Bytes.toBytes("g"), Bytes.toBytes("g")));
255 // Single row range entirely outside
256 assertFalse(hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("z")));
258 // Degenerate range
259 try {
260 hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("a"));
261 fail("Invalid range did not throw IAE");
262 } catch (IllegalArgumentException iae) {
266 @Test
267 public void testContainsRangeForMetaTable() {
268 TableDescriptor tableDesc =
269 TableDescriptorBuilder.newBuilder(TableName.META_TABLE_NAME).build();
270 RegionInfo hri = RegionInfoBuilder.newBuilder(tableDesc.getTableName()).build();
271 byte[] startRow = HConstants.EMPTY_START_ROW;
272 byte[] row1 = Bytes.toBytes("a,a,0");
273 byte[] row2 = Bytes.toBytes("aaaaa,,1");
274 byte[] row3 = Bytes.toBytes("aaaaa,\u0000\u0000,2");
275 byte[] row4 = Bytes.toBytes("aaaaa,\u0001,3");
276 byte[] row5 = Bytes.toBytes("aaaaa,a,4");
277 byte[] row6 = Bytes.toBytes("aaaaa,\u1000,5");
279 // Single row range at start of region
280 assertTrue(hri.containsRange(startRow, startRow));
281 // Fully contained range
282 assertTrue(hri.containsRange(row1, row2));
283 assertTrue(hri.containsRange(row2, row3));
284 assertTrue(hri.containsRange(row3, row4));
285 assertTrue(hri.containsRange(row4, row5));
286 assertTrue(hri.containsRange(row5, row6));
287 // Range overlapping start of region
288 assertTrue(hri.containsRange(startRow, row2));
289 // Fully contained single-row range
290 assertTrue(hri.containsRange(row1, row1));
291 // Degenerate range
292 try {
293 hri.containsRange(row3, row2);
294 fail("Invalid range did not throw IAE");
295 } catch (IllegalArgumentException iae) {
299 @Test
300 public void testLastRegionCompare() {
301 TableDescriptor tableDesc =
302 TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
303 RegionInfo hrip = RegionInfoBuilder.newBuilder(tableDesc.getTableName())
304 .setStartKey(Bytes.toBytes("a")).build();
305 RegionInfo hric = RegionInfoBuilder.newBuilder(tableDesc.getTableName())
306 .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("b")).build();
307 assertTrue(hrip.compareTo(hric) > 0);
310 @Test
311 public void testMetaTables() {
312 assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isMetaRegion());
315 @SuppressWarnings("SelfComparison")
316 @Test
317 public void testComparator() {
318 final TableName tableName = TableName.valueOf(name.getMethodName());
319 RegionInfo older = RegionInfoBuilder.newBuilder(tableName).setRegionId(0).build();
320 RegionInfo newer = RegionInfoBuilder.newBuilder(tableName).setRegionId(1).build();
321 assertTrue(older.compareTo(newer) < 0);
322 assertTrue(newer.compareTo(older) > 0);
323 assertEquals(0, older.compareTo(older));
324 assertEquals(0, newer.compareTo(newer));
326 RegionInfo a = RegionInfoBuilder.newBuilder(TableName.valueOf("a")).build();
327 RegionInfo b = RegionInfoBuilder.newBuilder(TableName.valueOf("b")).build();
328 assertNotEquals(0, a.compareTo(b));
329 TableName t = TableName.valueOf("t");
330 byte [] midway = Bytes.toBytes("midway");
331 a = RegionInfoBuilder.newBuilder(t).setEndKey(midway).build();
332 b = RegionInfoBuilder.newBuilder(t).setStartKey(midway).build();
333 assertTrue(a.compareTo(b) < 0);
334 assertTrue(b.compareTo(a) > 0);
335 assertEquals(a, a);
336 assertEquals(0, a.compareTo(a));
337 a = RegionInfoBuilder.newBuilder(t).setStartKey(Bytes.toBytes("a"))
338 .setEndKey(Bytes.toBytes("d")).build();
339 b = RegionInfoBuilder.newBuilder(t).setStartKey(Bytes.toBytes("e"))
340 .setEndKey(Bytes.toBytes("g")).build();
341 assertTrue(a.compareTo(b) < 0);
342 a = RegionInfoBuilder.newBuilder(t).setStartKey(Bytes.toBytes("aaaa"))
343 .setEndKey(Bytes.toBytes("dddd")).build();
344 b = RegionInfoBuilder.newBuilder(t).setStartKey(Bytes.toBytes("e"))
345 .setEndKey(Bytes.toBytes("g")).build();
346 assertTrue(a.compareTo(b) < 0);
347 a = RegionInfoBuilder.newBuilder(t).setStartKey(Bytes.toBytes("aaaa"))
348 .setEndKey(Bytes.toBytes("dddd")).build();
349 b = RegionInfoBuilder.newBuilder(t).setStartKey(Bytes.toBytes("aaaa"))
350 .setEndKey(Bytes.toBytes("eeee")).build();
351 assertTrue(a.compareTo(b) < 0);
355 @Test
356 public void testRegionNameForRegionReplicas() throws Exception {
357 String tableName = name.getMethodName();
358 final TableName tn = TableName.valueOf(tableName);
359 String startKey = "startkey";
360 final byte[] sk = Bytes.toBytes(startKey);
361 String id = "id";
363 // assert with only the region name without encoding
365 // primary, replicaId = 0
366 byte [] name = RegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0, false);
367 String nameStr = Bytes.toString(name);
368 assertEquals(tableName + "," + startKey + "," + id, nameStr);
370 // replicaId = 1
371 name = RegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 1, false);
372 nameStr = Bytes.toString(name);
373 assertEquals(tableName + "," + startKey + "," + id + "_" +
374 String.format(RegionInfo.REPLICA_ID_FORMAT, 1), nameStr);
376 // replicaId = max
377 name = RegionInfo.createRegionName(tn, sk, Bytes.toBytes(id), 0xFFFF, false);
378 nameStr = Bytes.toString(name);
379 assertEquals(tableName + "," + startKey + "," + id + "_" +
380 String.format(RegionInfo.REPLICA_ID_FORMAT, 0xFFFF), nameStr);
383 @Test
384 public void testParseName() throws IOException {
385 final TableName tableName = TableName.valueOf(name.getMethodName());
386 byte[] startKey = Bytes.toBytes("startKey");
387 long regionId = EnvironmentEdgeManager.currentTime();
388 int replicaId = 42;
390 // test without replicaId
391 byte[] regionName = RegionInfo.createRegionName(tableName, startKey, regionId, false);
393 byte[][] fields = RegionInfo.parseRegionName(regionName);
394 assertArrayEquals(Bytes.toString(fields[0]),tableName.getName(), fields[0]);
395 assertArrayEquals(Bytes.toString(fields[1]),startKey, fields[1]);
396 assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)),fields[2]);
397 assertEquals(3, fields.length);
399 // test with replicaId
400 regionName = RegionInfo.createRegionName(tableName, startKey, regionId,
401 replicaId, false);
403 fields = RegionInfo.parseRegionName(regionName);
404 assertArrayEquals(Bytes.toString(fields[0]),tableName.getName(), fields[0]);
405 assertArrayEquals(Bytes.toString(fields[1]),startKey, fields[1]);
406 assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)),fields[2]);
407 assertArrayEquals(Bytes.toString(fields[3]), Bytes.toBytes(
408 String.format(RegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]);
411 @Test
412 public void testConvert() {
413 final TableName tableName = TableName.valueOf("ns1:" + name.getMethodName());
414 byte[] startKey = Bytes.toBytes("startKey");
415 byte[] endKey = Bytes.toBytes("endKey");
416 boolean split = false;
417 long regionId = EnvironmentEdgeManager.currentTime();
418 int replicaId = 42;
420 RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).setEndKey(endKey)
421 .setSplit(split).setRegionId(regionId).setReplicaId(replicaId).build();
423 // convert two times, compare
424 RegionInfo convertedHri = ProtobufUtil.toRegionInfo(ProtobufUtil.toRegionInfo(hri));
426 assertEquals(hri, convertedHri);
428 // test convert RegionInfo without replicaId
429 HBaseProtos.RegionInfo info = HBaseProtos.RegionInfo.newBuilder()
430 .setTableName(HBaseProtos.TableName.newBuilder()
431 .setQualifier(UnsafeByteOperations.unsafeWrap(tableName.getQualifier()))
432 .setNamespace(UnsafeByteOperations.unsafeWrap(tableName.getNamespace())).build())
433 .setStartKey(UnsafeByteOperations.unsafeWrap(startKey))
434 .setEndKey(UnsafeByteOperations.unsafeWrap(endKey)).setSplit(split).setRegionId(regionId)
435 .build();
437 convertedHri = ProtobufUtil.toRegionInfo(info);
438 // expecting default replicaId
439 RegionInfo expectedHri = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey)
440 .setEndKey(endKey).setSplit(split).setRegionId(regionId).setReplicaId(0).build();
442 assertEquals(expectedHri, convertedHri);
444 @Test
445 public void testRegionDetailsForDisplay() throws IOException {
446 byte[] startKey = new byte[] {0x01, 0x01, 0x02, 0x03};
447 byte[] endKey = new byte[] {0x01, 0x01, 0x02, 0x04};
448 Configuration conf = new Configuration();
449 conf.setBoolean("hbase.display.keys", false);
450 RegionInfo h = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
451 .setStartKey(startKey).setEndKey(endKey).build();
452 checkEquality(h, conf);
453 // check HRIs with non-default replicaId
454 h = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setStartKey(startKey)
455 .setEndKey(endKey).setRegionId(EnvironmentEdgeManager.currentTime()).setReplicaId(1).build();
456 checkEquality(h, conf);
457 assertArrayEquals(RegionInfoDisplay.HIDDEN_END_KEY,
458 RegionInfoDisplay.getEndKeyForDisplay(h, conf));
459 assertArrayEquals(RegionInfoDisplay.HIDDEN_START_KEY,
460 RegionInfoDisplay.getStartKeyForDisplay(h, conf));
462 RegionState state = RegionState.createForTesting(h, RegionState.State.OPEN);
463 String descriptiveNameForDisplay =
464 RegionInfoDisplay.getDescriptiveNameFromRegionStateForDisplay(state, conf);
465 checkDescriptiveNameEquality(descriptiveNameForDisplay, state.toDescriptiveString(), startKey);
467 conf.setBoolean("hbase.display.keys", true);
468 assertArrayEquals(endKey, RegionInfoDisplay.getEndKeyForDisplay(h, conf));
469 assertArrayEquals(startKey, RegionInfoDisplay.getStartKeyForDisplay(h, conf));
470 assertEquals(state.toDescriptiveString(),
471 RegionInfoDisplay.getDescriptiveNameFromRegionStateForDisplay(state, conf));
474 private void checkDescriptiveNameEquality(String descriptiveNameForDisplay, String origDesc,
475 byte[] startKey) {
476 // except for the "hidden-start-key" substring everything else should exactly match
477 String firstPart = descriptiveNameForDisplay.substring(0,
478 descriptiveNameForDisplay.indexOf(new String(RegionInfoDisplay.HIDDEN_START_KEY)));
479 String secondPart = descriptiveNameForDisplay
480 .substring(descriptiveNameForDisplay.indexOf(new String(RegionInfoDisplay.HIDDEN_START_KEY)) +
481 RegionInfoDisplay.HIDDEN_START_KEY.length);
482 String firstPartOrig = origDesc.substring(0, origDesc.indexOf(Bytes.toStringBinary(startKey)));
483 String secondPartOrig = origDesc.substring(
484 origDesc.indexOf(Bytes.toStringBinary(startKey)) + Bytes.toStringBinary(startKey).length());
485 assert (firstPart.equals(firstPartOrig));
486 assert (secondPart.equals(secondPartOrig));
489 private void checkEquality(RegionInfo h, Configuration conf) throws IOException {
490 byte[] modifiedRegionName = RegionInfoDisplay.getRegionNameForDisplay(h, conf);
491 byte[][] modifiedRegionNameParts = RegionInfo.parseRegionName(modifiedRegionName);
492 byte[][] regionNameParts = RegionInfo.parseRegionName(h.getRegionName());
494 // same number of parts
495 assert (modifiedRegionNameParts.length == regionNameParts.length);
497 for (int i = 0; i < regionNameParts.length; i++) {
498 // all parts should match except for [1] where in the modified one,
499 // we should have "hidden_start_key"
500 if (i != 1) {
501 Assert.assertArrayEquals(regionNameParts[i], modifiedRegionNameParts[i]);
502 } else {
503 assertNotEquals(regionNameParts[i][0], modifiedRegionNameParts[i][0]);
504 Assert.assertArrayEquals(modifiedRegionNameParts[1],
505 RegionInfoDisplay.getStartKeyForDisplay(h, conf));