001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.replication; 019 020import static org.junit.Assert.assertArrayEquals; 021import static org.junit.Assert.fail; 022 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.client.Get; 025import org.apache.hadoop.hbase.client.Put; 026import org.apache.hadoop.hbase.client.Result; 027import org.apache.hadoop.hbase.testclassification.LargeTests; 028import org.apache.hadoop.hbase.testclassification.ReplicationTests; 029import org.apache.hadoop.hbase.util.Bytes; 030import org.junit.ClassRule; 031import org.junit.Test; 032import org.junit.experimental.categories.Category; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036@Category({ ReplicationTests.class, LargeTests.class }) 037public class TestReplicationDisableInactivePeer extends TestReplicationBase { 038 039 @ClassRule 040 public static final HBaseClassTestRule CLASS_RULE = 041 HBaseClassTestRule.forClass(TestReplicationDisableInactivePeer.class); 042 043 private static final Logger LOG = 044 LoggerFactory.getLogger(TestReplicationDisableInactivePeer.class); 045 046 /** 047 * Test disabling an inactive peer. Add a peer which is inactive, trying to insert, disable the 048 * peer, then activate the peer and make sure nothing is replicated. In Addition, enable the peer 049 * and check the updates are replicated. 050 */ 051 @Test 052 public void testDisableInactivePeer() throws Exception { 053 UTIL2.shutdownMiniHBaseCluster(); 054 055 byte[] rowkey = Bytes.toBytes("disable inactive peer"); 056 Put put = new Put(rowkey); 057 put.addColumn(famName, row, row); 058 htable1.put(put); 059 060 // wait for the sleep interval of the master cluster to become long 061 Thread.sleep(SLEEP_TIME * NB_RETRIES); 062 063 // disable and start the peer 064 hbaseAdmin.disableReplicationPeer("2"); 065 restartTargetHBaseCluster(2); 066 Get get = new Get(rowkey); 067 for (int i = 0; i < NB_RETRIES; i++) { 068 Result res = htable2.get(get); 069 if (res.size() >= 1) { 070 fail("Replication wasn't disabled"); 071 } else { 072 LOG.info("Row not replicated, let's wait a bit more..."); 073 Thread.sleep(SLEEP_TIME); 074 } 075 } 076 077 // Test enable replication 078 admin.enablePeer("2"); 079 // wait since the sleep interval would be long 080 Thread.sleep(SLEEP_TIME * NB_RETRIES); 081 for (int i = 0; i < NB_RETRIES; i++) { 082 Result res = htable2.get(get); 083 if (res.isEmpty()) { 084 LOG.info("Row not available"); 085 Thread.sleep(SLEEP_TIME * NB_RETRIES); 086 } else { 087 assertArrayEquals(row, res.value()); 088 return; 089 } 090 } 091 fail("Waited too much time for put replication"); 092 } 093}