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 org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.testclassification.LargeTests;
24 import org.apache.hadoop.hbase.client.Get;
25 import org.apache.hadoop.hbase.client.Put;
26 import org.apache.hadoop.hbase.client.Result;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31 import static org.junit.Assert.assertArrayEquals;
32 import static org.junit.Assert.fail;
33
34 @Category(LargeTests.class)
35 public class TestReplicationDisableInactivePeer extends TestReplicationBase {
36
37 private static final Log LOG = LogFactory.getLog(TestReplicationDisableInactivePeer.class);
38
39
40
41
42
43
44
45
46
47 @Test(timeout = 600000)
48 public void testDisableInactivePeer() throws Exception {
49
50
51 admin.enablePeer("2");
52 utility2.shutdownMiniHBaseCluster();
53
54 byte[] rowkey = Bytes.toBytes("disable inactive peer");
55 Put put = new Put(rowkey);
56 put.add(famName, row, row);
57 htable1.put(put);
58
59
60 Thread.sleep(SLEEP_TIME * NB_RETRIES);
61
62
63 admin.disablePeer("2");
64 utility2.startMiniHBaseCluster(1, 2);
65 htable2 = utility2.getConnection().getTable(tableName);
66 Get get = new Get(rowkey);
67 for (int i = 0; i < NB_RETRIES; i++) {
68 Result res = htable2.get(get);
69 if (res.size() >= 1) {
70 fail("Replication wasn't disabled");
71 } else {
72 LOG.info("Row not replicated, let's wait a bit more...");
73 Thread.sleep(SLEEP_TIME);
74 }
75 }
76
77
78 admin.enablePeer("2");
79
80 Thread.sleep(SLEEP_TIME * NB_RETRIES);
81 for (int i = 0; i < NB_RETRIES; i++) {
82 Result res = htable2.get(get);
83 if (res.size() == 0) {
84 LOG.info("Row not available");
85 Thread.sleep(SLEEP_TIME * NB_RETRIES);
86 } else {
87 assertArrayEquals(res.value(), row);
88 return;
89 }
90 }
91 fail("Waited too much time for put replication");
92 }
93 }