Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.coprocessor;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -32,7 +32,6 @@
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValueUtil;
Expand All @@ -53,25 +52,17 @@
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WALEdit;
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;

@Category({ CoprocessorTests.class, MediumTests.class })
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;

@Tag(CoprocessorTests.TAG)
@Tag(MediumTests.TAG)
public class TestPassCustomCellViaRegionObserver {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestPassCustomCellViaRegionObserver.class);

@Rule
public TestName testName = new TestName();

private TableName tableName;
private Table table = null;

Expand All @@ -85,22 +76,22 @@ public class TestPassCustomCellViaRegionObserver {

private static final byte[] QUALIFIER_FROM_CP = Bytes.toBytes("QUALIFIER_FROM_CP");

@BeforeClass
@BeforeAll
public static void setupBeforeClass() throws Exception {
// small retry number can speed up the failed tests.
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
UTIL.startMiniCluster();
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}

@Before
public void clearTable() throws IOException {
@BeforeEach
public void clearTable(TestInfo testInfo) throws IOException {
RegionObserverImpl.COUNT.set(0);
tableName = TableName.valueOf(testName.getMethodName());
tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
if (table != null) {
table.close();
}
Expand Down Expand Up @@ -149,8 +140,8 @@ public void testMutation() throws Exception {
Delete delete = new Delete(ROW);
delete.addColumns(FAMILY, QUALIFIER);
table.delete(delete);
assertTrue(Arrays.asList(table.get(new Get(ROW)).rawCells()).toString(),
table.get(new Get(ROW)).isEmpty());
assertTrue(table.get(new Get(ROW)).isEmpty(),
Arrays.asList(table.get(new Get(ROW)).rawCells()).toString());
assertObserverHasExecuted();

assertTrue(table.checkAndPut(ROW, FAMILY, QUALIFIER, null, put));
Expand Down Expand Up @@ -186,21 +177,21 @@ private static void assertObserverHasExecuted() {
private static void assertResult(Result result, byte[] expectedValue) {
assertFalse(result.isEmpty());
for (Cell c : result.rawCells()) {
assertTrue(c.toString(), Bytes.equals(ROW, CellUtil.cloneRow(c)));
assertTrue(c.toString(), Bytes.equals(FAMILY, CellUtil.cloneFamily(c)));
assertTrue(c.toString(), Bytes.equals(expectedValue, CellUtil.cloneValue(c)));
assertTrue(Bytes.equals(ROW, CellUtil.cloneRow(c)), c.toString());
assertTrue(Bytes.equals(FAMILY, CellUtil.cloneFamily(c)), c.toString());
assertTrue(Bytes.equals(expectedValue, CellUtil.cloneValue(c)), c.toString());
}
}

private static void assertResult(Result result, byte[] expectedValue, byte[] expectedFromCp) {
assertFalse(result.isEmpty());
for (Cell c : result.rawCells()) {
assertTrue(c.toString(), Bytes.equals(ROW, CellUtil.cloneRow(c)));
assertTrue(c.toString(), Bytes.equals(FAMILY, CellUtil.cloneFamily(c)));
assertTrue(Bytes.equals(ROW, CellUtil.cloneRow(c)), c.toString());
assertTrue(Bytes.equals(FAMILY, CellUtil.cloneFamily(c)), c.toString());
if (Bytes.equals(QUALIFIER, CellUtil.cloneQualifier(c))) {
assertTrue(c.toString(), Bytes.equals(expectedValue, CellUtil.cloneValue(c)));
assertTrue(Bytes.equals(expectedValue, CellUtil.cloneValue(c)), c.toString());
} else if (Bytes.equals(QUALIFIER_FROM_CP, CellUtil.cloneQualifier(c))) {
assertTrue(c.toString(), Bytes.equals(expectedFromCp, CellUtil.cloneValue(c)));
assertTrue(Bytes.equals(expectedFromCp, CellUtil.cloneValue(c)), c.toString());
} else {
fail("No valid qualifier");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNameTestExtension;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.master.RackManager;
Expand All @@ -44,11 +45,10 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Triple;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.rules.TestName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mockito;

import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
Expand All @@ -65,8 +65,8 @@ public class TestFavoredNodeAssignmentHelper {
// Some tests have randomness, so we run them multiple times
private static final int MAX_ATTEMPTS = 100;

@Rule
public TestName name = new TestName();
@RegisterExtension
private final TableNameTestExtension tableNameExt = new TableNameTestExtension();

private static String getRack(int index) {
if (index < 10) {
Expand All @@ -80,7 +80,7 @@ private static String getRack(int index) {
}
}

@BeforeClass
@BeforeAll
public static void setupBeforeClass() throws Exception {
// Set up some server -> rack mappings
// Have three racks in the cluster with 10 hosts each.
Expand Down Expand Up @@ -296,7 +296,7 @@ public void testSecondaryAndTertiaryPlacementWithMoreThanOneServerInPrimaryRack(
// create regions
List<RegionInfo> regions = new ArrayList<>(regionCount);
for (int i = 0; i < regionCount; i++) {
regions.add(RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
regions.add(RegionInfoBuilder.newBuilder(tableNameExt.getTableName())
.setStartKey(Bytes.toBytes(i)).setEndKey(Bytes.toBytes(i + 1)).build());
}
// place the regions
Expand Down Expand Up @@ -390,7 +390,7 @@ public void testConstrainedPlacement() throws Exception {

List<RegionInfo> regions = new ArrayList<>(20);
for (int i = 0; i < 20; i++) {
regions.add(RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
regions.add(RegionInfoBuilder.newBuilder(tableNameExt.getTableName())
.setStartKey(Bytes.toBytes(i)).setEndKey(Bytes.toBytes(i + 1)).build());
}
Map<ServerName, List<RegionInfo>> assignmentMap = new HashMap<ServerName, List<RegionInfo>>();
Expand Down Expand Up @@ -532,7 +532,7 @@ public void testGetFavoredNodes() throws IOException {
helper.initialize();
assertTrue(helper.canPlaceFavoredNodes());

RegionInfo region = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
RegionInfo region = RegionInfoBuilder.newBuilder(tableNameExt.getTableName())
.setStartKey(HConstants.EMPTY_START_ROW).setEndKey(HConstants.EMPTY_END_ROW).build();

for (int maxattempts = 0; maxattempts < MAX_ATTEMPTS; maxattempts++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@
*/
package org.apache.hadoop.hbase.filter;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Set;
import java.util.TreeSet;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.FilterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@SuppressWarnings("deprecation")
@Category({ FilterTests.class, SmallTests.class })
@Tag(FilterTests.TAG)
@Tag(SmallTests.TAG)
public class TestFirstKeyValueMatchingQualifiersFilter {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestFirstKeyValueMatchingQualifiersFilter.class);

private static final byte[] ROW = Bytes.toBytes("test");
private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test");
private static final byte[] COLUMN_QUALIFIER_1 = Bytes.toBytes("foo");
Expand All @@ -48,6 +44,7 @@ public class TestFirstKeyValueMatchingQualifiersFilter {
* Test the functionality of
* {@link FirstKeyValueMatchingQualifiersFilter#filterCell(org.apache.hadoop.hbase.Cell)}
*/
@Test
public void testFirstKeyMatchingQualifierFilter() throws Exception {
Set<byte[]> quals = new TreeSet<>(Bytes.BYTES_COMPARATOR);
quals.add(COLUMN_QUALIFIER_1);
Expand All @@ -57,19 +54,19 @@ public void testFirstKeyMatchingQualifierFilter() throws Exception {
// Match in first attempt
KeyValue cell;
cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_1, VAL_1);
assertTrue("includeAndSetFlag", filter.filterCell(cell) == Filter.ReturnCode.INCLUDE);
assertTrue(filter.filterCell(cell) == Filter.ReturnCode.INCLUDE, "includeAndSetFlag");
cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);
assertTrue("flagIsSetSkipToNextRow", filter.filterCell(cell) == Filter.ReturnCode.NEXT_ROW);
assertTrue(filter.filterCell(cell) == Filter.ReturnCode.NEXT_ROW, "flagIsSetSkipToNextRow");

// A mismatch in first attempt and match in second attempt.
filter.reset();
cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_3, VAL_1);
System.out.println(filter.filterCell(cell));
assertTrue("includeFlagIsUnset", filter.filterCell(cell) == Filter.ReturnCode.INCLUDE);
assertTrue(filter.filterCell(cell) == Filter.ReturnCode.INCLUDE, "includeFlagIsUnset");
cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);
assertTrue("includeAndSetFlag", filter.filterCell(cell) == Filter.ReturnCode.INCLUDE);
assertTrue(filter.filterCell(cell) == Filter.ReturnCode.INCLUDE, "includeAndSetFlag");
cell = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_1, VAL_1);
assertTrue("flagIsSetSkipToNextRow", filter.filterCell(cell) == Filter.ReturnCode.NEXT_ROW);
assertTrue(filter.filterCell(cell) == Filter.ReturnCode.NEXT_ROW, "flagIsSetSkipToNextRow");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,31 @@
*/
package org.apache.hadoop.hbase.master;

import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.CommonFSUtils;
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;

@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestMasterNotCarryTable {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestMasterNotCarryTable.class);

private static final Logger LOG = LoggerFactory.getLogger(TestMasterNotCarryTable.class);

private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();

private static HMaster master;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
Configuration c = UTIL.getConfiguration();
// We use local filesystem. Set it so it writes into the testdir.
Expand All @@ -61,7 +56,7 @@ public static void setUp() throws Exception {
}
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
master.stop("Shutdown");
UTIL.shutdownMiniZKCluster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
*/
package org.apache.hadoop.hbase.master;

import static junit.framework.TestCase.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -32,13 +31,11 @@
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
import org.apache.zookeeper.KeeperException;
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.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
Expand All @@ -47,29 +44,25 @@
* Tests that table state is mirrored out to zookeeper for hbase-1.x clients. Also tests that table
* state gets migrated from zookeeper on master start.
*/
@Category({ MasterTests.class, LargeTests.class })
@Tag(MasterTests.TAG)
@Tag(LargeTests.TAG)
public class TestMirroringTableStateManager {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestMirroringTableStateManager.class);
@Rule
public TestName name = new TestName();

private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();

@Before
@BeforeEach
public void before() throws Exception {
TEST_UTIL.startMiniCluster();
}

@After
@AfterEach
public void after() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}

@Test
public void testMirroring() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
public void testMirroring(TestInfo testInfo) throws Exception {
final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY_STR);
ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
assertTrue(TableState.State.ENABLED.equals(getTableStateInZK(zkw, tableName)));
Expand Down
Loading
Loading