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,11 +17,11 @@
*/
package org.apache.hadoop.hbase;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
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.assertNotEquals;
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.invoke.MethodHandles;
Expand All @@ -36,36 +36,28 @@
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
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.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test {@link org.apache.hadoop.hbase.TestMetaTableForReplica}.
*/
@Category({ MiscTests.class, MediumTests.class })
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
@SuppressWarnings("deprecation")
public class TestMetaTableForReplica {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestMetaTableForReplica.class);

private static final Logger LOG = LoggerFactory.getLogger(TestMetaTableForReplica.class);
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
private static Connection connection;
private static Field metaTableName;
private static Object originalMetaTableName;

@Rule
public TestName name = new TestName();

@BeforeClass
@BeforeAll
public static void beforeClass() throws Exception {
Configuration c = UTIL.getConfiguration();
// quicker heartbeat interval for faster DN death notification
Expand All @@ -79,7 +71,7 @@ public static void beforeClass() throws Exception {
originalMetaTableName = metaTableName.get(null);
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
connection.close();
UTIL.shutdownMiniCluster();
Expand Down Expand Up @@ -109,16 +101,15 @@ private void testNameOfMetaForReplica() {
}

private void testGetNonExistentRegionFromMetaFromReplica() throws IOException {
final String name = this.name.getMethodName();
LOG.info("Started " + name);
LOG.info("Started testGetNonExistentRegionFromMetaFromReplica");
Pair<RegionInfo, ServerName> pair =
MetaTableAccessor.getRegion(connection, Bytes.toBytes("nonexistent-region"));
assertNull(pair);
LOG.info("Finished " + name);
LOG.info("Finished testGetNonExistentRegionFromMetaFromReplica");
}

private void testGetExistentRegionFromMetaFromReplica() throws IOException {
final TableName tableName = TableName.valueOf(name.getMethodName());
final TableName tableName = TableName.valueOf("testMetaTableNameForReplicaWithoutSuffix");
LOG.info("Started " + tableName);
UTIL.createTable(tableName, HConstants.CATALOG_FAMILY);
assertEquals(1, MetaTableAccessor.getTableRegions(connection, tableName).size());
Expand All @@ -139,12 +130,12 @@ public void testMetaTableNameForReplicaWithSuffix() throws Exception {
TableName defaultMetaName = TableName.getDefaultNameOfMetaForReplica();

// The current meta table name is not the default one.
assertNotEquals("META_TABLE_NAME should not be the default. ", defaultMetaName,
currentMetaName);
assertNotEquals(defaultMetaName, currentMetaName,
"META_TABLE_NAME should not be the default. ");

// The current meta table name has the configured suffix.
assertEquals("META_TABLE_NAME should have the configured suffix", expectedMetaTableName,
currentMetaName);
assertEquals(expectedMetaTableName, currentMetaName,
"META_TABLE_NAME should have the configured suffix");

// restore default value of META_TABLE_NAME
setDefaultMetaTableName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,35 @@
*/
package org.apache.hadoop.hbase.client;

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

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.NamespaceNotFoundException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.TestRefreshHFilesBase;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category({ MediumTests.class, ClientTests.class })
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag(MediumTests.TAG)
@Tag(ClientTests.TAG)
public class TestRefreshHFilesFromClient extends TestRefreshHFilesBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRefreshHFilesFromClient.class);

private static final TableName TEST_NONEXISTENT_TABLE =
TableName.valueOf("testRefreshHFilesNonExistentTable");
private static final String TEST_NONEXISTENT_NAMESPACE = "testRefreshHFilesNonExistentNamespace";

@Before
@BeforeEach
public void setup() throws Exception {
baseSetup(false);
}

@After
@AfterEach
public void tearDown() throws Exception {
baseTearDown();
}
Expand All @@ -63,7 +60,7 @@ public void testRefreshHFilesForTable() throws Exception {
Long procId = admin.refreshHFiles(TEST_TABLE);
assertTrue(procId >= 0);
} catch (Exception e) {
Assert.fail("RefreshHFilesForTable Should Not Throw Exception: " + e);
fail("RefreshHFilesForTable Should Not Throw Exception: " + e);
throw new RuntimeException(e);
} finally {
// Delete table name post test execution
Expand All @@ -72,14 +69,13 @@ public void testRefreshHFilesForTable() throws Exception {
}

// Not creating table hence refresh should throw exception
@Test(expected = TableNotFoundException.class)
public void testRefreshHFilesForNonExistentTable() throws Exception {
// RefreshHFiles for table
admin.refreshHFiles(TEST_NONEXISTENT_TABLE);
@Test
public void testRefreshHFilesForNonExistentTable() {
assertThrows(TableNotFoundException.class, () -> admin.refreshHFiles(TEST_NONEXISTENT_TABLE));
}

@Test
public void testRefreshHFilesForNamespace() throws Exception {
public void testRefreshHFilesForNamespace() {
try {
createNamespace(TEST_NAMESPACE);

Expand All @@ -91,7 +87,7 @@ public void testRefreshHFilesForNamespace() throws Exception {
assertTrue(procId >= 0);

} catch (Exception e) {
Assert.fail("RefreshHFilesForAllNamespace Should Not Throw Exception: " + e);
fail("RefreshHFilesForAllNamespace Should Not Throw Exception: " + e);
throw new RuntimeException(e);
} finally {
// Delete namespace post test execution
Expand All @@ -101,10 +97,11 @@ public void testRefreshHFilesForNamespace() throws Exception {
}
}

@Test(expected = NamespaceNotFoundException.class)
public void testRefreshHFilesForNonExistentNamespace() throws Exception {
@Test
public void testRefreshHFilesForNonExistentNamespace() {
// RefreshHFiles for namespace
admin.refreshHFiles(TEST_NONEXISTENT_NAMESPACE);
assertThrows(NamespaceNotFoundException.class,
() -> admin.refreshHFiles(TEST_NONEXISTENT_NAMESPACE));
}

@Test
Expand All @@ -124,7 +121,7 @@ public void testRefreshHFilesForAllTables() throws Exception {
assertTrue(procId >= 0);

} catch (Exception e) {
Assert.fail("RefreshHFilesForAllTables Should Not Throw Exception: " + e);
fail("RefreshHFilesForAllTables Should Not Throw Exception: " + e);
throw new RuntimeException(e);
} finally {
// Delete table name post test execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.master;

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.io.InterruptedIOException;
Expand Down Expand Up @@ -218,10 +218,10 @@ public void testClusterMetricsSkippingForeignMetaTable() throws Exception {
try {
Map<TableName, RegionStatesCount> tableRegionStatesCount = getTableRegionStatesCount();

assertFalse("Foreign meta table should not be present",
tableRegionStatesCount.containsKey(replicaMetaTable));
assertTrue("Local meta should be present",
tableRegionStatesCount.containsKey(TableName.META_TABLE_NAME));
assertFalse(tableRegionStatesCount.containsKey(replicaMetaTable),
"Foreign meta table should not be present");
assertTrue(tableRegionStatesCount.containsKey(TableName.META_TABLE_NAME),
"Local meta should be present");

} finally {
master.getTableDescriptors().remove(replicaMetaTable);
Expand Down Expand Up @@ -284,11 +284,11 @@ public void testClusterMetricsSkippingCachedForeignTables() throws Exception {
tableName.equals(TableName.META_TABLE_NAME)
|| tableName.getQualifierAsString().startsWith("familiar")
) {
assertTrue("Expected this table's state to exist: " + tableName,
tableRegionStatesCount.containsKey(tableName));
assertTrue(tableRegionStatesCount.containsKey(tableName),
"Expected this table's state to exist: " + tableName);
} else {
assertFalse("This foreign table's state should not exist: " + tableName,
tableRegionStatesCount.containsKey(tableName));
assertFalse(tableRegionStatesCount.containsKey(tableName),
"This foreign table's state should not exist: " + tableName);
}
} finally {
if (!TableName.META_TABLE_NAME.equals(tableName) && familiarTables.contains(tableName)) {
Expand Down Expand Up @@ -329,8 +329,10 @@ public void testClusterMetricsSkippingForeignTablesOnFileSystem() throws IOExcep
Map<String, TableDescriptor> tableDescriptorMap = master.getTableDescriptors().getAll();
assertEquals(4, tableDescriptorMap.size());
for (TableName tableName : familiarTables) {
assertTrue("Expected table descriptor map to contain table: " + tableName, tableDescriptorMap
.containsKey(tableName.getNamespaceAsString() + ":" + tableName.getQualifierAsString()));
assertTrue(
tableDescriptorMap
.containsKey(tableName.getNamespaceAsString() + ":" + tableName.getQualifierAsString()),
"Expected table descriptor map to contain table: " + tableName);
}

createTableDescriptorOnFileSystem("hbase", "meta_replica", foreignTables);
Expand All @@ -342,26 +344,26 @@ public void testClusterMetricsSkippingForeignTablesOnFileSystem() throws IOExcep
Path tableDescPath = new Path(testDir,
"data" + Path.SEPARATOR + tableName.getNamespaceAsString() + Path.SEPARATOR
+ tableName.getQualifierAsString() + Path.SEPARATOR + FSTableDescriptors.TABLEINFO_DIR);
assertTrue("Expected table descriptor directory to exist: " + tableDescPath,
fs.exists(tableDescPath));
assertTrue(fs.exists(tableDescPath),
"Expected table descriptor directory to exist: " + tableDescPath);
}

Map<TableName, RegionStatesCount> tableRegionStatesCount = getTableRegionStatesCount();

// The foreign tables should not be in the table state
assertEquals(4, tableRegionStatesCount.size());
for (TableName tableName : familiarTables) {
assertTrue("Expected table regions state count to contain: " + tableName,
tableRegionStatesCount.containsKey(tableName));
assertTrue(tableRegionStatesCount.containsKey(tableName),
"Expected table regions state count to contain: " + tableName);
// Delete unneeded tables
if (!TableName.META_TABLE_NAME.equals(tableName)) {
LOG.debug("Deleting table: {}", tableName);
TEST_UTIL.deleteTable(tableName);
}
}
for (TableName tableName : foreignTables) {
assertFalse("Expected table regions state count to NOT contain: " + tableName,
tableRegionStatesCount.containsKey(tableName));
assertFalse(tableRegionStatesCount.containsKey(tableName),
"Expected table regions state count to NOT contain: " + tableName);
// Remove unneeded table descriptors
LOG.debug("Removing table descriptor for foreign table: {}", tableName);
master.getTableDescriptors().remove(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,24 @@
package org.apache.hadoop.hbase.master.procedure;

import java.io.IOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TestRefreshHFilesBase;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestRefreshHFilesProcedure extends TestRefreshHFilesBase {

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

@Before
@BeforeEach
public void setup() throws Exception {
baseSetup(false);
}

@After
@AfterEach
public void tearDown() throws Exception {
baseTearDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,26 @@
package org.apache.hadoop.hbase.master.procedure;

import java.io.IOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TestRefreshHFilesBase;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestRefreshHFilesProcedureWithReadOnlyConf extends TestRefreshHFilesBase {

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

@Before
@BeforeEach
public void setup() throws Exception {
// When true is passed only setup for readonly property is done.
// The initial ReadOnly property will be false for table creation
baseSetup(true);
}

@After
@AfterEach
public void tearDown() throws Exception {
baseTearDown();
}
Expand Down
Loading
Loading