1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import static org.junit.Assert.*;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.hbase.util.Writables;
25 import org.junit.Test;
26 import org.junit.experimental.categories.Category;
27
28 @Category(SmallTests.class)
29 public class TestHServerInfo {
30
31 @Test
32 public void testHashCodeAndEquals() {
33 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
34 HServerInfo hsi1 = new HServerInfo(hsa1, 1L, 5678);
35 HServerInfo hsi2 = new HServerInfo(hsa1, 1L, 5678);
36 HServerInfo hsi3 = new HServerInfo(hsa1, 2L, 5678);
37 HServerInfo hsi4 = new HServerInfo(hsa1, 1L, 5677);
38 HServerAddress hsa2 = new HServerAddress("localhost", 1235);
39 HServerInfo hsi5 = new HServerInfo(hsa2, 1L, 5678);
40 assertEquals(hsi1.hashCode(), hsi2.hashCode());
41 assertTrue(hsi1.equals(hsi2));
42 assertNotSame(hsi1.hashCode(), hsi3.hashCode());
43 assertFalse(hsi1.equals(hsi3));
44 assertNotSame(hsi1.hashCode(), hsi4.hashCode());
45 assertFalse(hsi1.equals(hsi4));
46 assertNotSame(hsi1.hashCode(), hsi5.hashCode());
47 assertFalse(hsi1.equals(hsi5));
48 }
49
50 @Test
51 public void testHServerInfoHServerInfo() {
52 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
53 HServerInfo hsi1 = new HServerInfo(hsa1, 1L, 5678);
54 HServerInfo hsi2 = new HServerInfo(hsi1);
55 assertEquals(hsi1, hsi2);
56 }
57
58 @Test
59 public void testGetServerAddress() {
60 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
61 HServerInfo hsi1 = new HServerInfo(hsa1, 1L, 5678);
62 assertEquals(hsi1.getServerAddress(), hsa1);
63 }
64
65 @Test
66 public void testToString() {
67 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
68 HServerInfo hsi1 = new HServerInfo(hsa1, 1L, 5678);
69 System.out.println(hsi1.toString());
70 }
71
72 @Test
73 public void testReadFields() throws IOException {
74 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
75 HServerInfo hsi1 = new HServerInfo(hsa1, 1L, 5678);
76 HServerAddress hsa2 = new HServerAddress("localhost", 1235);
77 HServerInfo hsi2 = new HServerInfo(hsa2, 1L, 5678);
78 byte [] bytes = Writables.getBytes(hsi1);
79 HServerInfo deserialized =
80 (HServerInfo)Writables.getWritable(bytes, new HServerInfo());
81 assertEquals(hsi1, deserialized);
82 bytes = Writables.getBytes(hsi2);
83 deserialized = (HServerInfo)Writables.getWritable(bytes, new HServerInfo());
84 assertNotSame(hsa1, deserialized);
85 }
86
87 @Test
88 public void testCompareTo() {
89 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
90 HServerInfo hsi1 = new HServerInfo(hsa1, 1L, 5678);
91 HServerAddress hsa2 = new HServerAddress("localhost", 1235);
92 HServerInfo hsi2 = new HServerInfo(hsa2, 1L, 5678);
93 assertTrue(hsi1.compareTo(hsi1) == 0);
94 assertTrue(hsi2.compareTo(hsi2) == 0);
95 int compare1 = hsi1.compareTo(hsi2);
96 int compare2 = hsi2.compareTo(hsi1);
97 assertTrue((compare1 > 0)? compare2 < 0: compare2 > 0);
98 }
99
100 @org.junit.Rule
101 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
102 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
103 }
104