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 Get get = new Get(rowkey);
66 for (int i = 0; i < NB_RETRIES; i++) {
67 Result res = htable2.get(get);
68 if (res.size() >= 1) {
69 fail("Replication wasn't disabled");
70 } else {
71 LOG.info("Row not replicated, let's wait a bit more...");
72 Thread.sleep(SLEEP_TIME);
73 }
74 }
75
76
77 admin.enablePeer("2");
78
79 Thread.sleep(SLEEP_TIME * NB_RETRIES);
80 for (int i = 0; i < NB_RETRIES; i++) {
81 Result res = htable2.get(get);
82 if (res.size() == 0) {
83 LOG.info("Row not available");
84 Thread.sleep(SLEEP_TIME * NB_RETRIES);
85 } else {
86 assertArrayEquals(res.value(), row);
87 return;
88 }
89 }
90 fail("Waited too much time for put replication");
91 }
92 }