From d845abb7f06d33a3ffbfdd13f4b860abf877fae0 Mon Sep 17 00:00:00 2001 From: Artem Ervits Date: Fri, 23 Feb 2018 12:42:26 -0500 Subject: [PATCH 1/2] HBASE-19157 IntegrationTestBackupRestore should warn about missing config --- .../hadoop/hbase/IntegrationTestBackupRestore.java | 88 +++++++++++++++++++--- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java index 4c56444aaf..fbec2797f3 100644 --- hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java +++ hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java @@ -52,7 +52,6 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.hbase.thirdparty.com.google.common.base.Objects; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; /** @@ -80,6 +79,10 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { private static int rowsInBatch; private static String BACKUP_ROOT_DIR = "backupIT"; + /** + * + * @throws Exception + */ @Override @Before public void setUp() throws Exception { @@ -98,6 +101,10 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { LOG.info("Cluster ready"); } + /** + * + * @throws IOException + */ @After public void tearDown() throws IOException { LOG.info("Cleaning up after test."); @@ -120,11 +127,19 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { BackupManager.decorateRegionServerConfiguration(conf); } + /** + * + * @throws IOException + */ private void cleanUpBackupDir() throws IOException { FileSystem fs = FileSystem.get(util.getConfiguration()); fs.delete(new Path(BACKUP_ROOT_DIR), true); } + /** + * + * @throws Exception + */ @Test public void testBackupRestore() throws Exception { BACKUP_ROOT_DIR = util.getDataTestDirOnTestFS() + Path.SEPARATOR + BACKUP_ROOT_DIR; @@ -133,7 +148,10 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { runTest(); } - + /** + * + * @throws Exception + */ private void createTable(TableName tableName) throws Exception { long startTime, endTime; HTableDescriptor desc = new HTableDescriptor(tableName); @@ -150,6 +168,10 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { (endTime - startTime))); } + /** + * + * @throws IOException + */ private void loadData(TableName table, int numRows) throws IOException { Connection conn = util.getConnection(); // #0- insert some data to a table @@ -159,7 +181,18 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { conn.getAdmin().flush(TableName.valueOf(table.getName())); } + /** + * + * @throws IOException + */ private void runTest() throws IOException { + // Check if backup is enabled + if (!BackupManager.isBackupEnabled(getConf())) { + LOG.error(BackupRestoreConstants.ENABLE_BACKUP); + System.exit(EXIT_FAILURE); + } + + LOG.info(BackupRestoreConstants.VERIFY_BACKUP); try (Connection conn = util.getConnection(); Admin admin = conn.getAdmin(); @@ -180,12 +213,14 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { // #2 - insert some data to table loadData(TABLE_NAME1, rowsInBatch); loadData(TABLE_NAME2, rowsInBatch); - HTable t1 = (HTable) conn.getTable(TABLE_NAME1); - Assert.assertEquals(util.countRows(t1), rowsInBatch * 2); - t1.close(); - HTable t2 = (HTable) conn.getTable(TABLE_NAME2); - Assert.assertEquals(util.countRows(t2), rowsInBatch * 2); - t2.close(); + + try (HTable t1 = (HTable) conn.getTable(TABLE_NAME1)) { + Assert.assertEquals(util.countRows(t1), rowsInBatch * 2); + } + try (HTable t2 = (HTable) conn.getTable(TABLE_NAME2)) { + Assert.assertEquals(util.countRows(t2), rowsInBatch * 2); + } + // #3 - incremental backup for tables tables = Lists.newArrayList(TABLE_NAME1, TABLE_NAME2); builder = new BackupRequest.Builder(); @@ -221,6 +256,12 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { } } + /** + * + * @param backupId + * @return + * @throws IOException + */ protected boolean checkSucceeded(String backupId) throws IOException { BackupInfo status = getBackupInfo(backupId); if (status == null) return false; @@ -235,6 +276,14 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { /** * Get restore request. + * + * @param backupRootDir + * @param backupId + * @param check + * @param fromTables + * @param toTables + * @param isOverwrite + * @return */ public RestoreRequest createRestoreRequest(String backupRootDir, String backupId, boolean check, TableName[] fromTables, TableName[] toTables, boolean isOverwrite) { @@ -247,7 +296,11 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { .withOvewrite(isOverwrite).build(); } - @Override + /** + * + * @throws Exception + */ + @Override public void setUpCluster() throws Exception { util = getTestingUtil(getConf()); enableBackup(getConf()); @@ -256,8 +309,20 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { LOG.debug("Done initializing/checking cluster"); } + /** + * + * @throws Exception + */ @Override public int runTestFromCommandLine() throws Exception { + // Check if backup is enabled + if (!BackupManager.isBackupEnabled(getConf())) { + LOG.error(BackupRestoreConstants.ENABLE_BACKUP); + return -1; + } + + LOG.info(BackupRestoreConstants.VERIFY_BACKUP); + testBackupRestore(); return 0; } @@ -302,6 +367,11 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { .toString()); } + /** + * + * @param args + * @throws Exception + */ public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); IntegrationTestingUtility.setUseDistributedCluster(conf); -- 2.14.3 (Apple Git-98) From 66f54ca3a6088e94ae9017ac42f4850c7f683259 Mon Sep 17 00:00:00 2001 From: Artem Ervits Date: Fri, 23 Feb 2018 14:07:47 -0500 Subject: [PATCH 2/2] HBASE-19157 IntegrationTestBackupRestore should warn about missing config [addendum] --- .../hadoop/hbase/IntegrationTestBackupRestore.java | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java index fbec2797f3..e49d5f8369 100644 --- hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java +++ hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestBackupRestore.java @@ -259,7 +259,7 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { /** * * @param backupId - * @return + * @return status of backup * @throws IOException */ protected boolean checkSucceeded(String backupId) throws IOException { @@ -268,6 +268,10 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { return status.getState() == BackupState.COMPLETE; } + /** + * + * @throws IOException + */ private BackupInfo getBackupInfo(String backupId) throws IOException { try (BackupSystemTable table = new BackupSystemTable(util.getConnection())) { return table.readBackupInfo(backupId); @@ -277,13 +281,13 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { /** * Get restore request. * - * @param backupRootDir - * @param backupId - * @param check - * @param fromTables - * @param toTables - * @param isOverwrite - * @return + * @param backupRootDir directory where backup is located + * @param backupId backup ID + * @param check check the backup + * @param fromTables table names to restore from + * @param toTables new table names to restore to + * @param isOverwrite overwrite the table(s) + * @return an instance of RestoreRequest */ public RestoreRequest createRestoreRequest(String backupRootDir, String backupId, boolean check, TableName[] fromTables, TableName[] toTables, boolean isOverwrite) { @@ -311,17 +315,18 @@ public class IntegrationTestBackupRestore extends IntegrationTestBase { /** * + * @return status of CLI execution * @throws Exception */ @Override public int runTestFromCommandLine() throws Exception { // Check if backup is enabled if (!BackupManager.isBackupEnabled(getConf())) { - LOG.error(BackupRestoreConstants.ENABLE_BACKUP); + System.err.println(BackupRestoreConstants.ENABLE_BACKUP); return -1; } - LOG.info(BackupRestoreConstants.VERIFY_BACKUP); + System.out.println(BackupRestoreConstants.VERIFY_BACKUP); testBackupRestore(); return 0; -- 2.14.3 (Apple Git-98)