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.*;
23
24 import java.io.IOException;
25 import java.net.InetSocketAddress;
26
27 import org.apache.hadoop.hbase.util.Writables;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32
33
34 @Category(SmallTests.class)
35 public class TestHServerAddress {
36 @Test
37 public void testHashCode() {
38 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
39 HServerAddress hsa2 = new HServerAddress("localhost", 1234);
40 assertEquals(hsa1.hashCode(), hsa2.hashCode());
41 HServerAddress hsa3 = new HServerAddress("localhost", 1235);
42 assertNotSame(hsa1.hashCode(), hsa3.hashCode());
43 }
44
45 @Test
46 public void testHServerAddress() {
47 new HServerAddress();
48 }
49
50 @Test
51 public void testHServerAddressInetSocketAddress() {
52 HServerAddress hsa1 =
53 new HServerAddress(new InetSocketAddress("localhost", 1234));
54 System.out.println(hsa1.toString());
55 }
56
57 @Test
58 public void testHServerAddressString() {
59 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
60 HServerAddress hsa2 =
61 new HServerAddress(new InetSocketAddress("localhost", 1234));
62 assertTrue(hsa1.equals(hsa2));
63 }
64
65 @Test
66 public void testHServerAddressHServerAddress() {
67 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
68 HServerAddress hsa2 = new HServerAddress(hsa1);
69 assertEquals(hsa1, hsa2);
70 }
71
72 @Test
73 public void testReadFields() throws IOException {
74 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
75 HServerAddress hsa2 = new HServerAddress("localhost", 1235);
76 byte [] bytes = Writables.getBytes(hsa1);
77 HServerAddress deserialized =
78 (HServerAddress)Writables.getWritable(bytes, new HServerAddress());
79 assertEquals(hsa1, deserialized);
80 bytes = Writables.getBytes(hsa2);
81 deserialized =
82 (HServerAddress)Writables.getWritable(bytes, new HServerAddress());
83 assertNotSame(hsa1, deserialized);
84 }
85
86 @org.junit.Rule
87 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
88 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
89 }
90