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