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.junit.Test;
27 import org.junit.experimental.categories.Category;
28
29 @Category(SmallTests.class)
30 public class TestHRegionLocation {
31
32
33
34
35
36 @Test
37 public void testHashAndEqualsCode() {
38 ServerName hsa1 = ServerName.valueOf("localhost", 1234, -1L);
39 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
40 HRegionLocation hrl2 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
41 assertEquals(hrl1.hashCode(), hrl2.hashCode());
42 assertTrue(hrl1.equals(hrl2));
43 HRegionLocation hrl3 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
44 assertNotSame(hrl1, hrl3);
45
46
47 assertTrue(hrl1.equals(hrl3));
48 ServerName hsa2 = ServerName.valueOf("localhost", 12345, -1L);
49 HRegionLocation hrl4 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa2);
50
51 assertFalse(hrl3.equals(hrl4));
52 HRegionLocation hrl5 = new HRegionLocation(hrl4.getRegionInfo(),
53 hrl4.getServerName(), hrl4.getSeqNum() + 1);
54 assertTrue(hrl4.equals(hrl5));
55 }
56
57 @Test
58 public void testToString() {
59 ServerName hsa1 = ServerName.valueOf("localhost", 1234, -1L);
60 HRegionLocation hrl1 = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
61 System.out.println(hrl1.toString());
62 }
63
64 @Test
65 public void testCompareTo() {
66 ServerName hsa1 = ServerName.valueOf("localhost", 1234, -1L);
67 HRegionLocation hsl1 =
68 new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa1);
69 ServerName hsa2 = ServerName.valueOf("localhost", 1235, -1L);
70 HRegionLocation hsl2 =
71 new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, hsa2);
72 assertTrue(hsl1.compareTo(hsl1) == 0);
73 assertTrue(hsl2.compareTo(hsl2) == 0);
74 int compare1 = hsl1.compareTo(hsl2);
75 int compare2 = hsl2.compareTo(hsl1);
76 assertTrue((compare1 > 0)? compare2 < 0: compare2 > 0);
77 }
78
79 }
80