1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.mapreduce;
19
20 import org.apache.hadoop.conf.Configuration;
21 import org.apache.hadoop.hbase.TableName;
22 import org.apache.hadoop.hbase.testclassification.MapReduceTests;
23 import org.apache.hadoop.hbase.testclassification.SmallTests;
24 import org.apache.hadoop.util.ReflectionUtils;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.junit.experimental.categories.Category;
28
29 import java.util.HashSet;
30
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertTrue;
33
34 @Category({MapReduceTests.class, SmallTests.class})
35 public class TestTableSplit {
36 @Test
37 public void testHashCode() {
38 TableSplit split1 = new TableSplit(TableName.valueOf("table"),
39 "row-start".getBytes(),
40 "row-end".getBytes(), "location");
41 TableSplit split2 = new TableSplit(TableName.valueOf("table"),
42 "row-start".getBytes(),
43 "row-end".getBytes(), "location");
44 assertEquals (split1, split2);
45 assertTrue (split1.hashCode() == split2.hashCode());
46 HashSet<TableSplit> set = new HashSet<TableSplit>(2);
47 set.add(split1);
48 set.add(split2);
49 assertTrue(set.size() == 1);
50 }
51
52
53
54
55 @Test
56 public void testHashCode_length() {
57 TableSplit split1 = new TableSplit(TableName.valueOf("table"),
58 "row-start".getBytes(),
59 "row-end".getBytes(), "location", 1984);
60 TableSplit split2 = new TableSplit(TableName.valueOf("table"),
61 "row-start".getBytes(),
62 "row-end".getBytes(), "location", 1982);
63
64 assertEquals (split1, split2);
65 assertTrue (split1.hashCode() == split2.hashCode());
66 HashSet<TableSplit> set = new HashSet<TableSplit>(2);
67 set.add(split1);
68 set.add(split2);
69 assertTrue(set.size() == 1);
70 }
71
72
73
74
75 @Test
76 public void testLengthIsSerialized() throws Exception {
77 TableSplit split1 = new TableSplit(TableName.valueOf("table"),
78 "row-start".getBytes(),
79 "row-end".getBytes(), "location", 666);
80
81 TableSplit deserialized = new TableSplit(TableName.valueOf("table"),
82 "row-start2".getBytes(),
83 "row-end2".getBytes(), "location1");
84 ReflectionUtils.copy(new Configuration(), split1, deserialized);
85
86 Assert.assertEquals(666, deserialized.getLength());
87 }
88
89 @Test
90 public void testToString() {
91 TableSplit split =
92 new TableSplit(TableName.valueOf("table"), "row-start".getBytes(), "row-end".getBytes(),
93 "location");
94 String str =
95 "HBase table split(table name: table, scan: , start row: row-start, "
96 + "end row: row-end, region location: location)";
97 Assert.assertEquals(str, split.toString());
98
99 split = new TableSplit((TableName) null, null, null, null);
100 str =
101 "HBase table split(table name: null, scan: , start row: null, "
102 + "end row: null, region location: null)";
103 Assert.assertEquals(str, split.toString());
104 }
105 }
106