HBASE-23723 Ensure MOB compaction works in optimized mode after snapshot clone (...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / replication / TestReplicationDisableInactivePeer.java
blob4ea0bcf607331fe4afbda2af708f987460fd292f
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.replication;
20 import static org.junit.Assert.assertArrayEquals;
21 import static org.junit.Assert.fail;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
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.testclassification.LargeTests;
28 import org.apache.hadoop.hbase.testclassification.ReplicationTests;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.junit.ClassRule;
31 import org.junit.Test;
32 import org.junit.experimental.categories.Category;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 @Category({ReplicationTests.class, LargeTests.class})
37 public class TestReplicationDisableInactivePeer extends TestReplicationBase {
39 @ClassRule
40 public static final HBaseClassTestRule CLASS_RULE =
41 HBaseClassTestRule.forClass(TestReplicationDisableInactivePeer.class);
43 private static final Logger LOG =
44 LoggerFactory.getLogger(TestReplicationDisableInactivePeer.class);
46 /**
47 * Test disabling an inactive peer. Add a peer which is inactive, trying to
48 * insert, disable the peer, then activate the peer and make sure nothing is
49 * replicated. In Addition, enable the peer and check the updates are
50 * replicated.
52 * @throws Exception
54 @Test
55 public void testDisableInactivePeer() throws Exception {
56 UTIL2.shutdownMiniHBaseCluster();
58 byte[] rowkey = Bytes.toBytes("disable inactive peer");
59 Put put = new Put(rowkey);
60 put.addColumn(famName, row, row);
61 htable1.put(put);
63 // wait for the sleep interval of the master cluster to become long
64 Thread.sleep(SLEEP_TIME * NB_RETRIES);
66 // disable and start the peer
67 hbaseAdmin.disableReplicationPeer("2");
68 restartTargetHBaseCluster(2);
69 Get get = new Get(rowkey);
70 for (int i = 0; i < NB_RETRIES; i++) {
71 Result res = htable2.get(get);
72 if (res.size() >= 1) {
73 fail("Replication wasn't disabled");
74 } else {
75 LOG.info("Row not replicated, let's wait a bit more...");
76 Thread.sleep(SLEEP_TIME);
80 // Test enable replication
81 hbaseAdmin.enableReplicationPeer("2");
82 // wait since the sleep interval would be long
83 Thread.sleep(SLEEP_TIME * NB_RETRIES);
84 for (int i = 0; i < NB_RETRIES; i++) {
85 Result res = htable2.get(get);
86 if (res.isEmpty()) {
87 LOG.info("Row not available");
88 Thread.sleep(SLEEP_TIME * NB_RETRIES);
89 } else {
90 assertArrayEquals(row, res.value());
91 return;
94 fail("Waited too much time for put replication");