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 e87e13d151b9..02924dcaa616 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 @@ -17,256 +17,15 @@ */ package org.apache.hadoop.hbase.replication; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Admin; -import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.ConnectionFactory; -import org.apache.hadoop.hbase.client.Delete; -import org.apache.hadoop.hbase.client.Get; -import org.apache.hadoop.hbase.client.Put; -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.client.TableDescriptor; -import org.apache.hadoop.hbase.client.TableDescriptorBuilder; -import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; -import org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.apache.hadoop.hbase.wal.WAL; -import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; import org.junit.BeforeClass; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.hbase.thirdparty.com.google.common.collect.Lists; -import org.apache.hbase.thirdparty.com.google.common.io.Closeables; /** * This class is only a base for other integration-level replication tests. Do not add tests here. * TestReplicationSmallTests is where tests that don't require bring machines up/down should go All * other tests should have their own classes and extend this one */ -public class TestReplicationBase { - private static final Logger LOG = LoggerFactory.getLogger(TestReplicationBase.class); - protected static Connection connection1; - protected static Connection connection2; - protected static Configuration CONF_WITH_LOCALFS; - - protected static ReplicationAdmin admin; - protected static Admin hbaseAdmin; - - protected static Table htable1; - protected static Table htable2; - - protected static final HBaseTestingUtility UTIL1 = new HBaseTestingUtility(); - protected static final HBaseTestingUtility UTIL2 = new HBaseTestingUtility(); - protected static Configuration CONF1 = UTIL1.getConfiguration(); - protected static Configuration CONF2 = UTIL2.getConfiguration(); - - protected static int NUM_SLAVES1 = 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; - protected static final long SLEEP_TIME = 500; - protected static final int NB_RETRIES = 50; - protected static AtomicInteger replicateCount = new AtomicInteger(); - protected static volatile List replicatedEntries = Lists.newArrayList(); - - protected static final TableName tableName = TableName.valueOf("test"); - protected static final byte[] famName = Bytes.toBytes("f"); - protected static final byte[] row = Bytes.toBytes("row"); - protected static final byte[] noRepfamName = Bytes.toBytes("norep"); - protected static final String PEER_ID2 = "2"; - - protected boolean isSerialPeer() { - return false; - } - - protected final void cleanUp() throws IOException, InterruptedException { - // Starting and stopping replication can make us miss new logs, - // rolling like this makes sure the most recent one gets added to the queue - for (JVMClusterUtil.RegionServerThread r : UTIL1.getHBaseCluster().getRegionServerThreads()) { - UTIL1.getAdmin().rollWALWriter(r.getRegionServer().getServerName()); - } - int rowCount = UTIL1.countRows(tableName); - UTIL1.deleteTableData(tableName); - // truncating the table will send one Delete per row to the slave cluster - // in an async fashion, which is why we cannot just call deleteTableData on - // utility2 since late writes could make it to the slave in some way. - // Instead, we truncate the first table and wait for all the Deletes to - // make it to the slave. - Scan scan = new Scan(); - int lastCount = 0; - for (int i = 0; i < NB_RETRIES; i++) { - if (i == NB_RETRIES - 1) { - fail("Waited too much time for truncate"); - } - ResultScanner scanner = htable2.getScanner(scan); - Result[] res = scanner.next(rowCount); - scanner.close(); - if (res.length != 0) { - if (res.length < lastCount) { - i--; // Don't increment timeout if we make progress - } - lastCount = res.length; - LOG.info("Still got " + res.length + " rows"); - Thread.sleep(SLEEP_TIME); - } else { - break; - } - } - } - - protected static void waitForReplication(int expectedRows, int retries) - throws IOException, InterruptedException { - waitForReplication(htable2, expectedRows, retries); - } - - protected static void waitForReplication(Table table, int expectedRows, int retries) - throws IOException, InterruptedException { - Scan scan; - for (int i = 0; i < retries; i++) { - scan = new Scan(); - if (i == retries - 1) { - fail("Waited too much time for normal batch replication"); - } - int count = 0; - try (ResultScanner scanner = table.getScanner(scan)) { - while (scanner.next() != null) { - count++; - } - } - if (count != expectedRows) { - LOG.info("Only got " + count + " rows"); - Thread.sleep(SLEEP_TIME); - } else { - break; - } - } - } - - protected static void loadData(String prefix, byte[] row) throws IOException { - loadData(prefix, row, famName); - } - - protected static void loadData(String prefix, byte[] row, byte[] familyName) throws IOException { - List puts = new ArrayList<>(NB_ROWS_IN_BATCH); - for (int i = 0; i < NB_ROWS_IN_BATCH; i++) { - Put put = new Put(Bytes.toBytes(prefix + Integer.toString(i))); - put.addColumn(familyName, row, row); - puts.add(put); - } - htable1.put(puts); - } - - protected static void setupConfig(HBaseTestingUtility util, String znodeParent) { - Configuration conf = util.getConfiguration(); - conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, znodeParent); - // We don't want too many edits per batch sent to the ReplicationEndpoint to trigger - // sufficient number of events. But we don't want to go too low because - // HBaseInterClusterReplicationEndpoint partitions entries into batches and we want - // more than one batch sent to the peer cluster for better testing. - conf.setInt("replication.source.size.capacity", 102400); - conf.setLong("replication.source.sleepforretries", 100); - conf.setInt("hbase.regionserver.maxlogs", 10); - conf.setLong("hbase.master.logcleaner.ttl", 10); - conf.setInt("zookeeper.recovery.retry", 1); - conf.setInt("zookeeper.recovery.retry.intervalmill", 10); - conf.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100); - conf.setInt("replication.stats.thread.period.seconds", 5); - conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); - conf.setLong("replication.sleep.before.failover", 2000); - conf.setInt("replication.source.maxretriesmultiplier", 10); - conf.setFloat("replication.source.ratio", 1.0f); - conf.setBoolean("replication.source.eof.autorecovery", true); - conf.setLong("hbase.serial.replication.waiting.ms", 100); - } - - static void configureClusters(HBaseTestingUtility util1, HBaseTestingUtility util2) { - setupConfig(util1, "/1"); - setupConfig(util2, "/2"); - - Configuration conf2 = util2.getConfiguration(); - conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); - conf2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); - conf2.setBoolean("hbase.tests.use.shortcircuit.reads", false); - } - - static void restartSourceCluster(int numSlaves) throws Exception { - Closeables.close(hbaseAdmin, true); - Closeables.close(htable1, true); - UTIL1.shutdownMiniHBaseCluster(); - UTIL1.restartHBaseCluster(numSlaves); - // Invalidate the cached connection state. - CONF1 = UTIL1.getConfiguration(); - hbaseAdmin = UTIL1.getAdmin(); - Connection connection1 = UTIL1.getConnection(); - htable1 = connection1.getTable(tableName); - } - - static void restartTargetHBaseCluster(int numSlaves) throws Exception { - Closeables.close(htable2, true); - UTIL2.restartHBaseCluster(numSlaves); - // Invalidate the cached connection state - CONF2 = UTIL2.getConfiguration(); - htable2 = UTIL2.getConnection().getTable(tableName); - } - - protected static void createTable(TableName tableName) throws IOException { - TableDescriptor table = TableDescriptorBuilder.newBuilder(tableName) - .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName).setMaxVersions(100) - .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()) - .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build(); - UTIL1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); - UTIL2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); - UTIL1.waitUntilAllRegionsAssigned(tableName); - UTIL2.waitUntilAllRegionsAssigned(tableName); - } - - private static void startClusters() throws Exception { - UTIL1.startMiniZKCluster(); - MiniZooKeeperCluster miniZK = UTIL1.getZkCluster(); - LOG.info("Setup first Zk"); - - UTIL2.setZkCluster(miniZK); - LOG.info("Setup second Zk"); - - CONF_WITH_LOCALFS = HBaseConfiguration.create(CONF1); - UTIL1.startMiniCluster(NUM_SLAVES1); - // Have a bunch of slave servers, because inter-cluster shipping logic uses number of sinks - // as a component in deciding maximum number of parallel batches to send to the peer cluster. - UTIL2.startMiniCluster(NUM_SLAVES2); - - connection1 = ConnectionFactory.createConnection(CONF1); - connection2 = ConnectionFactory.createConnection(CONF2); - admin = new ReplicationAdmin(CONF1); - hbaseAdmin = connection1.getAdmin(); - - createTable(tableName); - htable1 = connection1.getTable(tableName); - htable2 = connection2.getTable(tableName); - } +public class TestReplicationBase extends TestReplicationBaseNoBeforeAll { @BeforeAll @BeforeClass @@ -274,146 +33,4 @@ public static void setUpBeforeClass() throws Exception { configureClusters(UTIL1, UTIL2); startClusters(); } - - private boolean peerExist(String peerId) throws IOException { - return peerExist(peerId, UTIL1); - } - - private boolean peerExist(String peerId, HBaseTestingUtility util) throws IOException { - return util.getAdmin().listReplicationPeers().stream() - .anyMatch(p -> peerId.equals(p.getPeerId())); - } - - protected final void addPeer(String peerId, TableName tableName) throws Exception { - addPeer(peerId, tableName, UTIL1, UTIL2); - } - - protected final void addPeer(String peerId, TableName tableName, HBaseTestingUtility source, - HBaseTestingUtility target) throws Exception { - if (peerExist(peerId, source)) { - return; - } - ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder() - .setClusterKey(target.getClusterKey()).setSerial(isSerialPeer()) - .setReplicationEndpointImpl(ReplicationEndpointTest.class.getName()); - source.getAdmin().addReplicationPeer(peerId, builder.build()); - } - - @Before - @BeforeEach - public void setUpBase() throws Exception { - addPeer(PEER_ID2, tableName); - } - - protected final void removePeer(String peerId) throws Exception { - removePeer(peerId, UTIL1); - } - - protected final void removePeer(String peerId, HBaseTestingUtility util) throws Exception { - if (peerExist(peerId, util)) { - util.getAdmin().removeReplicationPeer(peerId); - } - } - - @After - @AfterEach - public void tearDownBase() throws Exception { - removePeer(PEER_ID2); - } - - protected static void runSimplePutDeleteTest() throws IOException, InterruptedException { - Put put = new Put(row); - put.addColumn(famName, row, row); - - htable1 = UTIL1.getConnection().getTable(tableName); - htable1.put(put); - - Get get = new Get(row); - for (int i = 0; i < NB_RETRIES; i++) { - if (i == NB_RETRIES - 1) { - fail("Waited too much time for put replication"); - } - Result res = htable2.get(get); - if (res.isEmpty()) { - LOG.info("Row not available"); - Thread.sleep(SLEEP_TIME); - } else { - assertArrayEquals(row, res.value()); - break; - } - } - - Delete del = new Delete(row); - htable1.delete(del); - - get = new Get(row); - for (int i = 0; i < NB_RETRIES; i++) { - if (i == NB_RETRIES - 1) { - fail("Waited too much time for del replication"); - } - Result res = htable2.get(get); - if (res.size() >= 1) { - LOG.info("Row not deleted"); - Thread.sleep(SLEEP_TIME); - } else { - break; - } - } - } - - protected static void runSmallBatchTest() throws IOException, InterruptedException { - // normal Batch tests - loadData("", row); - - Scan scan = new Scan(); - - ResultScanner scanner1 = htable1.getScanner(scan); - Result[] res1 = scanner1.next(NB_ROWS_IN_BATCH); - scanner1.close(); - assertEquals(NB_ROWS_IN_BATCH, res1.length); - - waitForReplication(NB_ROWS_IN_BATCH, NB_RETRIES); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - if (htable2 != null) { - htable2.close(); - } - if (htable1 != null) { - htable1.close(); - } - if (admin != null) { - admin.close(); - } - if (hbaseAdmin != null) { - hbaseAdmin.close(); - } - - if (connection2 != null) { - connection2.close(); - } - if (connection1 != null) { - connection1.close(); - } - UTIL2.shutdownMiniCluster(); - UTIL1.shutdownMiniCluster(); - } - - /** - * Custom replication endpoint to keep track of replication status for tests. - */ - public static class ReplicationEndpointTest extends HBaseInterClusterReplicationEndpoint { - public ReplicationEndpointTest() { - replicateCount.set(0); - } - - @Override - public boolean replicate(ReplicateContext replicateContext) { - replicateCount.incrementAndGet(); - replicatedEntries.addAll(replicateContext.getEntries()); - - return super.replicate(replicateContext); - } - } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBaseNoBeforeAll.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBaseNoBeforeAll.java new file mode 100644 index 000000000000..96cc8e23ac7a --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBaseNoBeforeAll.java @@ -0,0 +1,409 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.replication; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; +import org.apache.hadoop.hbase.client.Delete; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Put; +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.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; +import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; +import org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.JVMClusterUtil; +import org.apache.hadoop.hbase.wal.WAL; +import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hbase.thirdparty.com.google.common.collect.Lists; +import org.apache.hbase.thirdparty.com.google.common.io.Closeables; + +/** + * Replication test base class without BeforeAll method, as in some tests we need to do some changes + * before starting clusters. + * @see TestReplicationBase + */ +public class TestReplicationBaseNoBeforeAll { + private static final Logger LOG = LoggerFactory.getLogger(TestReplicationBaseNoBeforeAll.class); + protected static Connection connection1; + protected static Connection connection2; + protected static Configuration CONF_WITH_LOCALFS; + + protected static ReplicationAdmin admin; + protected static Admin hbaseAdmin; + + protected static Table htable1; + protected static Table htable2; + + protected static final HBaseTestingUtility UTIL1 = new HBaseTestingUtility(); + protected static final HBaseTestingUtility UTIL2 = new HBaseTestingUtility(); + protected static Configuration CONF1 = UTIL1.getConfiguration(); + protected static Configuration CONF2 = UTIL2.getConfiguration(); + + protected static int NUM_SLAVES1 = 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; + protected static final long SLEEP_TIME = 500; + protected static final int NB_RETRIES = 50; + protected static AtomicInteger replicateCount = new AtomicInteger(); + protected static volatile List replicatedEntries = Lists.newArrayList(); + + protected static final TableName tableName = TableName.valueOf("test"); + protected static final byte[] famName = Bytes.toBytes("f"); + protected static final byte[] row = Bytes.toBytes("row"); + protected static final byte[] noRepfamName = Bytes.toBytes("norep"); + protected static final String PEER_ID2 = "2"; + + protected boolean isSerialPeer() { + return false; + } + + protected final void cleanUp() throws IOException, InterruptedException { + // Starting and stopping replication can make us miss new logs, + // rolling like this makes sure the most recent one gets added to the queue + for (JVMClusterUtil.RegionServerThread r : UTIL1.getHBaseCluster().getRegionServerThreads()) { + UTIL1.getAdmin().rollWALWriter(r.getRegionServer().getServerName()); + } + int rowCount = UTIL1.countRows(tableName); + UTIL1.deleteTableData(tableName); + // truncating the table will send one Delete per row to the slave cluster + // in an async fashion, which is why we cannot just call deleteTableData on + // utility2 since late writes could make it to the slave in some way. + // Instead, we truncate the first table and wait for all the Deletes to + // make it to the slave. + Scan scan = new Scan(); + int lastCount = 0; + for (int i = 0; i < NB_RETRIES; i++) { + if (i == NB_RETRIES - 1) { + fail("Waited too much time for truncate"); + } + ResultScanner scanner = htable2.getScanner(scan); + Result[] res = scanner.next(rowCount); + scanner.close(); + if (res.length != 0) { + if (res.length < lastCount) { + i--; // Don't increment timeout if we make progress + } + lastCount = res.length; + LOG.info("Still got " + res.length + " rows"); + Thread.sleep(SLEEP_TIME); + } else { + break; + } + } + } + + protected static void waitForReplication(int expectedRows, int retries) + throws IOException, InterruptedException { + waitForReplication(htable2, expectedRows, retries); + } + + protected static void waitForReplication(Table table, int expectedRows, int retries) + throws IOException, InterruptedException { + Scan scan; + for (int i = 0; i < retries; i++) { + scan = new Scan(); + if (i == retries - 1) { + fail("Waited too much time for normal batch replication"); + } + int count = 0; + try (ResultScanner scanner = table.getScanner(scan)) { + while (scanner.next() != null) { + count++; + } + } + if (count != expectedRows) { + LOG.info("Only got " + count + " rows"); + Thread.sleep(SLEEP_TIME); + } else { + break; + } + } + } + + protected static void loadData(String prefix, byte[] row) throws IOException { + loadData(prefix, row, famName); + } + + protected static void loadData(String prefix, byte[] row, byte[] familyName) throws IOException { + List puts = new ArrayList<>(NB_ROWS_IN_BATCH); + for (int i = 0; i < NB_ROWS_IN_BATCH; i++) { + Put put = new Put(Bytes.toBytes(prefix + Integer.toString(i))); + put.addColumn(familyName, row, row); + puts.add(put); + } + htable1.put(puts); + } + + protected static void setupConfig(HBaseTestingUtility util, String znodeParent) { + Configuration conf = util.getConfiguration(); + conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, znodeParent); + // We don't want too many edits per batch sent to the ReplicationEndpoint to trigger + // sufficient number of events. But we don't want to go too low because + // HBaseInterClusterReplicationEndpoint partitions entries into batches and we want + // more than one batch sent to the peer cluster for better testing. + conf.setInt("replication.source.size.capacity", 102400); + conf.setLong("replication.source.sleepforretries", 100); + conf.setInt("hbase.regionserver.maxlogs", 10); + conf.setLong("hbase.master.logcleaner.ttl", 10); + conf.setInt("zookeeper.recovery.retry", 1); + conf.setInt("zookeeper.recovery.retry.intervalmill", 10); + conf.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100); + conf.setInt("replication.stats.thread.period.seconds", 5); + conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); + conf.setLong("replication.sleep.before.failover", 2000); + conf.setInt("replication.source.maxretriesmultiplier", 10); + conf.setFloat("replication.source.ratio", 1.0f); + conf.setBoolean("replication.source.eof.autorecovery", true); + conf.setLong("hbase.serial.replication.waiting.ms", 100); + } + + protected static void configureClusters(HBaseTestingUtility util1, HBaseTestingUtility util2) { + setupConfig(util1, "/1"); + setupConfig(util2, "/2"); + + Configuration conf2 = util2.getConfiguration(); + conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); + conf2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); + conf2.setBoolean("hbase.tests.use.shortcircuit.reads", false); + } + + static void restartSourceCluster(int numSlaves) throws Exception { + Closeables.close(hbaseAdmin, true); + Closeables.close(htable1, true); + Closeables.close(connection1, true); + UTIL1.shutdownMiniHBaseCluster(); + UTIL1.restartHBaseCluster(numSlaves); + // Invalidate the cached connection state. + CONF1 = UTIL1.getConfiguration(); + connection1 = ConnectionFactory.createConnection(CONF1); + hbaseAdmin = connection1.getAdmin(); + htable1 = connection1.getTable(tableName); + } + + static void restartTargetHBaseCluster(int numSlaves) throws Exception { + Closeables.close(htable2, true); + Closeables.close(connection2, true); + UTIL2.restartHBaseCluster(numSlaves); + // Invalidate the cached connection state + CONF2 = UTIL2.getConfiguration(); + connection2 = ConnectionFactory.createConnection(CONF2); + htable2 = connection2.getTable(tableName); + } + + protected static void createTable(TableName tableName) throws IOException { + TableDescriptor table = TableDescriptorBuilder.newBuilder(tableName) + .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName).setMaxVersions(100) + .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()) + .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build(); + UTIL1.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); + UTIL2.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); + UTIL1.waitUntilAllRegionsAssigned(tableName); + UTIL2.waitUntilAllRegionsAssigned(tableName); + } + + protected static void startClusters() throws Exception { + UTIL1.startMiniZKCluster(); + MiniZooKeeperCluster miniZK = UTIL1.getZkCluster(); + LOG.info("Setup first Zk"); + + UTIL2.setZkCluster(miniZK); + LOG.info("Setup second Zk"); + + CONF_WITH_LOCALFS = HBaseConfiguration.create(CONF1); + UTIL1.startMiniCluster(NUM_SLAVES1); + // Have a bunch of slave servers, because inter-cluster shipping logic uses number of sinks + // as a component in deciding maximum number of parallel batches to send to the peer cluster. + UTIL2.startMiniCluster(NUM_SLAVES2); + + connection1 = ConnectionFactory.createConnection(CONF1); + connection2 = ConnectionFactory.createConnection(CONF2); + admin = new ReplicationAdmin(CONF1); + hbaseAdmin = connection1.getAdmin(); + + createTable(tableName); + htable1 = connection1.getTable(tableName); + htable2 = connection2.getTable(tableName); + } + + private boolean peerExist(String peerId, HBaseTestingUtility util) throws IOException { + return util.getAdmin().listReplicationPeers().stream() + .anyMatch(p -> peerId.equals(p.getPeerId())); + } + + protected final void addPeer(String peerId, TableName tableName) throws Exception { + addPeer(peerId, tableName, UTIL1, UTIL2); + } + + protected final void addPeer(String peerId, TableName tableName, HBaseTestingUtility source, + HBaseTestingUtility target) throws Exception { + if (peerExist(peerId, source)) { + return; + } + ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder() + .setClusterKey(target.getClusterKey()).setSerial(isSerialPeer()) + .setReplicationEndpointImpl(ReplicationEndpointTest.class.getName()); + source.getAdmin().addReplicationPeer(peerId, builder.build()); + } + + @Before + @BeforeEach + public void setUpBase() throws Exception { + addPeer(PEER_ID2, tableName); + } + + protected final void removePeer(String peerId) throws Exception { + removePeer(peerId, UTIL1); + } + + protected final void removePeer(String peerId, HBaseTestingUtility util) throws Exception { + if (peerExist(peerId, util)) { + util.getAdmin().removeReplicationPeer(peerId); + } + } + + @After + @AfterEach + public void tearDownBase() throws Exception { + removePeer(PEER_ID2); + } + + protected static void runSimplePutDeleteTest() throws IOException, InterruptedException { + Put put = new Put(row); + put.addColumn(famName, row, row); + + htable1 = UTIL1.getConnection().getTable(tableName); + htable1.put(put); + + Get get = new Get(row); + for (int i = 0; i < NB_RETRIES; i++) { + if (i == NB_RETRIES - 1) { + fail("Waited too much time for put replication"); + } + Result res = htable2.get(get); + if (res.isEmpty()) { + LOG.info("Row not available"); + Thread.sleep(SLEEP_TIME); + } else { + assertArrayEquals(row, res.value()); + break; + } + } + + Delete del = new Delete(row); + htable1.delete(del); + + get = new Get(row); + for (int i = 0; i < NB_RETRIES; i++) { + if (i == NB_RETRIES - 1) { + fail("Waited too much time for del replication"); + } + Result res = htable2.get(get); + if (res.size() >= 1) { + LOG.info("Row not deleted"); + Thread.sleep(SLEEP_TIME); + } else { + break; + } + } + } + + protected static void runSmallBatchTest() throws IOException, InterruptedException { + // normal Batch tests + loadData("", row); + + Scan scan = new Scan(); + + ResultScanner scanner1 = htable1.getScanner(scan); + Result[] res1 = scanner1.next(NB_ROWS_IN_BATCH); + scanner1.close(); + assertEquals(NB_ROWS_IN_BATCH, res1.length); + + waitForReplication(NB_ROWS_IN_BATCH, NB_RETRIES); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (htable2 != null) { + htable2.close(); + } + if (htable1 != null) { + htable1.close(); + } + if (admin != null) { + admin.close(); + } + if (hbaseAdmin != null) { + hbaseAdmin.close(); + } + + if (connection2 != null) { + connection2.close(); + } + if (connection1 != null) { + connection1.close(); + } + UTIL2.shutdownMiniCluster(); + UTIL1.shutdownMiniCluster(); + } + + /** + * Custom replication endpoint to keep track of replication status for tests. + */ + public static class ReplicationEndpointTest extends HBaseInterClusterReplicationEndpoint { + public ReplicationEndpointTest() { + replicateCount.set(0); + } + + @Override + public boolean replicate(ReplicateContext replicateContext) { + replicateCount.incrementAndGet(); + replicatedEntries.addAll(replicateContext.getEntries()); + + return super.replicate(replicateContext); + } + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStream.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStream.java index b3265da3887a..0579aec49846 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStream.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStream.java @@ -17,14 +17,15 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -32,7 +33,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.NavigableMap; @@ -71,11 +71,8 @@ import org.apache.hadoop.hbase.wal.WALFactory; import org.apache.hadoop.hbase.wal.WALKeyImpl; import org.apache.hadoop.hbase.wal.WALProvider; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestTemplate; import org.mockito.Mockito; import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos; @@ -83,15 +80,13 @@ public abstract class TestBasicWALEntryStream extends WALEntryStreamTestBase { - @Parameter - public boolean isCompressionEnabled; + protected boolean isCompressionEnabled; - @Parameters(name = "{index}: isCompressionEnabled={0}") - public static Iterable data() { - return Arrays.asList(new Object[] { false }, new Object[] { true }); + protected TestBasicWALEntryStream(boolean isCompressionEnabled) { + this.isCompressionEnabled = isCompressionEnabled; } - @Before + @BeforeEach public void setUp() throws Exception { CONF.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, isCompressionEnabled); initWAL(); @@ -105,7 +100,7 @@ private WAL.Entry next(WALEntryStream entryStream) { /** * Tests basic reading of log appends */ - @Test + @TestTemplate public void testAppendsWithRolls() throws Exception { appendToLogAndSync(); long oldPos; @@ -160,7 +155,7 @@ oldPos, log, new MetricsSource("1"), fakeWalGroupId)) { * Tests that if after a stream is opened, more entries come in and then the log is rolled, we * don't mistakenly dequeue the current log thinking we're done with it */ - @Test + @TestTemplate public void testLogRollWhileStreaming() throws Exception { appendToLog("1"); // 2 @@ -197,7 +192,7 @@ public void testLogRollWhileStreaming() throws Exception { * Tests that if writes come in while we have a stream open, we shouldn't miss them */ - @Test + @TestTemplate public void testNewEntriesWhileStreaming() throws Exception { appendToLog("1"); try (WALEntryStream entryStream = @@ -219,7 +214,7 @@ public void testNewEntriesWhileStreaming() throws Exception { } } - @Test + @TestTemplate public void testResumeStreamingFromPosition() throws Exception { long lastPosition = 0; appendToLog("1"); @@ -244,7 +239,7 @@ public void testResumeStreamingFromPosition() throws Exception { * Tests that if we stop before hitting the end of a stream, we can continue where we left off * using the last position */ - @Test + @TestTemplate public void testPosition() throws Exception { long lastPosition = 0; appendEntriesToLogAndSync(3); @@ -263,7 +258,7 @@ public void testPosition() throws Exception { } } - @Test + @TestTemplate public void testEmptyStream() throws Exception { try (WALEntryStream entryStream = new WALEntryStream(logQueue, fs, CONF, 0, log, new MetricsSource("1"), fakeWalGroupId)) { @@ -271,7 +266,7 @@ public void testEmptyStream() throws Exception { } } - @Test + @TestTemplate public void testWALKeySerialization() throws Exception { Map attributes = new HashMap(); attributes.put("foo", Bytes.toBytes("foo-value")); @@ -279,7 +274,7 @@ public void testWALKeySerialization() throws Exception { WALKeyImpl key = new WALKeyImpl(info.getEncodedNameAsBytes(), tableName, EnvironmentEdgeManager.currentTime(), new ArrayList(), 0L, 0L, mvcc, scopes, attributes); - Assert.assertEquals(attributes, key.getExtendedAttributes()); + assertEquals(attributes, key.getExtendedAttributes()); WALProtos.WALKey.Builder builder = key.getBuilder(WALCellCodec.getNoneCompressor()); WALProtos.WALKey serializedKey = builder.build(); @@ -288,14 +283,14 @@ public void testWALKeySerialization() throws Exception { deserializedKey.readFieldsFromPb(serializedKey, WALCellCodec.getNoneUncompressor()); // equals() only checks region name, sequence id and write time - Assert.assertEquals(key, deserializedKey); + assertEquals(key, deserializedKey); // can't use Map.equals() because byte arrays use reference equality - Assert.assertEquals(key.getExtendedAttributes().keySet(), + assertEquals(key.getExtendedAttributes().keySet(), deserializedKey.getExtendedAttributes().keySet()); for (Map.Entry entry : deserializedKey.getExtendedAttributes().entrySet()) { - Assert.assertArrayEquals(key.getExtendedAttribute(entry.getKey()), entry.getValue()); + assertArrayEquals(key.getExtendedAttribute(entry.getKey()), entry.getValue()); } - Assert.assertEquals(key.getReplicationScopes(), deserializedKey.getReplicationScopes()); + assertEquals(key.getReplicationScopes(), deserializedKey.getReplicationScopes()); } private ReplicationSource mockReplicationSource(boolean recovered, Configuration conf) @@ -345,7 +340,7 @@ private ReplicationSourceWALReader createReaderWithBadReplicationFilter(int numF return reader; } - @Test + @TestTemplate public void testReplicationSourceWALReader() throws Exception { appendEntriesToLogAndSync(3); // get ending position @@ -376,7 +371,7 @@ public void testReplicationSourceWALReader() throws Exception { assertEquals("foo", getRow(entryBatch.getWalEntries().get(0))); } - @Test + @TestTemplate public void testReplicationSourceWALReaderWithFailingFilter() throws Exception { appendEntriesToLogAndSync(3); // get ending position @@ -405,7 +400,7 @@ public void testReplicationSourceWALReaderWithFailingFilter() throws Exception { assertEquals(3, entryBatch.getNbRowKeys()); } - @Test + @TestTemplate public void testReplicationSourceWALReaderRecovered() throws Exception { appendEntriesToLogAndSync(10); Path walPath = getQueue().peek(); @@ -438,7 +433,7 @@ public void testReplicationSourceWALReaderRecovered() throws Exception { } // Testcase for HBASE-20206 - @Test + @TestTemplate public void testReplicationSourceWALReaderWrongPosition() throws Exception { appendEntriesToLogAndSync(1); Path walPath = getQueue().peek(); @@ -465,8 +460,8 @@ public String explainFailure() throws Exception { assertEquals(walPath, entryBatch.getLastWalPath()); long walLength = fs.getFileStatus(walPath).getLen(); - assertTrue("Position " + entryBatch.getLastWalPosition() + " is out of range, file length is " - + walLength, entryBatch.getLastWalPosition() <= walLength); + assertTrue(entryBatch.getLastWalPosition() <= walLength, "Position " + + entryBatch.getLastWalPosition() + " is out of range, file length is " + walLength); assertEquals(1, entryBatch.getNbEntries()); assertTrue(entryBatch.isEndOfFile()); @@ -490,7 +485,7 @@ public String explainFailure() throws Exception { assertFalse(entryBatch.isEndOfFile()); } - @Test + @TestTemplate public void testReplicationSourceWALReaderDisabled() throws IOException, InterruptedException, ExecutionException { appendEntriesToLogAndSync(3); @@ -598,7 +593,7 @@ public static int numFailures() { } } - @Test + @TestTemplate public void testReadBeyondCommittedLength() throws IOException, InterruptedException { appendToLog("1"); appendToLog("2"); @@ -625,7 +620,7 @@ public void testReadBeyondCommittedLength() throws IOException, InterruptedExcep * Test removal of 0 length log from logQueue if the source is a recovered source and size of * logQueue is only 1. */ - @Test + @TestTemplate public void testEOFExceptionForRecoveredQueue() throws Exception { // Create a 0 length log. Path emptyLog = new Path("emptyLog"); @@ -656,7 +651,7 @@ public void testEOFExceptionForRecoveredQueue() throws Exception { assertEquals(0, localLogQueue.getQueueSize(fakeWalGroupId)); } - @Test + @TestTemplate public void testEOFExceptionForRecoveredQueueWithMultipleLogs() throws Exception { Configuration conf = new Configuration(CONF); MetricsSource metrics = mock(MetricsSource.class); @@ -681,14 +676,14 @@ public void testEOFExceptionForRecoveredQueueWithMultipleLogs() throws Exception // Create a reader thread. ReplicationSourceWALReader reader = new ReplicationSourceWALReader(fs, conf, localLogQueue, 0, getDummyFilter(), source, fakeWalGroupId); - assertEquals("Initial log queue size is not correct", 2, - localLogQueue.getQueueSize(fakeWalGroupId)); + assertEquals(2, localLogQueue.getQueueSize(fakeWalGroupId), + "Initial log queue size is not correct"); reader.start(); reader.join(); // remove empty log from logQueue. assertEquals(0, localLogQueue.getQueueSize(fakeWalGroupId)); - assertEquals("Log queue should be empty", 0, localLogQueue.getQueueSize(fakeWalGroupId)); + assertEquals(0, localLogQueue.getQueueSize(fakeWalGroupId), "Log queue should be empty"); } private PriorityBlockingQueue getQueue() { @@ -713,7 +708,7 @@ private void appendEntries(WALProvider.Writer writer, int numEntries) throws IOE /*** * Tests size of log queue is incremented and decremented properly. */ - @Test + @TestTemplate public void testSizeOfLogQueue() throws Exception { // There should be always 1 log which is current wal. assertEquals(1, logQueue.getMetrics().getSizeOfLogQueue()); @@ -744,7 +739,7 @@ public void testSizeOfLogQueue() throws Exception { * Tests that wals are closed cleanly and we read the trailer when we remove wal from * WALEntryStream. */ - @Test + @TestTemplate public void testCleanClosedWALs() throws Exception { try (WALEntryStream entryStream = new WALEntryStreamWithRetries(logQueue, fs, CONF, 0, log, logQueue.getMetrics(), fakeWalGroupId)) { @@ -761,7 +756,7 @@ public void testCleanClosedWALs() throws Exception { /** * Tests that we handle EOFException properly if the wal has moved to oldWALs directory. */ - @Test + @TestTemplate public void testEOFExceptionInOldWALsDirectory() throws Exception { assertEquals(1, logQueue.getQueueSize(fakeWalGroupId)); AbstractFSWAL abstractWAL = (AbstractFSWAL) log; @@ -805,7 +800,7 @@ public void testEOFExceptionInOldWALsDirectory() throws Exception { * decreased because {@link WALEntryBatch} is not put to * {@link ReplicationSourceWALReader#entryBatchQueue}. */ - @Test + @TestTemplate public void testReplicationSourceWALReaderWithPartialWALEntryFailingFilter() throws Exception { appendEntriesToLogAndSync(3); // get ending position @@ -844,7 +839,7 @@ public void testReplicationSourceWALReaderWithPartialWALEntryFailingFilter() thr } // testcase for HBASE-28748 - @Test + @TestTemplate public void testWALEntryStreamEOFRightAfterHeader() throws Exception { assertEquals(1, logQueue.getQueueSize(fakeWalGroupId)); AbstractFSWAL abstractWAL = (AbstractFSWAL) log; @@ -887,7 +882,7 @@ public void testWALEntryStreamEOFRightAfterHeader() throws Exception { * WALEntryFilterRetryableException does not cause the new file to be opened at the old file's * position. */ - @Test + @TestTemplate public void testPositionResetOnFileSwitchWithRetryableFilter() throws Exception { appendEntriesToLogAndSync(3); log.rollWriter(); @@ -922,15 +917,15 @@ public void testPositionResetOnFileSwitchWithRetryableFilter() throws Exception long deadline = System.currentTimeMillis() + 30000; while (totalEntries < 6) { long remaining = deadline - System.currentTimeMillis(); - assertTrue("Reader appears stuck - likely position corruption. Only got " + totalEntries - + " of 6 entries", remaining > 0); + assertTrue(remaining > 0, "Reader appears stuck - likely position corruption. Only got " + + totalEntries + " of 6 entries"); WALEntryBatch batch = reader.poll(1); if (batch != null && batch != WALEntryBatch.NO_MORE_DATA) { totalEntries += batch.getNbEntries(); } } assertEquals(6, totalEntries); - assertTrue("Filter should have thrown at least once", threwOnce.get()); + assertTrue(threwOnce.get(), "Filter should have thrown at least once"); } private static class PartialWALEntryFailingWALEntryFilter implements WALEntryFilter { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamAsyncFSWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamAsyncFSWAL.java index 2c37e34ae4e7..d4ccfeed5dc2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamAsyncFSWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamAsyncFSWAL.java @@ -17,30 +17,31 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import java.util.stream.Stream; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.apache.hadoop.hbase.wal.AsyncFSWALProvider; import org.apache.hadoop.hbase.wal.WALFactory; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.params.provider.Arguments; -/** - * TestBasicWALEntryStream with {@link AsyncFSWALProvider} as the WAL provider. - */ -@RunWith(Parameterized.class) -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: isCompressionEnabled={0}") public class TestBasicWALEntryStreamAsyncFSWAL extends TestBasicWALEntryStream { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestBasicWALEntryStreamAsyncFSWAL.class); + public TestBasicWALEntryStreamAsyncFSWAL(boolean isCompressionEnabled) { + super(isCompressionEnabled); + } + + public static Stream parameters() { + return Stream.of(Arguments.of(false), Arguments.of(true)); + } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, AsyncFSWALProvider.class, AbstractFSWALProvider.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamFSHLog.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamFSHLog.java index 7ab9d3fc5a88..84928f8fcbd5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamFSHLog.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStreamFSHLog.java @@ -17,30 +17,31 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import java.util.stream.Stream; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.apache.hadoop.hbase.wal.FSHLogProvider; import org.apache.hadoop.hbase.wal.WALFactory; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.params.provider.Arguments; -/** - * TestBasicWALEntryStream with {@link FSHLogProvider} as the WAL provider. - */ -@RunWith(Parameterized.class) -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: isCompressionEnabled={0}") public class TestBasicWALEntryStreamFSHLog extends TestBasicWALEntryStream { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestBasicWALEntryStreamFSHLog.class); + public TestBasicWALEntryStreamFSHLog(boolean isCompressionEnabled) { + super(isCompressionEnabled); + } + + public static Stream parameters() { + return Stream.of(Arguments.of(false), Arguments.of(true)); + } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, FSHLogProvider.class, AbstractFSWALProvider.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestDumpReplicationQueues.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestDumpReplicationQueues.java index d78a45ca6b9c..7385e13ea41f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestDumpReplicationQueues.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestDumpReplicationQueues.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,7 +27,6 @@ import java.util.List; import java.util.Set; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -35,20 +34,18 @@ import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; import org.apache.hadoop.hbase.zookeeper.ZNodePaths; -import org.junit.ClassRule; -import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Tests for DumpReplicationQueues tool */ +@Tag(ReplicationTests.TAG) +@Tag(SmallTests.TAG) @Category({ ReplicationTests.class, SmallTests.class }) public class TestDumpReplicationQueues { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestDumpReplicationQueues.class); - /** * Makes sure dumpQueues returns wals znodes ordered chronologically. * @throws Exception if dumpqueues finds any error while handling list of znodes. @@ -82,16 +79,13 @@ public void testDumpReplicationReturnsWalSorted() throws Exception { dumpQueues.setConf(config); String dump = dumpQueues.dumpQueues(zkWatcherMock, peerIds, false); String[] parsedDump = dump.split("Replication position for"); - assertEquals("Parsed dump should have 4 parts.", 4, parsedDump.length); - assertTrue( - "First wal should be rs1%2C60964%2C1549394085556.1549394101426, but got: " + parsedDump[1], - parsedDump[1].indexOf("rs1%2C60964%2C1549394085556.1549394101426") >= 0); - assertTrue( - "Second wal should be rs1%2C60964%2C1549394085556.1549394101427, but got: " + parsedDump[2], - parsedDump[2].indexOf("rs1%2C60964%2C1549394085556.1549394101427") >= 0); - assertTrue( - "Third wal should be rs1%2C60964%2C1549394085556.1549394101428, but got: " + parsedDump[3], - parsedDump[3].indexOf("rs1%2C60964%2C1549394085556.1549394101428") >= 0); + assertEquals(4, parsedDump.length, "Parsed dump should have 4 parts."); + assertTrue(parsedDump[1].indexOf("rs1%2C60964%2C1549394085556.1549394101426") >= 0, + "First wal should be rs1%2C60964%2C1549394085556.1549394101426, but got: " + parsedDump[1]); + assertTrue(parsedDump[2].indexOf("rs1%2C60964%2C1549394085556.1549394101427") >= 0, + "Second wal should be rs1%2C60964%2C1549394085556.1549394101427, but got: " + parsedDump[2]); + assertTrue(parsedDump[3].indexOf("rs1%2C60964%2C1549394085556.1549394101428") >= 0, + "Third wal should be rs1%2C60964%2C1549394085556.1549394101428, but got: " + parsedDump[3]); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java index 698c19a80e85..eec5bd221107 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java @@ -17,21 +17,22 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import java.io.IOException; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTestConst; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Put; 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.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.testclassification.LargeTests; @@ -41,25 +42,20 @@ import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ ReplicationTests.class, LargeTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(LargeTests.TAG) public class TestGlobalReplicationThrottler { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestGlobalReplicationThrottler.class); - private static final Logger LOG = LoggerFactory.getLogger(TestGlobalReplicationThrottler.class); + private static final int REPLICATION_SOURCE_QUOTA = 200; private static int numOfPeer = 0; private static Configuration conf1; @@ -73,10 +69,9 @@ public class TestGlobalReplicationThrottler { private static final byte[] ROW = Bytes.toBytes("r"); private static final byte[][] ROWS = HTestConst.makeNAscii(ROW, 100); - @Rule - public TestName name = new TestName(); + private String testName; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { conf1 = HBaseConfiguration.create(); conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1"); @@ -110,7 +105,7 @@ public static void setUpBeforeClass() throws Exception { numOfPeer = admin1.getPeersCount(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { utility2.shutdownMiniCluster(); utility1.shutdownMiniCluster(); @@ -120,14 +115,14 @@ public static void tearDownAfterClass() throws Exception { volatile private boolean testQuotaNonZero = false; @Test - public void testQuota() throws IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); - HTableDescriptor table = new HTableDescriptor(tableName); - HColumnDescriptor fam = new HColumnDescriptor(famName); - fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL); - table.addFamily(fam); - utility1.getAdmin().createTable(table); - utility2.getAdmin().createTable(table); + public void testQuota(TestInfo testInfo) throws Exception { + testName = testInfo.getTestMethod().get().getName(); + final TableName tableName = TableName.valueOf(testName); + TableDescriptor tableDescriptor = + TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder + .newBuilder(famName).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).build(); + utility1.getAdmin().createTable(tableDescriptor); + utility2.getAdmin().createTable(tableDescriptor); Thread watcher = new Thread(() -> { Replication replication = (Replication) utility1.getMiniHBaseCluster().getRegionServer(0) @@ -181,8 +176,8 @@ public void testQuota() throws IOException { } watcher.interrupt(); - Assert.assertTrue(testQuotaPass); - Assert.assertTrue(testQuotaNonZero); + assertTrue(testQuotaPass); + assertTrue(testQuotaNonZero); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestHBaseInterClusterReplicationEndpointFilterEdits.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestHBaseInterClusterReplicationEndpointFilterEdits.java index 9f71bee4b079..d9c9fd114546 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestHBaseInterClusterReplicationEndpointFilterEdits.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestHBaseInterClusterReplicationEndpointFilterEdits.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -26,7 +26,6 @@ import java.util.List; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.Type; @@ -41,11 +40,10 @@ import org.apache.hadoop.hbase.wal.WAL.Entry; import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.wal.WALKeyImpl; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; @@ -53,13 +51,10 @@ * Tests {@link HBaseInterClusterReplicationEndpoint#filterNotExistColumnFamilyEdits(List)} and * {@link HBaseInterClusterReplicationEndpoint#filterNotExistTableEdits(List)} */ -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestHBaseInterClusterReplicationEndpointFilterEdits { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHBaseInterClusterReplicationEndpointFilterEdits.class); - private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static HBaseInterClusterReplicationEndpoint endpoint; @@ -73,7 +68,7 @@ public class TestHBaseInterClusterReplicationEndpointFilterEdits { private static final byte[] ROW = Bytes.toBytes("r"); private static final byte[] VALUE = Bytes.toBytes("v"); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL.startMiniCluster(); ReplicationPeer replicationPeer = mock(ReplicationPeer.class); @@ -88,7 +83,7 @@ public static void setUpBeforeClass() throws Exception { UTIL.createTable(TABLE1, FAMILY); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetaRegionReplicaReplicationEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetaRegionReplicaReplicationEndpoint.java index d3e644ff4330..ca3103b7c11a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetaRegionReplicaReplicationEndpoint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetaRegionReplicaReplicationEndpoint.java @@ -18,11 +18,11 @@ package org.apache.hadoop.hbase.replication.regionserver; import static org.apache.hadoop.hbase.client.RegionLocator.LOCATOR_META_REPLICAS_MODE; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -35,7 +35,6 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -57,15 +56,14 @@ import org.apache.hadoop.hbase.regionserver.RegionScanner; import org.apache.hadoop.hbase.replication.ReplicationPeerImpl; import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,11 +72,10 @@ * verifying async wal replication replays the edits to the secondary region in various scenarios. * @see TestRegionReplicaReplicationEndpoint */ -@Category({ LargeTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(LargeTests.TAG) public class TestMetaRegionReplicaReplicationEndpoint { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMetaRegionReplicaReplicationEndpoint.class); + private static final Logger LOG = LoggerFactory.getLogger(TestMetaRegionReplicaReplicationEndpoint.class); private static final int NB_SERVERS = 4; @@ -86,11 +83,10 @@ public class TestMetaRegionReplicaReplicationEndpoint { private int numOfMetaReplica = NB_SERVERS - 1; private static byte[] VALUE = Bytes.toBytes("value"); - @Rule - public TestName name = new TestName(); + private String methodName; - @Before - public void before() throws Exception { + @BeforeEach + public void before(TestInfo testInfo) throws Exception { Configuration conf = HTU.getConfiguration(); conf.setFloat("hbase.regionserver.logroll.multiplier", 0.0003f); conf.setInt("replication.source.size.capacity", 10240); @@ -113,9 +109,10 @@ public void before() throws Exception { HTU.waitFor(30000, () -> HTU.getMiniHBaseCluster().getRegions(TableName.META_TABLE_NAME).size() >= numOfMetaReplica); + methodName = testInfo.getTestMethod().get().getName(); } - @After + @AfterEach public void after() throws Exception { HTU.shutdownMiniCluster(); } @@ -170,8 +167,8 @@ public void testHBaseMetaReplicationSourceCreatedOnOpen() throws Exception { */ private void testHBaseMetaReplicatesOneRow(int i) throws Exception { waitForMetaReplicasToOnline(); - try (Table table = HTU.createTable(TableName.valueOf(this.name.getMethodName() + "_" + i), - HConstants.CATALOG_FAMILY)) { + try (Table table = + HTU.createTable(TableName.valueOf(methodName + "_" + i), HConstants.CATALOG_FAMILY)) { verifyReplication(TableName.META_TABLE_NAME, numOfMetaReplica, getMetaCells(table.getName())); } } @@ -188,14 +185,14 @@ private boolean isMetaRegionReplicaReplicationSource(HRegionServer hrs) { */ @Test public void testHBaseMetaReplicates() throws Exception { - try (Table table = HTU.createTable(TableName.valueOf(this.name.getMethodName() + "_0"), - HConstants.CATALOG_FAMILY, - Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length))) { + try ( + Table table = HTU.createTable(TableName.valueOf(methodName + "_0"), HConstants.CATALOG_FAMILY, + Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length))) { verifyReplication(TableName.META_TABLE_NAME, numOfMetaReplica, getMetaCells(table.getName())); } - try (Table table = HTU.createTable(TableName.valueOf(this.name.getMethodName() + "_1"), - HConstants.CATALOG_FAMILY, - Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length))) { + try ( + Table table = HTU.createTable(TableName.valueOf(methodName + "_1"), HConstants.CATALOG_FAMILY, + Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length))) { verifyReplication(TableName.META_TABLE_NAME, numOfMetaReplica, getMetaCells(table.getName())); // Try delete. HTU.deleteTableIfAny(table.getName()); @@ -577,8 +574,7 @@ private void getMetaReplicaReadRequests(final Region[] metaRegions, final long[] @Test public void testHBaseMetaReplicaGets() throws Exception { - - TableName tn = TableName.valueOf(this.name.getMethodName()); + TableName tn = TableName.valueOf(methodName); final Region[] metaRegions = getAllRegions(TableName.META_TABLE_NAME, numOfMetaReplica); long[] readReqsForMetaReplicas = new long[numOfMetaReplica]; long[] readReqsForMetaReplicasAfterGet = new long[numOfMetaReplica]; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRaceWhenCreatingReplicationSource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRaceWhenCreatingReplicationSource.java index 082b42c23b69..afa1dc56ac48 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRaceWhenCreatingReplicationSource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRaceWhenCreatingReplicationSource.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.io.UncheckedIOException; @@ -27,7 +27,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -46,22 +45,18 @@ import org.apache.hadoop.hbase.wal.WALFactory; import org.apache.hadoop.hbase.wal.WALProvider; import org.apache.hadoop.hbase.wal.WALStreamReader; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Testcase for HBASE-20624. */ -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestRaceWhenCreatingReplicationSource { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRaceWhenCreatingReplicationSource.class); - private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static String PEER_ID = "1"; @@ -82,7 +77,7 @@ public class TestRaceWhenCreatingReplicationSource { public static final class LocalReplicationEndpoint extends BaseReplicationEndpoint { - private static final UUID PEER_UUID = UTIL.getRandomUUID(); + private static final UUID PEER_UUID = HBaseTestingUtility.getRandomUUID(); @Override public UUID getPeerUUID() { @@ -134,7 +129,7 @@ public boolean canReplicateToSameCluster() { } } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, "multiwal"); // make sure that we will create a new group for the table @@ -150,7 +145,7 @@ public static void setUpBeforeClass() throws Exception { true); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshPeerWhileRegionServerRestarts.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshPeerWhileRegionServerRestarts.java index 267e85b2706d..1fa3dcf74a6b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshPeerWhileRegionServerRestarts.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshPeerWhileRegionServerRestarts.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.Future; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.master.replication.DisablePeerProcedure; import org.apache.hadoop.hbase.procedure2.Procedure; @@ -34,9 +33,8 @@ import org.apache.hadoop.hbase.replication.TestReplicationBase; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationState; @@ -44,13 +42,10 @@ * This UT is used to make sure that we will not accidentally change the way to generate online * servers. See HBASE-25774 and HBASE-25032 for more details. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRefreshPeerWhileRegionServerRestarts extends TestReplicationBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRefreshPeerWhileRegionServerRestarts.class); - private static CountDownLatch ARRIVE; private static CountDownLatch RESUME; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshRecoveredReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshRecoveredReplication.java index 93aa7130926f..775ff9ef7cef 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshRecoveredReplication.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRefreshRecoveredReplication.java @@ -17,39 +17,33 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.List; import java.util.Optional; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Put; -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.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.regionserver.HRegionServer; -import org.apache.hadoop.hbase.replication.TestReplicationBase; +import org.apache.hadoop.hbase.replication.TestReplicationBaseNoBeforeAll; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,44 +52,36 @@ /** * Testcase for HBASE-24871. */ -@Category({ ReplicationTests.class, MediumTests.class }) -public class TestRefreshRecoveredReplication extends TestReplicationBase { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRefreshRecoveredReplication.class); +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +public class TestRefreshRecoveredReplication extends TestReplicationBaseNoBeforeAll { private static final Logger LOG = LoggerFactory.getLogger(TestRefreshRecoveredReplication.class); private static final int BATCH = 50; - @Rule - public TestName name = new TestName(); - - private TableName tablename; - private Table table1; - private Table table2; - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { // NUM_SLAVES1 is presumed 2 in below. NUM_SLAVES1 = 2; + configureClusters(UTIL1, UTIL2); // replicate slowly - Configuration conf1 = UTIL1.getConfiguration(); - conf1.setInt(HConstants.REPLICATION_SOURCE_TOTAL_BUFFER_KEY, 100); - TestReplicationBase.setUpBeforeClass(); + CONF1.setInt(HConstants.REPLICATION_SOURCE_TOTAL_BUFFER_KEY, 100); + startClusters(); } - @AfterClass - public static void tearDownAfterClass() throws Exception { - TestReplicationBase.tearDownAfterClass(); - } + private String testName; + + private TableName tablename; + private Table table1; + private Table table2; - @Before - public void setup() throws Exception { + @BeforeEach + public void setup(TestInfo testInfo) throws Exception { + testName = testInfo.getTestMethod().get().getName(); setUpBase(); - tablename = TableName.valueOf(name.getMethodName()); + tablename = TableName.valueOf(testName); TableDescriptor table = TableDescriptorBuilder.newBuilder(tablename).setColumnFamily(ColumnFamilyDescriptorBuilder .newBuilder(famName).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).build(); @@ -108,7 +94,7 @@ public void setup() throws Exception { table2 = UTIL2.getConnection().getTable(tablename); } - @After + @AfterEach public void teardown() throws Exception { tearDownBase(); @@ -130,7 +116,7 @@ public void testReplicationRefreshSource() throws Exception { Optional server = rss.stream() .filter(rst -> CollectionUtils.isNotEmpty(rst.getRegionServer().getRegions(tablename))) .findAny(); - Assert.assertTrue(server.isPresent()); + assertTrue(server.isPresent()); HRegionServer otherServer = rss.get(0).getRegionServer() == server.get().getRegionServer() ? rss.get(1).getRegionServer() : rss.get(0).getRegionServer(); @@ -159,9 +145,10 @@ public void testReplicationRefreshSource() throws Exception { private int checkReplicationData() throws IOException { int count = 0; - ResultScanner results = table2.getScanner(new Scan().setCaching(BATCH)); - for (Result r : results) { - count++; + try (ResultScanner results = table2.getScanner(new Scan().setCaching(BATCH))) { + while (results.next() != null) { + count++; + } } return count; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java index 861414c3709a..5bc6267a3a67 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -41,7 +41,6 @@ import org.apache.hadoop.hbase.Cell.Type; import org.apache.hadoop.hbase.CellBuilderFactory; import org.apache.hadoop.hbase.CellBuilderType; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -73,13 +72,12 @@ import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.wal.WALKeyImpl; import org.apache.hadoop.hbase.zookeeper.ZKConfig; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,13 +88,10 @@ * Tests RegionReplicaReplicationEndpoint class by setting up region replicas and verifying async * wal replication replays the edits to the secondary region in various scenarios. */ -@Category({ FlakeyTests.class, LargeTests.class }) +@Tag(FlakeyTests.TAG) +@Tag(LargeTests.TAG) public class TestRegionReplicaReplicationEndpoint { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicaReplicationEndpoint.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionReplicaReplicationEndpoint.class); @@ -104,10 +99,9 @@ public class TestRegionReplicaReplicationEndpoint { private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); - @Rule - public TestName name = new TestName(); + private String methodName; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Configuration conf = HTU.getConfiguration(); conf.setFloat("hbase.regionserver.logroll.multiplier", 0.0003f); @@ -127,11 +121,16 @@ public static void beforeClass() throws Exception { HTU.startMiniCluster(NB_SERVERS); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HTU.shutdownMiniCluster(); } + @BeforeEach + public void before(TestInfo testInfo) { + methodName = testInfo.getTestMethod().get().getName(); + } + @Test public void testRegionReplicaReplicationPeerIsCreated() throws IOException, ReplicationException { // create a table with region replicas. Check whether the replication peer is created @@ -325,7 +324,7 @@ public void testRegionReplicaReplicationWith10Replicas() throws Exception { @Test public void testRegionReplicaWithoutMemstoreReplication() throws Exception { int regionReplication = 3; - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); HTableDescriptor htd = HTU.createTableDescriptor(tableName); htd.setRegionReplication(regionReplication); htd.setRegionMemstoreReplication(false); @@ -361,7 +360,7 @@ public void testRegionReplicaReplicationForFlushAndCompaction() throws Exception // does not test whether the replicas actually pick up flushed files and apply compaction // to their stores int regionReplication = 3; - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); HTableDescriptor htd = HTU.createTableDescriptor(tableName); htd.setRegionReplication(regionReplication); createOrEnableTableWithRetries(htd, true); @@ -408,8 +407,8 @@ public void testRegionReplicaReplicationIgnores(boolean dropTable, boolean disab // tests having edits from a disabled or dropped table is handled correctly by skipping those // entries and further edits after the edits from dropped/disabled table can be replicated // without problems. - final TableName tableName = TableName.valueOf( - name.getMethodName() + "_drop_" + dropTable + "_disabledReplication_" + disableReplication); + final TableName tableName = TableName + .valueOf(methodName + "_drop_" + dropTable + "_disabledReplication_" + disableReplication); HTableDescriptor htd = HTU.createTableDescriptor(tableName); int regionReplication = 3; htd.setRegionReplication(regionReplication); @@ -515,7 +514,7 @@ public void testRegionReplicaReplicationIgnores(boolean dropTable, boolean disab @Test public void testMetaCacheMissTriggersRefresh() throws Exception { - TableName tableName = TableName.valueOf(name.getMethodName()); + TableName tableName = TableName.valueOf(methodName); int regionReplication = 3; HTableDescriptor htd = HTU.createTableDescriptor(tableName); htd.setRegionReplication(regionReplication); @@ -555,8 +554,7 @@ public void testMetaCacheMissTriggersRefresh() throws Exception { sinkWriter.append(tableName, encodedRegionName, Bytes.toBytes("testRow"), Lists.newArrayList(entry)); - assertEquals("No entries should be skipped for valid table", 0, skippedEdits.get()); - + assertEquals(0, skippedEdits.get(), "No entries should be skipped for valid table"); } finally { table.close(); connection.close(); @@ -565,7 +563,7 @@ public void testMetaCacheMissTriggersRefresh() throws Exception { @Test public void testNullTableDescriptorDoesNotCauseNPE() throws Exception { - TableName tableName = TableName.valueOf(name.getMethodName()); + TableName tableName = TableName.valueOf(methodName); int regionReplication = 2; HTableDescriptor htd = HTU.createTableDescriptor(tableName); htd.setRegionReplication(regionReplication); @@ -618,7 +616,7 @@ public void testNullTableDescriptorDoesNotCauseNPE() throws Exception { @Test public void testMetaCacheSkippedForSingleReplicaTable() throws Exception { - TableName tableName = TableName.valueOf(name.getMethodName()); + TableName tableName = TableName.valueOf(methodName); int regionReplication = 1; HTableDescriptor htd = HTU.createTableDescriptor(tableName); htd.setRegionReplication(regionReplication); @@ -658,8 +656,7 @@ public void testMetaCacheSkippedForSingleReplicaTable() throws Exception { sinkWriter.append(tableName, encodedRegionName, Bytes.toBytes("testRow"), Lists.newArrayList(entry)); - assertEquals("No entries should be skipped for single replica table", 0, skippedEdits.get()); - + assertEquals(0, skippedEdits.get(), "No entries should be skipped for single replica table"); } finally { table.close(); connection.close(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpointNoMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpointNoMaster.java index 91e04fe6e10b..faee6fb8c4fe 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpointNoMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpointNoMaster.java @@ -19,6 +19,7 @@ import static org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster.closeRegion; import static org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster.openRegion; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,7 +30,6 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -62,14 +62,11 @@ import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.wal.WALKey; import org.apache.hadoop.hbase.wal.WALKeyImpl; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; @@ -79,13 +76,10 @@ * Tests RegionReplicaReplicationEndpoint. Unlike TestRegionReplicaReplicationEndpoint this class * contains lower level tests using callables. */ -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionReplicaReplicationEndpointNoMaster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicaReplicationEndpointNoMaster.class); - private static final int NB_SERVERS = 2; private static TableName tableName = TableName.valueOf(TestRegionReplicaReplicationEndpointNoMaster.class.getSimpleName()); @@ -101,7 +95,7 @@ public class TestRegionReplicaReplicationEndpointNoMaster { private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); private static final byte[] f = HConstants.CATALOG_FAMILY; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Configuration conf = HTU.getConfiguration(); conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_CONF_KEY, true); @@ -137,22 +131,18 @@ public static void beforeClass() throws Exception { rs1 = HTU.getMiniHBaseCluster().getRegionServer(1); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HRegionServer.TEST_SKIP_REPORTING_TRANSITION = false; table.close(); HTU.shutdownMiniCluster(); } - @Before + @BeforeEach public void before() throws Exception { entries.clear(); } - @After - public void after() throws Exception { - } - static ConcurrentLinkedQueue entries = new ConcurrentLinkedQueue<>(); public static class WALEditCopro implements WALCoprocessor, WALObserver { @@ -186,7 +176,7 @@ public void testReplayCallable() throws Exception { // load some data to primary HTU.loadNumericRows(table, f, 0, 1000); - Assert.assertEquals(1000, entries.size()); + assertEquals(1000, entries.size()); // replay the edits to the secondary using replay callable replicateUsingCallable(connection, entries); @@ -226,7 +216,7 @@ public void testReplayCallableWithRegionMove() throws Exception { // load some data to primary HTU.loadNumericRows(table, f, 0, 1000); - Assert.assertEquals(1000, entries.size()); + assertEquals(1000, entries.size()); // replay the edits to the secondary using replay callable replicateUsingCallable(connection, entries); @@ -269,7 +259,7 @@ public void testRegionReplicaReplicationEndpointReplicate() throws Exception { // load some data to primary HTU.loadNumericRows(table, f, 0, 1000); - Assert.assertEquals(1000, entries.size()); + assertEquals(1000, entries.size()); // replay the edits to the secondary using replay callable final String fakeWalGroupId = "fakeWALGroup"; replicator.replicate( diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationCompressedWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationCompressedWAL.java index 27c39cc0df2f..c57d252bd8ab 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationCompressedWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationCompressedWAL.java @@ -17,46 +17,37 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.replication.TestReplicationBase; +import org.apache.hadoop.hbase.replication.TestReplicationBaseNoBeforeAll; import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category(MediumTests.class) -public class TestReplicationCompressedWAL extends TestReplicationBase { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationCompressedWAL.class); +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +public class TestReplicationCompressedWAL extends TestReplicationBaseNoBeforeAll { static final Logger LOG = LoggerFactory.getLogger(TestReplicationCompressedWAL.class); static final int NUM_BATCHES = 20; static final int NUM_ROWS_PER_BATCH = 100; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { + configureClusters(UTIL1, UTIL2); CONF1.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true); - TestReplicationBase.setUpBeforeClass(); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - TestReplicationBase.tearDownAfterClass(); + startClusters(); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationMarker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationMarker.java index 5a30bc717112..5494e3ca1f07 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationMarker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationMarker.java @@ -25,9 +25,9 @@ import static org.apache.hadoop.hbase.replication.master.ReplicationSinkTrackerTableCreator.WAL_NAME_COLUMN; import static org.apache.hadoop.hbase.replication.regionserver.ReplicationMarkerChore.REPLICATION_MARKER_CHORE_DURATION_KEY; import static org.apache.hadoop.hbase.replication.regionserver.ReplicationMarkerChore.REPLICATION_MARKER_ENABLED_KEY; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -35,7 +35,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -53,11 +52,10 @@ import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.wal.WAL; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,11 +67,9 @@ * "hbase.regionserver.replication.sink.tracker.enabled" conf key enabled. This will persist the * marker rows coming from peer cluster to persist to REPLICATION.SINK_TRACKER table. **/ -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestReplicationMarker { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationMarker.class); private static final Logger LOG = LoggerFactory.getLogger(TestReplicationMarker.class); @@ -82,7 +78,7 @@ public class TestReplicationMarker { private static HBaseTestingUtility utility1; private static HBaseTestingUtility utility2; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { conf1 = HBaseConfiguration.create(); conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1"); @@ -111,15 +107,15 @@ public static void setUpBeforeClass() throws Exception { ReplicationSourceManager manager = utility1.getHBaseCluster().getRegionServer(0) .getReplicationSourceService().getReplicationManager(); // Wait until the peer gets established. - Waiter.waitFor(conf1, 10000, (Waiter.Predicate) () -> manager.getSources().size() == 1); + Waiter.waitFor(conf1, 10000, () -> manager.getSources().size() == 1); } private static void waitForReplicationTrackerTableCreation() { - Waiter.waitFor(conf2, 10000, (Waiter.Predicate) () -> utility2.getAdmin() - .tableExists(REPLICATION_SINK_TRACKER_TABLE_NAME)); + Waiter.waitFor(conf2, 10000, + () -> utility2.getAdmin().tableExists(REPLICATION_SINK_TRACKER_TABLE_NAME)); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { utility1.shutdownMiniCluster(); utility2.shutdownMiniCluster(); @@ -131,14 +127,14 @@ public void testReplicationMarkerRow() throws Exception { // create enough sentinel rows. Thread.sleep(5000); WAL wal1 = utility1.getHBaseCluster().getRegionServer(0).getWAL(null); - String walName1ForCluster1 = ((AbstractFSWAL) wal1).getCurrentFileName().getName(); + String walName1ForCluster1 = ((AbstractFSWAL) wal1).getCurrentFileName().getName(); String rs1Name = utility1.getHBaseCluster().getRegionServer(0).getServerName().getHostname(); // Since we sync the marker edits while appending to wal, all the edits should be visible // to Replication threads immediately. assertTrue(getReplicatedEntries() >= 5); // Force log roll. wal1.rollWriter(true); - String walName2ForCluster1 = ((AbstractFSWAL) wal1).getCurrentFileName().getName(); + String walName2ForCluster1 = ((AbstractFSWAL) wal1).getCurrentFileName().getName(); Connection connection2 = utility2.getMiniHBaseCluster().getRegionServer(0).getConnection(); // Sleep for 5 more seconds to get marker rows with new wal name. Thread.sleep(5000); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSink.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSink.java index 3c48c336ef96..108f13f81a85 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSink.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSink.java @@ -17,7 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; @@ -37,7 +38,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -62,13 +62,11 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.HFileTestUtil; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,13 +78,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALKey; -@Category({ ReplicationTests.class, LargeTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(LargeTests.TAG) public class TestReplicationSink { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSink.class); - private static final Logger LOG = LoggerFactory.getLogger(TestReplicationSink.class); private static final int BATCH_SIZE = 10; @@ -122,10 +117,7 @@ public void stop(String why) { protected static String hfileArchiveDir; protected static String replicationClusterId; - /** - * @throws java.lang.Exception - */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().set("hbase.replication.source.fs.conf.provider", TestSourceFSConfigurationProvider.class.getCanonicalName()); @@ -141,19 +133,13 @@ public static void setUpBeforeClass() throws Exception { replicationClusterId = "12345"; } - /** - * @throws java.lang.Exception - */ - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { STOPPABLE.stop("Shutting down"); TEST_UTIL.shutdownMiniCluster(); } - /** - * @throws java.lang.Exception - */ - @Before + @BeforeEach public void setUp() throws Exception { table1 = TEST_UTIL.deleteTableData(TABLE_NAME1); table2 = TEST_UTIL.deleteTableData(TABLE_NAME2); @@ -319,7 +305,7 @@ public void testRethrowRetriesExhaustedWithDetailsException() throws Exception { try { SINK.replicateEntries(entries, CellUtil.createCellScanner(cells.iterator()), replicationClusterId, baseNamespaceDir, hfileArchiveDir); - Assert.fail("Should re-throw TableNotFoundException."); + fail("Should re-throw TableNotFoundException."); } catch (TableNotFoundException e) { } entries.clear(); @@ -333,7 +319,7 @@ public void testRethrowRetriesExhaustedWithDetailsException() throws Exception { try { SINK.replicateEntries(entries, CellUtil.createCellScanner(cells.iterator()), replicationClusterId, baseNamespaceDir, hfileArchiveDir); - Assert.fail("Should re-throw RetriesExhaustedException."); + fail("Should re-throw RetriesExhaustedException."); } catch (RetriesExhaustedException e) { } finally { admin.enableTable(TABLE_NAME1); @@ -437,7 +423,7 @@ public void testFailedReplicationSinkMetrics() throws IOException { try { SINK.replicateEntries(entries, CellUtil.createCellScanner(cells.iterator()), replicationClusterId, baseNamespaceDir, hfileArchiveDir); - Assert.fail("Should re-throw ArrayIndexOutOfBoundsException."); + fail("Should re-throw ArrayIndexOutOfBoundsException."); } catch (ArrayIndexOutOfBoundsException e) { errorCount++; assertEquals(initialFailedBatches + errorCount, SINK.getSinkMetrics().getFailedBatches()); @@ -452,7 +438,7 @@ public void testFailedReplicationSinkMetrics() throws IOException { try { SINK.replicateEntries(entries, CellUtil.createCellScanner(cells.iterator()), replicationClusterId, baseNamespaceDir, hfileArchiveDir); - Assert.fail("Should re-throw TableNotFoundException."); + fail("Should re-throw TableNotFoundException."); } catch (TableNotFoundException e) { errorCount++; assertEquals(initialFailedBatches + errorCount, SINK.getSinkMetrics().getFailedBatches()); @@ -470,7 +456,7 @@ public void testFailedReplicationSinkMetrics() throws IOException { try { SINK.replicateEntries(entries, CellUtil.createCellScanner(cells.iterator()), replicationClusterId, baseNamespaceDir, hfileArchiveDir); - Assert.fail("Should re-throw IOException."); + fail("Should re-throw IOException."); } catch (IOException e) { errorCount++; assertEquals(initialFailedBatches + errorCount, SINK.getSinkMetrics().getFailedBatches()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSinkManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSinkManager.java index 8cf8d12c250f..ab82f189af84 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSinkManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSinkManager.java @@ -17,34 +17,29 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import java.util.List; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.replication.HBaseReplicationEndpoint; import org.apache.hadoop.hbase.replication.regionserver.ReplicationSinkManager.SinkPeer; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService; -@Category({ ReplicationTests.class, SmallTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(SmallTests.TAG) public class TestReplicationSinkManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSinkManager.class); - private static final String PEER_CLUSTER_ID = "PEER_CLUSTER_ID"; private ReplicationSinkManager sinkManager; @@ -74,7 +69,7 @@ public List getRegionServers() { } } - @Before + @BeforeEach public void setUp() { this.replicationEndpoint = new SetServersHBaseReplicationEndpoint(); sinkManager = new ReplicationSinkManager(mock(ClusterConnection.class), PEER_CLUSTER_ID, diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSource.java index b12c8eb73890..f57efc0459fb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSource.java @@ -18,11 +18,11 @@ package org.apache.hadoop.hbase.replication.regionserver; import static org.apache.hadoop.hbase.wal.AbstractFSWALProvider.META_WAL_PROVIDER_ID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -41,7 +41,6 @@ import org.apache.hadoop.hbase.CellBuilderFactory; import org.apache.hadoop.hbase.CellBuilderType; import org.apache.hadoop.hbase.CompatibilitySingletonFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -70,22 +69,18 @@ import org.apache.hadoop.hbase.wal.WALKeyImpl; import org.apache.hadoop.hbase.wal.WALProvider; import org.apache.hadoop.hbase.wal.WALStreamReader; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestReplicationSource { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSource.class); - private static final Logger LOG = LoggerFactory.getLogger(TestReplicationSource.class); private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private final static HBaseTestingUtility TEST_UTIL_PEER = new HBaseTestingUtility(); @@ -94,7 +89,7 @@ public class TestReplicationSource { private static Path logDir; private static Configuration conf = TEST_UTIL.getConfiguration(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniDFSCluster(1); FS = TEST_UTIL.getDFSCluster().getFileSystem(); @@ -109,7 +104,7 @@ public static void setUpBeforeClass() throws Exception { } } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL_PEER.shutdownMiniHBaseCluster(); TEST_UTIL.shutdownMiniHBaseCluster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceLogQueue.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceLogQueue.java index 9d101b97217e..4608100b42ca 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceLogQueue.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceLogQueue.java @@ -17,30 +17,25 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -@Category({ SmallTests.class, ReplicationTests.class }) +@Tag(SmallTests.TAG) +@Tag(ReplicationTests.TAG) public class TestReplicationSourceLogQueue { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSourceLogQueue.class); - - /* + /** * Testing enqueue and dequeuing of wal and check age of oldest wal. */ @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java index 2b5c22ced148..8d8d7ac8f795 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.lang.reflect.Field; @@ -46,7 +46,6 @@ import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.ClusterId; import org.apache.hadoop.hbase.CoordinatedStateManager; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; @@ -73,8 +72,6 @@ import org.apache.hadoop.hbase.replication.ReplicationSourceDummy; import org.apache.hadoop.hbase.replication.ReplicationStorageFactory; import org.apache.hadoop.hbase.replication.ZKReplicationPeerStorage; -import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; @@ -87,14 +84,11 @@ import org.apache.hadoop.hbase.zookeeper.ZKClusterId; import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,13 +103,8 @@ * An abstract class that tests ReplicationSourceManager. Classes that extend this class should set * up the proper config for this class and initialize the proper cluster using HBaseTestingUtility. */ -@Category({ ReplicationTests.class, MediumTests.class }) public abstract class TestReplicationSourceManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSourceManager.class); - protected static final Logger LOG = LoggerFactory.getLogger(TestReplicationSourceManager.class); protected static Configuration conf; @@ -220,7 +209,7 @@ private static ReplicationSourceManager getManagerFromCluster() { .map(Replication::getReplicationManager).get(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { if (manager != null) { manager.join(); @@ -228,23 +217,20 @@ public static void tearDownAfterClass() throws Exception { utility.shutdownMiniCluster(); } - @Rule - public TestName testName = new TestName(); - private void cleanLogDir() throws IOException { fs.delete(logDir, true); fs.delete(oldLogDir, true); } - @Before - public void setUp() throws Exception { - LOG.info("Start " + testName.getMethodName()); + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { + LOG.info("Start " + testInfo.getTestMethod().get().getName()); cleanLogDir(); } - @After - public void tearDown() throws Exception { - LOG.info("End " + testName.getMethodName()); + @AfterEach + public void tearDown(TestInfo testInfo) throws Exception { + LOG.info("End " + testInfo.getTestMethod().get().getName()); cleanLogDir(); List ids = manager.getSources().stream().map(ReplicationSourceInterface::getPeerId) .collect(Collectors.toList()); @@ -433,8 +419,8 @@ public void testBulkLoadWALEditsWithoutBulkLoadReplicationEnabled() throws Excep ReplicationSourceWALActionListener.scopeWALEdits(logKey, logEdit, conf); // 4. Assert that no bulk load entry scopes are added if bulk load hfile replication is disabled - assertNull("No bulk load entries scope should be added if bulk load replication is disabled.", - logKey.getReplicationScopes()); + assertNull(logKey.getReplicationScopes(), + "No bulk load entries scope should be added if bulk load replication is disabled."); } @Test @@ -453,11 +439,11 @@ public void testBulkLoadWALEdits() throws Exception { NavigableMap scopes = logKey.getReplicationScopes(); // Assert family with replication scope global is present in the key scopes - assertTrue("This family scope is set to global, should be part of replication key scopes.", - scopes.containsKey(f1)); + assertTrue(scopes.containsKey(f1), + "This family scope is set to global, should be part of replication key scopes."); // Assert family with replication scope local is not present in the key scopes - assertFalse("This family scope is set to local, should not be part of replication key scopes", - scopes.containsKey(f2)); + assertFalse(scopes.containsKey(f2), + "This family scope is set to local, should not be part of replication key scopes"); } /** @@ -697,22 +683,21 @@ public void testPeerConfigurationOverridesPropagate() throws Exception { ReplicationSource source = (ReplicationSource) manager.getSources().stream() .filter(s -> s.getPeerId().equals(peerId)).findFirst().orElse(null); - assertNotNull("Source should be created for peer", source); + assertNotNull(source, "Source should be created for peer"); - assertEquals("ReplicationSource should use peer config override for sleepForRetries", - peerSleepOverride, source.getSleepForRetries()); + assertEquals(peerSleepOverride, source.getSleepForRetries(), + "ReplicationSource should use peer config override for sleepForRetries"); Map workers = source.workerThreads; if (!workers.isEmpty()) { ReplicationSourceShipper shipper = workers.values().iterator().next(); - assertEquals("ReplicationSourceShipper should use peer config override for sleepForRetries", - peerSleepOverride, shipper.getSleepForRetries()); + assertEquals(peerSleepOverride, shipper.getSleepForRetries(), + "ReplicationSourceShipper should use peer config override for sleepForRetries"); ReplicationSourceWALReader reader = shipper.entryReader; if (reader != null) { - assertEquals( - "ReplicationSourceWALReader should use peer config override for sleepForRetries", - peerSleepOverride, reader.getSleepForRetries()); + assertEquals(peerSleepOverride, reader.getSleepForRetries(), + "ReplicationSourceWALReader should use peer config override for sleepForRetries"); } } } finally { @@ -770,16 +755,16 @@ public void testPeerConfigurationIsolation() throws Exception { // Verify peer with override uses the override value ReplicationSource sourceWithOverride = (ReplicationSource) manager.getSources().stream() .filter(s -> s.getPeerId().equals(peerIdWithOverride)).findFirst().orElse(null); - assertNotNull("Source with override should be created", sourceWithOverride); - assertEquals("Peer with override should use override value", peerSleepOverride, - sourceWithOverride.getSleepForRetries()); + assertNotNull(sourceWithOverride, "Source with override should be created"); + assertEquals(peerSleepOverride, sourceWithOverride.getSleepForRetries(), + "Peer with override should use override value"); // Verify peer without override uses global config ReplicationSource sourceWithoutOverride = (ReplicationSource) manager.getSources().stream() .filter(s -> s.getPeerId().equals(peerIdWithoutOverride)).findFirst().orElse(null); - assertNotNull("Source without override should be created", sourceWithoutOverride); - assertEquals("Peer without override should use global config", globalSleepValue, - sourceWithoutOverride.getSleepForRetries()); + assertNotNull(sourceWithoutOverride, "Source without override should be created"); + assertEquals(globalSleepValue, sourceWithoutOverride.getSleepForRetries(), + "Peer without override should use global config"); } finally { conf.set("replication.replicationsource.implementation", replicationSourceImplName); removePeerAndWait(peerIdWithOverride); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerJoin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerJoin.java index d7d23783eacb..3362a223fbd6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerJoin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerJoin.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Optional; import java.util.stream.Stream; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -31,40 +30,34 @@ import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.regionserver.HRegionServer; -import org.apache.hadoop.hbase.replication.TestReplicationBase; +import org.apache.hadoop.hbase.replication.TestReplicationBaseNoBeforeAll; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; -@Category({ ReplicationTests.class, MediumTests.class }) -public class TestReplicationSourceManagerJoin extends TestReplicationBase { +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +public class TestReplicationSourceManagerJoin extends TestReplicationBaseNoBeforeAll { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSourceManagerJoin.class); - - @Rule - public TestName testName = new TestName(); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { // NUM_SLAVES1 is presumed 2 in below. NUM_SLAVES1 = 2; - TestReplicationBase.setUpBeforeClass(); + configureClusters(UTIL1, UTIL2); + startClusters(); } @Test - public void testReplicationSourcesTerminate() throws Exception { + public void testReplicationSourcesTerminate(TestInfo testInfo) throws Exception { + String testName = testInfo.getTestMethod().get().getName(); // Create table in source cluster only, let TableNotFoundException block peer to avoid // recovered source end. - TableName tableName = TableName.valueOf(testName.getMethodName()); + TableName tableName = TableName.valueOf(testName); TableDescriptor td = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName) .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerZkImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerZkImpl.java index b8a148819625..3dfa2ebca80b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerZkImpl.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManagerZkImpl.java @@ -17,10 +17,9 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.Server; @@ -31,24 +30,20 @@ import org.apache.hadoop.hbase.replication.ReplicationStorageFactory; import org.apache.hadoop.hbase.testclassification.MediumTests; 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; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Tests the ReplicationSourceManager with ReplicationQueueZkImpl's and * ReplicationQueuesClientZkImpl. Also includes extra tests outside of those in * TestReplicationSourceManager that test ReplicationQueueZkImpl-specific behaviors. */ -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestReplicationSourceManagerZkImpl extends TestReplicationSourceManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationSourceManagerZkImpl.class); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { conf = HBaseConfiguration.create(); conf.set("replication.replicationsource.implementation", diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java index ce0f7a351e8a..078c3bc2d84b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java @@ -17,25 +17,20 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ ReplicationTests.class, SmallTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(SmallTests.TAG) public class TestReplicationThrottler { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationThrottler.class); - private static final Logger LOG = LoggerFactory.getLogger(TestReplicationThrottler.class); /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationValueCompressedWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationValueCompressedWAL.java index 03b83964dccf..436e745d2cda 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationValueCompressedWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationValueCompressedWAL.java @@ -17,38 +17,29 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.regionserver.wal.CompressionContext; -import org.apache.hadoop.hbase.replication.TestReplicationBase; +import org.apache.hadoop.hbase.replication.TestReplicationBaseNoBeforeAll; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.apache.hadoop.hbase.testclassification.ReplicationTests; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category(MediumTests.class) -public class TestReplicationValueCompressedWAL extends TestReplicationBase { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationValueCompressedWAL.class); +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +public class TestReplicationValueCompressedWAL extends TestReplicationBaseNoBeforeAll { static final Logger LOG = LoggerFactory.getLogger(TestReplicationValueCompressedWAL.class); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { + configureClusters(UTIL1, UTIL2); CONF1.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true); CONF1.setBoolean(CompressionContext.ENABLE_WAL_VALUE_COMPRESSION, true); - TestReplicationBase.setUpBeforeClass(); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - TestReplicationBase.tearDownAfterClass(); + startClusters(); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java index 4af4b219a9ad..dca7b2bf5216 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java @@ -17,50 +17,46 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; -import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.ipc.RpcServer; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; -import org.apache.hadoop.hbase.replication.TestReplicationBase; +import org.apache.hadoop.hbase.replication.TestReplicationBaseNoBeforeAll; import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.wal.WAL.Entry; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException; -@Category(MediumTests.class) -public class TestReplicator extends TestReplicationBase { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicator.class); +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) +public class TestReplicator extends TestReplicationBaseNoBeforeAll { static final Logger LOG = LoggerFactory.getLogger(TestReplicator.class); static final int NUM_ROWS = 10; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { + configureClusters(UTIL1, UTIL2); // Set RPC size limit to 10kb (will be applied to both source and sink clusters) CONF1.setInt(RpcServer.MAX_REQUEST_SIZE, 1024 * 10); - TestReplicationBase.setUpBeforeClass(); + startClusters(); } @Test @@ -105,9 +101,9 @@ public String explainFailure() throws Exception { } }); - assertEquals("We sent an incorrect number of batches", NUM_ROWS, - ReplicationEndpointForTest.getBatchCount()); - assertEquals("We did not replicate enough rows", NUM_ROWS, UTIL2.countRows(htable2)); + assertEquals(NUM_ROWS, ReplicationEndpointForTest.getBatchCount(), + "We sent an incorrect number of batches"); + assertEquals(NUM_ROWS, UTIL2.countRows(htable2), "We did not replicate enough rows"); } finally { admin.removePeer("testReplicatorBatching"); } @@ -155,19 +151,14 @@ public String explainFailure() throws Exception { } }); - assertEquals("We did not replicate enough rows", NUM_ROWS, UTIL2.countRows(htable2)); + assertEquals(NUM_ROWS, UTIL2.countRows(htable2), "We did not replicate enough rows"); } finally { admin.removePeer("testReplicatorWithErrors"); } } - @AfterClass - public static void tearDownAfterClass() throws Exception { - TestReplicationBase.tearDownAfterClass(); - } - private void truncateTable(HBaseTestingUtility util, TableName tablename) throws IOException { - HBaseAdmin admin = util.getHBaseAdmin(); + Admin admin = util.getAdmin(); admin.disableTable(tableName); admin.truncateTable(tablename, false); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationChecker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationChecker.java index 54a67ce4d32d..ebd2362f1783 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationChecker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationChecker.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -33,7 +33,6 @@ import org.apache.hadoop.hbase.Cell.Type; import org.apache.hadoop.hbase.CellBuilderFactory; import org.apache.hadoop.hbase.CellBuilderType; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; @@ -54,26 +53,21 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.wal.WAL.Entry; import org.apache.hadoop.hbase.wal.WALKeyImpl; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestSerialReplicationChecker { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSerialReplicationChecker.class); - private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static String PEER_ID = "1"; @@ -86,12 +80,11 @@ public class TestSerialReplicationChecker { private SerialReplicationChecker checker; - @Rule - public final TestName name = new TestName(); + private String testName; private TableName tableName; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL.startMiniCluster(1); QUEUE_STORAGE = ReplicationStorageFactory.getReplicationQueueStorage(UTIL.getZooKeeperWatcher(), @@ -100,13 +93,14 @@ public static void setUpBeforeClass() throws Exception { WAL_FILE_NAME); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } - @Before - public void setUp() throws IOException { + @BeforeEach + public void setUp(TestInfo testInfo) throws IOException { + testName = testInfo.getTestMethod().get().getName(); ReplicationSource source = mock(ReplicationSource.class); when(source.getPeerId()).thenReturn(PEER_ID); when(source.getReplicationQueueStorage()).thenReturn(QUEUE_STORAGE); @@ -124,7 +118,7 @@ public Table answer(InvocationOnMock invocation) throws Throwable { when(server.getConnection()).thenReturn(conn); when(source.getServer()).thenReturn(server); checker = new SerialReplicationChecker(UTIL.getConfiguration(), source); - tableName = TableName.valueOf(name.getMethodName()); + tableName = TableName.valueOf(testName); } private Entry createEntry(RegionInfo region, long seqId) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationEndpoint.java index 7596ca6647af..3598e1412c29 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationEndpoint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestSerialReplicationEndpoint.java @@ -17,6 +17,9 @@ */ package org.apache.hadoop.hbase.replication.regionserver; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -26,7 +29,6 @@ import java.util.concurrent.LinkedBlockingQueue; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -46,29 +48,24 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.wal.WAL.Entry; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hbase.thirdparty.com.google.common.io.Closeables; -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestSerialReplicationEndpoint { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSerialReplicationEndpoint.class); - private static HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static Configuration CONF; private static Connection CONN; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(); CONF = UTIL.getConfiguration(); @@ -76,7 +73,7 @@ public static void setUp() throws Exception { CONN = UTIL.getConnection(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { Closeables.close(CONN, true); UTIL.shutdownMiniCluster(); @@ -118,7 +115,7 @@ private void testHBaseReplicationEndpoint(String tableNameStr, String peerId, bo Waiter.waitFor(CONF, 60000, () -> TestEndpoint.getEntries().size() >= cellNum); int index = 0; - Assert.assertEquals(TestEndpoint.getEntries().size(), cellNum); + assertEquals(cellNum, TestEndpoint.getEntries().size()); if (!isSerial) { Collections.sort(TestEndpoint.getEntries(), (a, b) -> { long seqA = a.getKey().getSequenceId(); @@ -127,15 +124,14 @@ private void testHBaseReplicationEndpoint(String tableNameStr, String peerId, bo }); } for (Entry entry : TestEndpoint.getEntries()) { - Assert.assertEquals(entry.getKey().getTableName(), tableName); - Assert.assertEquals(entry.getEdit().getCells().size(), 1); + assertEquals(tableName, entry.getKey().getTableName()); + assertEquals(1, entry.getEdit().getCells().size()); Cell cell = entry.getEdit().getCells().get(0); - Assert.assertArrayEquals( - Bytes.copy(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()), - Bytes.toBytes(index)); + assertArrayEquals(Bytes.toBytes(index), + Bytes.copy(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); index++; } - Assert.assertEquals(index, cellNum); + assertEquals(cellNum, index); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java index 49689ddc8f5b..bab40044d53a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntrySinkFilter.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -26,7 +26,6 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; @@ -34,11 +33,9 @@ import org.apache.hadoop.hbase.CellBuilderFactory; import org.apache.hadoop.hbase.CellBuilderType; import org.apache.hadoop.hbase.CellScanner; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.AdvancedScanResultConsumer; import org.apache.hadoop.hbase.client.AsyncAdminBuilder; @@ -59,13 +56,9 @@ import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.apache.hbase.thirdparty.com.google.protobuf.ByteString; @@ -74,38 +67,14 @@ /** * Simple test of sink-side wal entry filter facility. */ -@Category({ ReplicationTests.class, SmallTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(SmallTests.TAG) public class TestWALEntrySinkFilter { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestWALEntrySinkFilter.class); - - private static final Logger LOG = LoggerFactory.getLogger(TestWALEntrySinkFilter.class); - @Rule - public TestName name = new TestName(); static final int BOUNDARY = 5; static final AtomicInteger UNFILTERED = new AtomicInteger(); static final AtomicInteger FILTERED = new AtomicInteger(); - /** - * Implemetentation of Stoppable to pass into ReplicationSink. - */ - private static Stoppable STOPPABLE = new Stoppable() { - private final AtomicBoolean stop = new AtomicBoolean(false); - - @Override - public boolean isStopped() { - return this.stop.get(); - } - - @Override - public void stop(String why) { - LOG.info("STOPPING BECAUSE: " + why); - this.stop.set(true); - } - }; - /** * Test filter. Filter will filter out any write time that is <= 5 (BOUNDARY). We count how many * items we filter out and we count how many cells make it through for distribution way down below @@ -113,7 +82,8 @@ public void stop(String why) { * our counting Table. */ @Test - public void testWALEntryFilter() throws IOException { + public void testWALEntryFilter(TestInfo testInfo) throws IOException { + String testName = testInfo.getTestMethod().get().getName(); Configuration conf = HBaseConfiguration.create(); // Make it so our filter is instantiated on construction of ReplicationSink. conf.setClass(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, @@ -128,8 +98,7 @@ public void testWALEntryFilter() throws IOException { new ArrayList<>(); AdminProtos.WALEntry.Builder entryBuilder = AdminProtos.WALEntry.newBuilder(); // Need a tablename. - ByteString tableName = - ByteString.copyFromUtf8(TableName.valueOf(this.name.getMethodName()).toString()); + ByteString tableName = ByteString.copyFromUtf8(TableName.valueOf(testName).toString()); // Add WALEdit Cells to Cells List. The way edits arrive at the sink is with protos // describing the edit with all Cells from all edits aggregated in a single CellScanner. final List cells = new ArrayList<>(); @@ -294,7 +263,7 @@ public CompletableFuture> batchAll(List actions) { for (Row action : actions) { // Row is the index of the loop above where we make WALEntry and Cells. int row = Bytes.toInt(action.getRow()); - assertTrue("" + row, row > BOUNDARY); + assertTrue(row > BOUNDARY, "" + row); UNFILTERED.incrementAndGet(); list.add(null); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamCompressionReset.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamCompressionReset.java index b687aaeee6ca..be5b6396d086 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamCompressionReset.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamCompressionReset.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -34,7 +34,6 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellBuilderFactory; import org.apache.hadoop.hbase.CellBuilderType; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -52,11 +51,10 @@ import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hbase.wal.WALKeyImpl; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.common.io.ByteStreams; @@ -66,13 +64,10 @@ * This is used to confirm that we can work well when hitting EOFException in the middle when * reading a WAL entry, when compression is enabled. See HBASE-27621 for more details. */ -@Category({ ReplicationTests.class, MediumTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(MediumTests.TAG) public class TestWALEntryStreamCompressionReset { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestWALEntryStreamCompressionReset.class); - private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static TableName TABLE_NAME = TableName.valueOf("reset"); @@ -134,7 +129,7 @@ private static Pair generateWAL() throws Exception { return Pair.newPair(path, offset); } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { Configuration conf = UTIL.getConfiguration(); FS = UTIL.getTestFileSystem(); @@ -163,7 +158,7 @@ public static void setUp() throws Exception { READER = new ReplicationSourceWALReader(FS, conf, LOG_QUEUE, 0, e -> e, SOURCE, GROUP_ID); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { READER.setReaderRunning(false); READER.join(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCounts.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCounts.java index 88f4f4539b23..41497c3f88f6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCounts.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCounts.java @@ -17,53 +17,38 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.HasNext; -import org.junit.Before; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestTemplate; /** * Try out different combinations of row count and KeyValue count */ public abstract class TestWALEntryStreamDifferentCounts extends WALEntryStreamTestBase { - @Parameter(0) - public int nbRows; + protected int nbRows; + protected int walEditKVs; + protected boolean isCompressionEnabled; - @Parameter(1) - public int walEditKVs; - - @Parameter(2) - public boolean isCompressionEnabled; - - @Parameters(name = "{index}: nbRows={0}, walEditKVs={1}, isCompressionEnabled={2}") - public static Iterable data() { - List params = new ArrayList<>(); - for (int nbRows : new int[] { 1500, 60000 }) { - for (int walEditKVs : new int[] { 1, 100 }) { - for (boolean isCompressionEnabled : new boolean[] { false, true }) { - params.add(new Object[] { nbRows, walEditKVs, isCompressionEnabled }); - } - } - } - return params; + protected TestWALEntryStreamDifferentCounts(int nbRows, int walEditKVs, + boolean isCompressionEnabled) { + this.nbRows = nbRows; + this.walEditKVs = walEditKVs; + this.isCompressionEnabled = isCompressionEnabled; } - @Before + @BeforeEach public void setUp() throws IOException { CONF.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, isCompressionEnabled); initWAL(); } - @Test + @TestTemplate public void testDifferentCounts() throws Exception { mvcc.advanceTo(1); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsAsyncFSWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsAsyncFSWAL.java index 9dcb8a344b6d..13bab98c1877 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsAsyncFSWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsAsyncFSWAL.java @@ -17,27 +17,43 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.apache.hadoop.hbase.wal.AsyncFSWALProvider; import org.apache.hadoop.hbase.wal.WALFactory; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) -@Category({ ReplicationTests.class, LargeTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(LargeTests.TAG) +@HBaseParameterizedTestTemplate( + name = "{index}: nbRows={0}, walEditKVs={1}, isCompressionEnabled={2}") public class TestWALEntryStreamDifferentCountsAsyncFSWAL extends TestWALEntryStreamDifferentCounts { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestWALEntryStreamDifferentCountsAsyncFSWAL.class); + public TestWALEntryStreamDifferentCountsAsyncFSWAL(int nbRows, int walEditKVs, + boolean isCompressionEnabled) { + super(nbRows, walEditKVs, isCompressionEnabled); + } + + public static Stream parameters() { + List params = new ArrayList<>(); + for (int nbRows : new int[] { 1500, 60000 }) { + for (int walEditKVs : new int[] { 1, 100 }) { + for (boolean isCompressionEnabled : new boolean[] { false, true }) { + params.add(Arguments.of(nbRows, walEditKVs, isCompressionEnabled)); + } + } + } + return params.stream(); + } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, AsyncFSWALProvider.class, AbstractFSWALProvider.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsFSHLog.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsFSHLog.java index fb7c3d555d8e..8c4f9eb46a47 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsFSHLog.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestWALEntryStreamDifferentCountsFSHLog.java @@ -17,27 +17,43 @@ */ package org.apache.hadoop.hbase.replication.regionserver; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.apache.hadoop.hbase.wal.FSHLogProvider; import org.apache.hadoop.hbase.wal.WALFactory; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) -@Category({ ReplicationTests.class, LargeTests.class }) +@Tag(ReplicationTests.TAG) +@Tag(LargeTests.TAG) +@HBaseParameterizedTestTemplate( + name = "{index}: nbRows={0}, walEditKVs={1}, isCompressionEnabled={2}") public class TestWALEntryStreamDifferentCountsFSHLog extends TestWALEntryStreamDifferentCounts { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestWALEntryStreamDifferentCountsFSHLog.class); + public TestWALEntryStreamDifferentCountsFSHLog(int nbRows, int walEditKVs, + boolean isCompressionEnabled) { + super(nbRows, walEditKVs, isCompressionEnabled); + } + + public static Stream parameters() { + List params = new ArrayList<>(); + for (int nbRows : new int[] { 1500, 60000 }) { + for (int walEditKVs : new int[] { 1, 100 }) { + for (boolean isCompressionEnabled : new boolean[] { false, true }) { + params.add(Arguments.of(nbRows, walEditKVs, isCompressionEnabled)); + } + } + } + return params.stream(); + } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, FSHLogProvider.class, AbstractFSWALProvider.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/WALEntryStreamTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/WALEntryStreamTestBase.java index b21675df2e4d..8bd8e42cd97d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/WALEntryStreamTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/WALEntryStreamTestBase.java @@ -41,10 +41,10 @@ import org.apache.hadoop.hbase.wal.WALKeyImpl; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Rule; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; import org.apache.hbase.thirdparty.com.google.common.io.Closeables; @@ -124,11 +124,14 @@ public void preLogRoll(Path oldPath, Path newPath) { protected WAL log; protected ReplicationSourceLogQueue logQueue; protected PathWatcher pathWatcher; - - @Rule - public TestName tn = new TestName(); + protected String testName; protected final MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl(); + @BeforeEach + public void setUp(TestInfo testInfo) { + testName = testInfo.getTestMethod().get().getName(); + } + protected static void startCluster() throws Exception { CONF = TEST_UTIL.getConfiguration(); CONF.setLong("replication.source.sleepforretries", 10); @@ -138,7 +141,7 @@ protected static void startCluster() throws Exception { fs = cluster.getFileSystem(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -150,12 +153,12 @@ protected void initWAL() throws IOException { metricsSource.clear(); logQueue = new ReplicationSourceLogQueue(CONF, metricsSource, source); pathWatcher = new PathWatcher(); - final WALFactory wals = new WALFactory(CONF, tn.getMethodName().replaceAll("[\\[:]", "_")); + final WALFactory wals = new WALFactory(CONF, testName.replaceAll("[\\[:]", "_")); wals.getWALProvider().addWALActionsListener(pathWatcher); log = wals.getWAL(info); } - @After + @AfterEach public void tearDown() throws Exception { Closeables.close(log, true); }