View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
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.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     * Test disabling an inactive peer. Add a peer which is inactive, trying to
41     * insert, disable the peer, then activate the peer and make sure nothing is
42     * replicated. In Addition, enable the peer and check the updates are
43     * replicated.
44     *
45     * @throws Exception
46     */
47    @Test(timeout = 600000)
48    public void testDisableInactivePeer() throws Exception {
49  
50      // enabling and shutdown the peer
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      // wait for the sleep interval of the master cluster to become long
60      Thread.sleep(SLEEP_TIME * NB_RETRIES);
61  
62      // disable and start the peer
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      // Test enable replication
77      admin.enablePeer("2");
78      // wait since the sleep interval would be long
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  }