1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client.replication;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.*;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.junit.experimental.categories.Category;
27
28 import static org.junit.Assert.fail;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertTrue;
31 import static org.junit.Assert.assertFalse;
32
33
34
35
36 @Category(MediumTests.class)
37 public class TestReplicationAdmin {
38
39 private static final Log LOG =
40 LogFactory.getLog(TestReplicationAdmin.class);
41 private final static HBaseTestingUtility TEST_UTIL =
42 new HBaseTestingUtility();
43
44 private final String ID_ONE = "1";
45 private final String KEY_ONE = "127.0.0.1:2181:/hbase";
46 private final String ID_SECOND = "2";
47 private final String KEY_SECOND = "127.0.0.1:2181:/hbase2";
48
49 private static ReplicationAdmin admin;
50
51
52
53
54 @BeforeClass
55 public static void setUpBeforeClass() throws Exception {
56 TEST_UTIL.startMiniZKCluster();
57 Configuration conf = TEST_UTIL.getConfiguration();
58 conf.setBoolean(HConstants.REPLICATION_ENABLE_KEY, HConstants.REPLICATION_ENABLE_DEFAULT);
59 admin = new ReplicationAdmin(conf);
60 }
61
62
63
64
65
66
67 @Test
68 public void testAddRemovePeer() throws Exception {
69
70 admin.addPeer(ID_ONE, KEY_ONE);
71
72 try {
73 admin.addPeer(ID_ONE, KEY_ONE);
74 } catch (IllegalArgumentException iae) {
75
76 }
77 assertEquals(1, admin.getPeersCount());
78
79 try {
80 admin.removePeer(ID_SECOND);
81 fail();
82 } catch (IllegalArgumentException iae) {
83
84 }
85 assertEquals(1, admin.getPeersCount());
86
87 try {
88 admin.addPeer(ID_SECOND, KEY_SECOND);
89 } catch (IllegalStateException iae) {
90 fail();
91 }
92 assertEquals(2, admin.getPeersCount());
93
94 admin.removePeer(ID_ONE);
95 assertEquals(1, admin.getPeersCount());
96 admin.removePeer(ID_SECOND);
97 assertEquals(0, admin.getPeersCount());
98 }
99
100
101
102
103
104 @Test
105 public void testEnableDisable() throws Exception {
106 admin.addPeer(ID_ONE, KEY_ONE);
107 assertEquals(1, admin.getPeersCount());
108 assertTrue(admin.getPeerState(ID_ONE));
109 admin.disablePeer(ID_ONE);
110
111 assertFalse(admin.getPeerState(ID_ONE));
112 try {
113 admin.getPeerState(ID_SECOND);
114 } catch (IllegalArgumentException iae) {
115
116 }
117 admin.removePeer(ID_ONE);
118 }
119
120 }
121