1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.replication;
20
21 import java.io.IOException;
22 import java.util.concurrent.atomic.AtomicBoolean;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseTestingUtility;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.MediumTests;
28 import org.apache.hadoop.hbase.Server;
29 import org.apache.hadoop.hbase.ServerName;
30 import org.apache.hadoop.hbase.catalog.CatalogTracker;
31 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
32 import org.apache.zookeeper.KeeperException;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37
38 import static org.junit.Assert.assertEquals;
39
40 @Category(MediumTests.class)
41 public class TestReplicationZookeeper {
42
43 private static Configuration conf;
44
45 private static HBaseTestingUtility utility;
46
47 private static ZooKeeperWatcher zkw;
48
49 private static ReplicationZookeeper repZk;
50
51 private static String slaveClusterKey;
52
53 @BeforeClass
54 public static void setUpBeforeClass() throws Exception {
55 utility = new HBaseTestingUtility();
56 utility.startMiniZKCluster();
57 conf = utility.getConfiguration();
58 zkw = HBaseTestingUtility.getZooKeeperWatcher(utility);
59 DummyServer server = new DummyServer();
60 repZk = new ReplicationZookeeper(server, new AtomicBoolean());
61 slaveClusterKey = conf.get(HConstants.ZOOKEEPER_QUORUM) + ":" +
62 conf.get("hbase.zookeeper.property.clientPort") + ":/1";
63 }
64
65 @AfterClass
66 public static void tearDownAfterClass() throws Exception {
67 utility.shutdownMiniZKCluster();
68 }
69
70 @Test
71 public void testGetAddressesMissingSlave()
72 throws IOException, KeeperException {
73 repZk.addPeer("1", slaveClusterKey);
74
75 assertEquals(0, repZk.getSlavesAddresses("1").size());
76 }
77
78 static class DummyServer implements Server {
79
80 @Override
81 public Configuration getConfiguration() {
82 return conf;
83 }
84
85 @Override
86 public ZooKeeperWatcher getZooKeeper() {
87 return zkw;
88 }
89
90 @Override
91 public CatalogTracker getCatalogTracker() {
92 return null;
93 }
94
95 @Override
96 public ServerName getServerName() {
97 return new ServerName("hostname.example.org", 1234, -1L);
98 }
99
100 @Override
101 public void abort(String why, Throwable e) {
102 }
103
104 @Override
105 public boolean isAborted() {
106 return false;
107 }
108
109 @Override
110 public void stop(String why) {
111 }
112
113 @Override
114 public boolean isStopped() {
115 return false;
116 }
117 }
118 }