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.util;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.SmallTests;
27 import org.apache.hadoop.hbase.util.HBaseFsck.HbckInfo;
28 import org.apache.hadoop.hbase.util.HBaseFsck.MetaEntry;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32
33
34
35 @Category(SmallTests.class)
36 public class TestHBaseFsckComparator {
37
38 byte[] table = Bytes.toBytes("table1");
39 byte[] table2 = Bytes.toBytes("table2");
40 byte[] keyStart = Bytes.toBytes("");
41 byte[] keyA = Bytes.toBytes("A");
42 byte[] keyB = Bytes.toBytes("B");
43 byte[] keyC = Bytes.toBytes("C");
44 byte[] keyEnd = Bytes.toBytes("");
45
46 static HbckInfo genHbckInfo(byte[] table, byte[] start, byte[] end, int time) {
47 return new HbckInfo(new MetaEntry(new HRegionInfo(table, start, end), null,
48 time));
49 }
50
51 @Test
52 public void testEquals() {
53 HbckInfo hi1 = genHbckInfo(table, keyA, keyB, 0);
54 HbckInfo hi2 = genHbckInfo(table, keyA, keyB, 0);
55 assertEquals(0, HBaseFsck.cmp.compare(hi1, hi2));
56 assertEquals(0, HBaseFsck.cmp.compare(hi2, hi1));
57 }
58
59 @Test
60 public void testEqualsInstance() {
61 HbckInfo hi1 = genHbckInfo(table, keyA, keyB, 0);
62 HbckInfo hi2 = hi1;
63 assertEquals(0, HBaseFsck.cmp.compare(hi1, hi2));
64 assertEquals(0, HBaseFsck.cmp.compare(hi2, hi1));
65 }
66
67 @Test
68 public void testDiffTable() {
69 HbckInfo hi1 = genHbckInfo(table, keyA, keyC, 0);
70 HbckInfo hi2 = genHbckInfo(table2, keyA, keyC, 0);
71 assertTrue(HBaseFsck.cmp.compare(hi1, hi2) < 0);
72 assertTrue(HBaseFsck.cmp.compare(hi2, hi1) > 0);
73 }
74
75 @Test
76 public void testDiffStartKey() {
77 HbckInfo hi1 = genHbckInfo(table, keyStart, keyC, 0);
78 HbckInfo hi2 = genHbckInfo(table, keyA, keyC, 0);
79 assertTrue(HBaseFsck.cmp.compare(hi1, hi2) < 0);
80 assertTrue(HBaseFsck.cmp.compare(hi2, hi1) > 0);
81 }
82
83 @Test
84 public void testDiffEndKey() {
85 HbckInfo hi1 = genHbckInfo(table, keyA, keyB, 0);
86 HbckInfo hi2 = genHbckInfo(table, keyA, keyC, 0);
87 assertTrue(HBaseFsck.cmp.compare(hi1, hi2) < 0);
88 assertTrue(HBaseFsck.cmp.compare(hi2, hi1) > 0);
89 }
90
91 @Test
92 public void testAbsEndKey() {
93 HbckInfo hi1 = genHbckInfo(table, keyA, keyC, 0);
94 HbckInfo hi2 = genHbckInfo(table, keyA, keyEnd, 0);
95 assertTrue(HBaseFsck.cmp.compare(hi1, hi2) < 0);
96 assertTrue(HBaseFsck.cmp.compare(hi2, hi1) > 0);
97 }
98
99 @org.junit.Rule
100 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
101 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
102 }
103