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
29 public class TestHRegionLocation {
30
31
32
33
34
35 @Test
36 public void testHashAndEqualsCode() {
37 ServerName hsa1 = new ServerName("localhost", 1234, -1L);
38 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
39 hsa1.getHostname(), hsa1.getPort());
40 HRegionLocation hrl2 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
41 hsa1.getHostname(), hsa1.getPort());
42 assertEquals(hrl1.hashCode(), hrl2.hashCode());
43 assertTrue(hrl1.equals(hrl2));
44 HRegionLocation hrl3 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
45 hsa1.getHostname(), hsa1.getPort());
46 assertNotSame(hrl1, hrl3);
47
48
49 assertTrue(hrl1.equals(hrl3));
50 ServerName hsa2 = new ServerName("localhost", 12345, -1L);
51 HRegionLocation hrl4 = new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,
52 hsa2.getHostname(), hsa2.getPort());
53
54 assertFalse(hrl3.equals(hrl4));
55 }
56
57 @Test
58 public void testToString() {
59 ServerName hsa1 = new ServerName("localhost", 1234, -1L);
60 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
61 hsa1.getHostname(), hsa1.getPort());
62 System.out.println(hrl1.toString());
63 }
64
65 @Test
66 public void testCompareTo() {
67 ServerName hsa1 = new ServerName("localhost", 1234, -1L);
68 HRegionLocation hsl1 =
69 new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa1.getHostname(), hsa1.getPort());
70 ServerName hsa2 = new ServerName("localhost", 1235, -1L);
71 HRegionLocation hsl2 =
72 new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, hsa2.getHostname(), hsa2.getPort());
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 }