1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.mapred;
20
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.testclassification.SmallTests;
26 import org.apache.hadoop.hbase.util.Bytes;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 @Category(SmallTests.class)
32 public class TestSplitTable {
33
34 @Test
35 @SuppressWarnings("deprecation")
36 public void testSplitTableCompareTo() {
37 TableSplit aTableSplit = new TableSplit(Bytes.toBytes("tableA"),
38 Bytes.toBytes("aaa"), Bytes.toBytes("ddd"), "locationA");
39
40 TableSplit bTableSplit = new TableSplit(Bytes.toBytes("tableA"),
41 Bytes.toBytes("iii"), Bytes.toBytes("kkk"), "locationA");
42
43 TableSplit cTableSplit = new TableSplit(Bytes.toBytes("tableA"),
44 Bytes.toBytes("lll"), Bytes.toBytes("zzz"), "locationA");
45
46 assertTrue(aTableSplit.compareTo(aTableSplit) == 0);
47 assertTrue(bTableSplit.compareTo(bTableSplit) == 0);
48 assertTrue(cTableSplit.compareTo(cTableSplit) == 0);
49
50 assertTrue(aTableSplit.compareTo(bTableSplit) < 0);
51 assertTrue(bTableSplit.compareTo(aTableSplit) > 0);
52
53 assertTrue(aTableSplit.compareTo(cTableSplit) < 0);
54 assertTrue(cTableSplit.compareTo(aTableSplit) > 0);
55
56 assertTrue(bTableSplit.compareTo(cTableSplit) < 0);
57 assertTrue(cTableSplit.compareTo(bTableSplit) > 0);
58
59 assertTrue(cTableSplit.compareTo(aTableSplit) > 0);
60 }
61
62 @Test
63 @SuppressWarnings("deprecation")
64 public void testSplitTableEquals() {
65 assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
66 Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
67 .toBytes("tableB"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"),
68 "locationA")));
69
70 assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
71 Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
72 .toBytes("tableA"), Bytes.toBytes("bbb"), Bytes.toBytes("ddd"),
73 "locationA")));
74
75 assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
76 Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
77 .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("eee"),
78 "locationA")));
79
80 assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
81 Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
82 .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"),
83 "locationB")));
84
85 assertTrue(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
86 Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
87 .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"),
88 "locationA")));
89 }
90
91 @Test
92 @SuppressWarnings("deprecation")
93 public void testToString() {
94 TableSplit split =
95 new TableSplit(TableName.valueOf("table"), "row-start".getBytes(), "row-end".getBytes(),
96 "location");
97 String str =
98 "HBase table split(table name: table, start row: row-start, "
99 + "end row: row-end, region location: location)";
100 Assert.assertEquals(str, split.toString());
101
102 split = new TableSplit((TableName) null, null, null, null);
103 str =
104 "HBase table split(table name: null, start row: null, "
105 + "end row: null, region location: null)";
106 Assert.assertEquals(str, split.toString());
107 }
108 }