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 048 * insert, disable the peer, then activate the peer and make sure nothing is 049 * replicated. In Addition, enable the peer and check the updates are 050 * replicated. 051 * 052 * @throws Exception 053 */ 054 @Test 055 public void testDisableInactivePeer() throws Exception { 056 UTIL2.shutdownMiniHBaseCluster(); 057 058 byte[] rowkey = Bytes.toBytes("disable inactive peer"); 059 Put put = new Put(rowkey); 060 put.addColumn(famName, row, row); 061 htable1.put(put); 062 063 // wait for the sleep interval of the master cluster to become long 064 Thread.sleep(SLEEP_TIME * NB_RETRIES); 065 066 // disable and start the peer 067 hbaseAdmin.disableReplicationPeer("2"); 068 restartTargetHBaseCluster(2); 069 Get get = new Get(rowkey); 070 for (int i = 0; i < NB_RETRIES; i++) { 071 Result res = htable2.get(get); 072 if (res.size() >= 1) { 073 fail("Replication wasn't disabled"); 074 } else { 075 LOG.info("Row not replicated, let's wait a bit more..."); 076 Thread.sleep(SLEEP_TIME); 077 } 078 } 079 080 // Test enable replication 081 admin.enablePeer("2"); 082 // wait since the sleep interval would be long 083 Thread.sleep(SLEEP_TIME * NB_RETRIES); 084 for (int i = 0; i < NB_RETRIES; i++) { 085 Result res = htable2.get(get); 086 if (res.isEmpty()) { 087 LOG.info("Row not available"); 088 Thread.sleep(SLEEP_TIME * NB_RETRIES); 089 } else { 090 assertArrayEquals(row, res.value()); 091 return; 092 } 093 } 094 fail("Waited too much time for put replication"); 095 } 096}