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.SmallTests;
23 import org.apache.hadoop.util.ReflectionUtils;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.junit.experimental.categories.Category;
27
28 import java.util.HashSet;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32
33 @Category(SmallTests.class)
34 public class TestTableSplit {
35 @Test
36 public void testHashCode() {
37 TableSplit split1 = new TableSplit(TableName.valueOf("table"),
38 "row-start".getBytes(),
39 "row-end".getBytes(), "location");
40 TableSplit split2 = new TableSplit(TableName.valueOf("table"),
41 "row-start".getBytes(),
42 "row-end".getBytes(), "location");
43 assertEquals (split1, split2);
44 assertTrue (split1.hashCode() == split2.hashCode());
45 HashSet<TableSplit> set = new HashSet<TableSplit>(2);
46 set.add(split1);
47 set.add(split2);
48 assertTrue(set.size() == 1);
49 }
50
51
52
53
54 @Test
55 public void testHashCode_length() {
56 TableSplit split1 = new TableSplit(TableName.valueOf("table"),
57 "row-start".getBytes(),
58 "row-end".getBytes(), "location", 1984);
59 TableSplit split2 = new TableSplit(TableName.valueOf("table"),
60 "row-start".getBytes(),
61 "row-end".getBytes(), "location", 1982);
62
63 assertEquals (split1, split2);
64 assertTrue (split1.hashCode() == split2.hashCode());
65 HashSet<TableSplit> set = new HashSet<TableSplit>(2);
66 set.add(split1);
67 set.add(split2);
68 assertTrue(set.size() == 1);
69 }
70
71
72
73
74 @Test
75 public void testLengthIsSerialized() throws Exception {
76 TableSplit split1 = new TableSplit(TableName.valueOf("table"),
77 "row-start".getBytes(),
78 "row-end".getBytes(), "location", 666);
79
80 TableSplit deserialized = new TableSplit(TableName.valueOf("table"),
81 "row-start2".getBytes(),
82 "row-end2".getBytes(), "location1");
83 ReflectionUtils.copy(new Configuration(), split1, deserialized);
84
85 Assert.assertEquals(666, deserialized.getLength());
86 }
87
88 }
89