1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertNotSame;
24 import static org.junit.Assert.assertTrue;
25
26 import org.apache.hadoop.hbase.testclassification.SmallTests;
27 import org.junit.Test;
28 import org.junit.experimental.categories.Category;
29
30 @Category(SmallTests.class)
31 public class TestHRegionLocation {
32
33
34
35
36
37 @Test
38 public void testHashAndEqualsCode() {
39 ServerName hsa1 = ServerName.valueOf("localhost", 1234, -1L);
40 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
41 HRegionLocation hrl2 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
42 assertEquals(hrl1.hashCode(), hrl2.hashCode());
43 assertTrue(hrl1.equals(hrl2));
44 HRegionLocation hrl3 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
45 assertNotSame(hrl1, hrl3);
46
47
48 assertTrue(hrl1.equals(hrl3));
49 ServerName hsa2 = ServerName.valueOf("localhost", 12345, -1L);
50 HRegionLocation hrl4 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa2);
51
52 assertFalse(hrl3.equals(hrl4));
53 HRegionLocation hrl5 = new HRegionLocation(hrl4.getRegionInfo(),
54 hrl4.getServerName(), hrl4.getSeqNum() + 1);
55 assertTrue(hrl4.equals(hrl5));
56 }
57
58 @Test
59 public void testToString() {
60 ServerName hsa1 = ServerName.valueOf("localhost", 1234, -1L);
61 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
62 System.out.println(hrl1.toString());
63 }
64
65 @Test
66 public void testCompareTo() {
67 ServerName hsa1 = ServerName.valueOf("localhost", 1234, -1L);
68 HRegionLocation hsl1 =
69 new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
70 ServerName hsa2 = ServerName.valueOf("localhost", 1235, -1L);
71 HRegionLocation hsl2 =
72 new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa2);
73 assertTrue(hsl1.compareTo(hsl1) == 0);
74 assertTrue(hsl2.compareTo(hsl2) == 0);
75 int compare1 = hsl1.compareTo(hsl2);
76 int compare2 = hsl2.compareTo(hsl1);
77 assertTrue((compare1 > 0)? compare2 < 0: compare2 > 0);
78 }
79
80 }
81