OmidTableManager { public void executeActionsOnHBase(Configuration hbaseConf) throws IOException { HBaseLogin.loginIfNeeded(mainConfig.loginFlags); try (Connection conn = ConnectionFactory.createConnection(hbaseConf); Admin hBaseAdmin = conn.getAdmin()) { byte[][] tableFamilies; byte[][] splitKeys = new byte[0][0]; String tableName; LOG.info("----------------------------------------------------------------------------------------------"); switch (commandLine.getParsedCommand()) { case COMMIT_TABLE_COMMAND_NAME: LOG.info("Performing actions related to COMMIT TABLE"); tableName = commitTableCommand.tableName; tableFamilies = commitTableFamilies; if (commitTableCommand.numRegions > 1) { splitKeys = splitInUniformRegions(hbaseConf, commitTableCommand.numRegions); } break; case TIMESTAMP_TABLE_COMMAND_NAME: LOG.info("Performing actions related to TIMESTAMP TABLE"); tableName = timestampTableCommand.tableName; tableFamilies = timestampTableFamilies; break; default: LOG.error("Unknown command: {}", commandLine.getParsedCommand()); commandLine.usage(); return; } createTable(hBaseAdmin, tableName, tableFamilies, splitKeys, 1); LOG.info("----------------------------------------------------------------------------------------------"); } } OmidTableManager(String... args); void executeActionsOnHBase(Configuration hbaseConf); static void main(String... args); static final String COMMIT_TABLE_COMMAND_NAME; }
@Test(timeOut = 20_000) public void testCreateDefaultTimestampTableSucceeds() throws Throwable { String[] args = new String[]{TIMESTAMP_TABLE_COMMAND_NAME}; OmidTableManager omidTableManager = new OmidTableManager(args); omidTableManager.executeActionsOnHBase(hbaseConf); TableName tableName = TableName.valueOf(HBaseTimestampStorageConfig.DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME); assertTrue(hBaseAdmin.tableExists(tableName)); int numRegions = hBaseAdmin.getTableRegions(tableName).size(); assertEquals(numRegions, 1, "Should have only 1 region"); }
@Test(timeOut = 20_000) public void testCreateDefaultCommitTableSucceeds() throws Throwable { String[] args = new String[]{COMMIT_TABLE_COMMAND_NAME}; OmidTableManager omidTableManager = new OmidTableManager(args); omidTableManager.executeActionsOnHBase(hbaseConf); TableName tableName = TableName.valueOf(HBaseCommitTableConfig.DEFAULT_COMMIT_TABLE_NAME); assertTrue(hBaseAdmin.tableExists(tableName)); int numRegions = hBaseAdmin.getTableRegions(tableName).size(); assertEquals(numRegions, 16, "Should have 16 regions"); }
@Test(timeOut = 20_000) public void testCreateCustomCommitTableSucceeds() throws Throwable { String[] args = new String[]{COMMIT_TABLE_COMMAND_NAME, "-tableName", "my-commit-table", "-numRegions", "1"}; OmidTableManager omidTableManager = new OmidTableManager(args); omidTableManager.executeActionsOnHBase(hbaseConf); TableName tableName = TableName.valueOf("my-commit-table"); assertTrue(hBaseAdmin.tableExists(tableName)); int numRegions = hBaseAdmin.getTableRegions(tableName).size(); assertEquals(numRegions, 1, "Should have only 1 regions"); }
@Test(expectedExceptions = IllegalArgumentException.class, timeOut = 20_000) public void testExceptionIsThrownWhenSpecifyingAWrongCommand() throws Throwable { String[] args = new String[]{"non-recognized-command"}; OmidTableManager omidTableManager = new OmidTableManager(args); omidTableManager.executeActionsOnHBase(hbaseConf); }