diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java index e26fbb1eb83..6d40f850765 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java @@ -82,7 +82,7 @@ public class TestReplicationBase { protected static Configuration CONF2 = UTIL2.getConfiguration(); protected static int NUM_SLAVES1 = 1; - protected static final int NUM_SLAVES2 = 1; + protected static int NUM_SLAVES2 = 1; protected static final int NB_ROWS_IN_BATCH = 100; protected static final int NB_ROWS_IN_BIG_BATCH = NB_ROWS_IN_BATCH * 10; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRS.java index ae99eb897ad..b261b25bd81 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRS.java @@ -20,20 +20,27 @@ package org.apache.hadoop.hbase.replication; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; +import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; /** - * Runs the TestReplicationKillRS test and selects the RS to kill in the master cluster - * Do not add other tests in this class. + * Runs the TestReplicationKillRS test and selects the RS to kill in the master cluster Do not add + * other tests in this class. */ @Category({ ReplicationTests.class, LargeTests.class }) public class TestReplicationKillMasterRS extends TestReplicationKillRS { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationKillMasterRS.class); + HBaseClassTestRule.forClass(TestReplicationKillMasterRS.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + NUM_SLAVES1 = 2; + TestReplicationBase.setUpBeforeClass(); + } @Test public void killOneMasterRS() throws Exception { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSCompressed.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSCompressed.java index e649149ca57..8cfe8027340 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSCompressed.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSCompressed.java @@ -36,12 +36,9 @@ public class TestReplicationKillMasterRSCompressed extends TestReplicationKillMa public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestReplicationKillMasterRSCompressed.class); - /** - * @throws java.lang.Exception - */ @BeforeClass public static void setUpBeforeClass() throws Exception { CONF1.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true); - TestReplicationBase.setUpBeforeClass(); + TestReplicationKillMasterRS.setUpBeforeClass(); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSWithSeparateOldWALs.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSWithSeparateOldWALs.java index aa3aadde51a..d0ceb6b3957 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSWithSeparateOldWALs.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillMasterRSWithSeparateOldWALs.java @@ -15,7 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.hadoop.hbase.replication; import org.apache.hadoop.hbase.HBaseClassTestRule; @@ -24,24 +23,18 @@ import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Test; import org.junit.experimental.categories.Category; @Category({ ReplicationTests.class, LargeTests.class }) -public class TestReplicationKillMasterRSWithSeparateOldWALs extends TestReplicationKillRS { +public class TestReplicationKillMasterRSWithSeparateOldWALs extends TestReplicationKillMasterRS { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationKillMasterRSWithSeparateOldWALs.class); + HBaseClassTestRule.forClass(TestReplicationKillMasterRSWithSeparateOldWALs.class); @BeforeClass public static void setUpBeforeClass() throws Exception { CONF1.setBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR, true); - TestReplicationBase.setUpBeforeClass(); - } - - @Test - public void killOneMasterRS() throws Exception { - loadTableAndKillRS(UTIL1); + TestReplicationKillMasterRS.setUpBeforeClass(); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillRS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillRS.java index c2457267b28..c1f0760e49c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillRS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillRS.java @@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.replication; import static org.junit.Assert.fail; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.UnknownScannerException; import org.apache.hadoop.hbase.client.Connection; @@ -28,19 +27,11 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; -import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.apache.hadoop.hbase.testclassification.ReplicationTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ ReplicationTests.class, LargeTests.class }) -public class TestReplicationKillRS extends TestReplicationBase { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationKillRS.class); +public abstract class TestReplicationKillRS extends TestReplicationBase { private static final Logger LOG = LoggerFactory.getLogger(TestReplicationKillRS.class); @@ -48,7 +39,7 @@ public class TestReplicationKillRS extends TestReplicationBase { * Load up 1 tables over 2 region servers and kill a source during the upload. The failover * happens internally. WARNING this test sometimes fails because of HBASE-3515 */ - public void loadTableAndKillRS(HBaseTestingUtility util) throws Exception { + protected void loadTableAndKillRS(HBaseTestingUtility util) throws Exception { // killing the RS with hbase:meta can result into failed puts until we solve // IO fencing int rsToKill1 = util.getHBaseCluster().getServerWithMeta() == 0 ? 1 : 0; @@ -84,14 +75,14 @@ public class TestReplicationKillRS extends TestReplicationBase { } int lastCount = 0; - final long start = System.currentTimeMillis(); + final long start = EnvironmentEdgeManager.currentTime(); int i = 0; try (Connection conn = ConnectionFactory.createConnection(CONF2)) { try (Table table = conn.getTable(tableName)) { while (true) { if (i == NB_RETRIES - 1) { fail("Waited too much time for queueFailover replication. " + "Waited " - + (System.currentTimeMillis() - start) + "ms."); + + (EnvironmentEdgeManager.currentTime() - start) + "ms."); } Result[] res2; try (ResultScanner scanner = table.getScanner(new Scan())) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRS.java index 733fa3aa8d3..16663f0e77b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRS.java @@ -20,20 +20,27 @@ package org.apache.hadoop.hbase.replication; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; +import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; /** - * Runs the TestReplicationKillRS test and selects the RS to kill in the slave cluster - * Do not add other tests in this class. + * Runs the TestReplicationKillRS test and selects the RS to kill in the slave cluster Do not add + * other tests in this class. */ @Category({ ReplicationTests.class, LargeTests.class }) public class TestReplicationKillSlaveRS extends TestReplicationKillRS { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationKillSlaveRS.class); + HBaseClassTestRule.forClass(TestReplicationKillSlaveRS.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + NUM_SLAVES2 = 2; + TestReplicationBase.setUpBeforeClass(); + } @Test public void killOneSlaveRS() throws Exception { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRSWithSeparateOldWALs.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRSWithSeparateOldWALs.java index abff3e2caf6..195ad89b3e3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRSWithSeparateOldWALs.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationKillSlaveRSWithSeparateOldWALs.java @@ -24,24 +24,18 @@ import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Test; import org.junit.experimental.categories.Category; @Category({ ReplicationTests.class, LargeTests.class }) -public class TestReplicationKillSlaveRSWithSeparateOldWALs extends TestReplicationKillRS { +public class TestReplicationKillSlaveRSWithSeparateOldWALs extends TestReplicationKillSlaveRS { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationKillSlaveRSWithSeparateOldWALs.class); + HBaseClassTestRule.forClass(TestReplicationKillSlaveRSWithSeparateOldWALs.class); @BeforeClass public static void setUpBeforeClass() throws Exception { CONF1.setBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR, true); - TestReplicationBase.setUpBeforeClass(); - } - - @Test - public void killOneSlaveRS() throws Exception { - loadTableAndKillRS(UTIL2); + TestReplicationKillSlaveRS.setUpBeforeClass(); } }