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
30
31
32
33 public class TestHServerAddress {
34 @Test
35 public void testHashCode() {
36 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
37 HServerAddress hsa2 = new HServerAddress("localhost", 1234);
38 assertEquals(hsa1.hashCode(), hsa2.hashCode());
39 HServerAddress hsa3 = new HServerAddress("localhost", 1235);
40 assertNotSame(hsa1.hashCode(), hsa3.hashCode());
41 }
42
43 @Test
44 public void testHServerAddress() {
45 new HServerAddress();
46 }
47
48 @Test
49 public void testHServerAddressInetSocketAddress() {
50 HServerAddress hsa1 =
51 new HServerAddress(new InetSocketAddress("localhost", 1234));
52 System.out.println(hsa1.toString());
53 }
54
55 @Test
56 public void testHServerAddressString() {
57 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
58 HServerAddress hsa2 =
59 new HServerAddress(new InetSocketAddress("localhost", 1234));
60 assertTrue(hsa1.equals(hsa2));
61 }
62
63 @Test
64 public void testHServerAddressHServerAddress() {
65 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
66 HServerAddress hsa2 = new HServerAddress(hsa1);
67 assertEquals(hsa1, hsa2);
68 }
69
70 @Test
71 public void testReadFields() throws IOException {
72 HServerAddress hsa1 = new HServerAddress("localhost", 1234);
73 HServerAddress hsa2 = new HServerAddress("localhost", 1235);
74 byte [] bytes = Writables.getBytes(hsa1);
75 HServerAddress deserialized =
76 (HServerAddress)Writables.getWritable(bytes, new HServerAddress());
77 assertEquals(hsa1, deserialized);
78 bytes = Writables.getBytes(hsa2);
79 deserialized =
80 (HServerAddress)Writables.getWritable(bytes, new HServerAddress());
81 assertNotSame(hsa1, deserialized);
82 }
83 }