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.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     * 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      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      // Test enable replication
78      admin.enablePeer("2");
79      // wait since the sleep interval would be long
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  }