1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotSame;
25 import static org.junit.Assert.assertTrue;
26
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 = new ServerName("localhost", 1234, -1L);
40 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
41 hsa1.getHostname(), hsa1.getPort());
42 HRegionLocation hrl2 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
43 hsa1.getHostname(), hsa1.getPort());
44 assertEquals(hrl1.hashCode(), hrl2.hashCode());
45 assertTrue(hrl1.equals(hrl2));
46 HRegionLocation hrl3 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
47 hsa1.getHostname(), hsa1.getPort());
48 assertNotSame(hrl1, hrl3);
49
50
51 assertTrue(hrl1.equals(hrl3));
52 ServerName hsa2 = new ServerName("localhost", 12345, -1L);
53 HRegionLocation hrl4 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
54 hsa2.getHostname(), hsa2.getPort());
55
56 assertFalse(hrl3.equals(hrl4));
57 }
58
59 @Test
60 public void testToString() {
61 ServerName hsa1 = new ServerName("localhost", 1234, -1L);
62 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
63 hsa1.getHostname(), hsa1.getPort());
64 System.out.println(hrl1.toString());
65 }
66
67 @Test
68 public void testCompareTo() {
69 ServerName hsa1 = new ServerName("localhost", 1234, -1L);
70 HRegionLocation hsl1 =
71 new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa1.getHostname(), hsa1.getPort());
72 ServerName hsa2 = new ServerName("localhost", 1235, -1L);
73 HRegionLocation hsl2 =
74 new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa2.getHostname(), hsa2.getPort());
75 assertTrue(hsl1.compareTo(hsl1) == 0);
76 assertTrue(hsl2.compareTo(hsl2) == 0);
77 int compare1 = hsl1.compareTo(hsl2);
78 int compare2 = hsl2.compareTo(hsl1);
79 assertTrue((compare1 > 0)? compare2 < 0: compare2 > 0);
80 }
81
82 @org.junit.Rule
83 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
84 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
85 }
86