1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master;
19
20 import static junit.framework.TestCase.assertFalse;
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.ServerName;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.HRegionInfo;
28 import org.apache.hadoop.hbase.testclassification.MasterTests;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.hadoop.hbase.TableName;
31 import org.junit.rules.TestName;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36 @Category(SmallTests.class)
37 public class TestRegionPlan {
38 private final ServerName SRC = ServerName.valueOf("source", 1234, 2345);
39 private final ServerName DEST = ServerName.valueOf("dest", 1234, 2345);
40 @Rule
41 public TestName name = new TestName();
42
43 @Test
44 public void testCompareTo() {
45 HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName()));
46 RegionPlan a = new RegionPlan(hri, null, null);
47 RegionPlan b = new RegionPlan(hri, null, null);
48 assertEquals(0, a.compareTo(b));
49 a = new RegionPlan(hri, SRC, null);
50 b = new RegionPlan(hri, null, null);
51 assertEquals(1, a.compareTo(b));
52 a = new RegionPlan(hri, null, null);
53 b = new RegionPlan(hri, SRC, null);
54 assertEquals(-1, a.compareTo(b));
55 a = new RegionPlan(hri, SRC, null);
56 b = new RegionPlan(hri, SRC, null);
57 assertEquals(0, a.compareTo(b));
58 a = new RegionPlan(hri, SRC, null);
59 b = new RegionPlan(hri, SRC, DEST);
60 assertEquals(-1, a.compareTo(b));
61 a = new RegionPlan(hri, SRC, DEST);
62 b = new RegionPlan(hri, SRC, DEST);
63 assertEquals(0, a.compareTo(b));
64 }
65
66 @Test
67 public void testEqualsWithNulls() {
68 HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName()));
69 RegionPlan a = new RegionPlan(hri, null, null);
70 RegionPlan b = new RegionPlan(hri, null, null);
71 assertTrue(a.equals(b));
72 a = new RegionPlan(hri, SRC, null);
73 b = new RegionPlan(hri, null, null);
74 assertFalse(a.equals(b));
75 a = new RegionPlan(hri, SRC, null);
76 b = new RegionPlan(hri, SRC, null);
77 assertTrue(a.equals(b));
78 a = new RegionPlan(hri, SRC, null);
79 b = new RegionPlan(hri, SRC, DEST);
80 assertFalse(a.equals(b));
81 }
82
83 @Test
84 public void testEquals() {
85 HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName()));
86
87
88 RegionPlan plan = new RegionPlan(hri, SRC, DEST);
89 assertEquals(plan.hashCode(), new RegionPlan(hri, SRC, DEST).hashCode());
90 assertEquals(plan, new RegionPlan(hri, SRC, DEST));
91
92
93 HRegionInfo other =
94 new HRegionInfo(TableName.valueOf(name.getMethodName() + "other"));
95 assertNotEquals(plan.hashCode(), new RegionPlan(other, SRC, DEST).hashCode());
96 assertNotEquals(plan, new RegionPlan(other, SRC, DEST));
97 }
98 }