1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.rest.model;
21
22 import org.apache.hadoop.hbase.*;
23 import org.apache.hadoop.hbase.testclassification.SmallTests;
24 import org.apache.hadoop.hbase.util.Bytes;
25
26 import org.junit.experimental.categories.Category;
27
28 @Category(SmallTests.class)
29 public class TestTableRegionModel extends TestModelBase<TableRegionModel> {
30 private static final String TABLE = "testtable";
31 private static final byte[] START_KEY = Bytes.toBytes("abracadbra");
32 private static final byte[] END_KEY = Bytes.toBytes("zzyzx");
33 private static final long ID = 8731042424L;
34 private static final String LOCATION = "testhost:9876";
35
36 public TestTableRegionModel() throws Exception {
37 super(TableRegionModel.class);
38
39 AS_XML =
40 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Region endKey=\"enp5eng=\" " +
41 "id=\"8731042424\" location=\"testhost:9876\" " +
42 "name=\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\" " +
43 "startKey=\"YWJyYWNhZGJyYQ==\"/>";
44
45 AS_JSON =
46 "{\"endKey\":\"enp5eng=\",\"id\":8731042424,\"location\":\"testhost:9876\"," +
47 "\"name\":\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\",\"" +
48 "startKey\":\"YWJyYWNhZGJyYQ==\"}";
49 }
50
51 protected TableRegionModel buildTestModel() {
52 TableRegionModel model =
53 new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION);
54 return model;
55 }
56
57 protected void checkModel(TableRegionModel model) {
58 assertTrue(Bytes.equals(model.getStartKey(), START_KEY));
59 assertTrue(Bytes.equals(model.getEndKey(), END_KEY));
60 assertEquals(model.getId(), ID);
61 assertEquals(model.getLocation(), LOCATION);
62 assertEquals(model.getName(),
63 TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) +
64 ".ad9860f031282c46ed431d7af8f94aca.");
65 }
66
67 public void testGetName() {
68 TableRegionModel model = buildTestModel();
69 String modelName = model.getName();
70 HRegionInfo hri = new HRegionInfo(TableName.valueOf(TABLE),
71 START_KEY, END_KEY, false, ID);
72 assertEquals(modelName, hri.getRegionNameAsString());
73 }
74
75 public void testSetName() {
76 TableRegionModel model = buildTestModel();
77 String name = model.getName();
78 model.setName(name);
79 assertEquals(name, model.getName());
80 }
81
82 @Override
83 public void testFromPB() throws Exception {
84
85 }
86 }
87