private HBaseAdmin createTable(TableName tableName) throws IOException { HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor("value"); htd.addFamily(hcd); admin.createTable(htd, null); return admin; }
/** * Verify that a single table is restored using overwrite. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreSingleOverwriteCommand() throws Exception { LOG.info("test full restore on a single table empty table: command-line"); List<TableName> tables = Lists.newArrayList(table1); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); LOG.info("backup complete"); TableName[] tableset = new TableName[] { table1 }; // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(tableset, ","), "-o" }; // Run restore int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1)); hba.close(); }
@Test(timeout = 180000) public void testEnsureTemporaryDirectoryTransfer() throws Exception { Admin admin = null; TableName tableName2 = TableName.valueOf("testListTableSnapshots"); try { admin = UTIL.getHBaseAdmin(); HTableDescriptor htd = new HTableDescriptor(tableName2); UTIL.createTable(htd, new byte[][] { TEST_FAM }, UTIL.getConfiguration()); assertEquals(3, listTableSnapshots.size()); for (SnapshotDescription s : listTableSnapshots) { listTableSnapshotNames.add(s.getName()); assertTrue(listTableSnapshotNames.contains(table1Snapshot1)); assertTrue(listTableSnapshotNames.contains(table1Snapshot2)); assertTrue(listTableSnapshotNames.contains(table2Snapshot1)); } finally { if (admin != null) {
@Test public void testFullBackupRemote() throws Exception { LOG.info("test remote full backup on a single table"); t.start(); table1Desc.addFamily(new HColumnDescriptor(fam3Name)); String backupId = backupTables(BackupType.FULL, Lists.newArrayList(table1), BACKUP_REMOTE_ROOT_DIR); assertTrue(checkSucceeded(backupId)); Assert.assertEquals(TEST_UTIL.countRows(t1, famName), NB_ROWS_IN_BATCH); Assert.assertEquals(TEST_UTIL.countRows(t1, fam3Name), NB_ROWS_IN_FAM3); t1.close(); HBaseAdmin hAdmin = TEST_UTIL.getHBaseAdmin(); assertTrue(hAdmin.tableExists(table1_restore)); Assert.assertEquals(TEST_UTIL.countRows(hTable, famName), NB_ROWS_IN_BATCH); int cnt3 = TEST_UTIL.countRows(hTable, fam3Name); Assert.assertTrue(cnt3 >= 0 && cnt3 <= NB_ROWS_IN_FAM3);
@Test public void testReplayEditsWrittenViaHRegion() throws Exception { final String tableNameStr = "testReplayEditsWrittenViaHRegion"; CoveredColumnIndexer.createIndexTable(UTIL.getHBaseAdmin(), INDEX_TABLE_NAME); assertEquals("Index wasn't propertly updated from WAL replay!", 1, indexSize); Get g = new Get(rowkey); final Result result = region1.get(g); assertEquals("Primary region wasn't updated from WAL replay!", 1, result.size()); HBaseAdmin admin = UTIL.getHBaseAdmin(); admin.disableTable(INDEX_TABLE_NAME); admin.deleteTable(INDEX_TABLE_NAME);
/** * Test that a coprocessor is able to override a normal regionserver stop request. */ @Test public void testStopOverrideFromCoprocessor() throws Exception { Admin admin = testUtil.getHBaseAdmin(); HRegionServer regionserver = cluster.getRegionServer(0); admin.stopRegionServer(regionserver.getServerName().getHostAndPort()); // regionserver should have failed to stop due to coprocessor assertFalse(cluster.getRegionServer(0).isAborted()); assertFalse(cluster.getRegionServer(0).isStopped()); }
private void testCrashRsWithUserRegion(final boolean kill, final boolean withData) throws Exception { final int NROWS = 100; int nkilled = 0; for (RegionInfo hri: UTIL.getHBaseAdmin().getTableRegions(TEST_TABLE)) { ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri); if (AssignmentTestingUtil.isServerHoldingMeta(UTIL, serverName)) continue; if (withData) { testInsert(hri, NROWS); } // wait for regions to enter in transition and then to get out of transition AssignmentTestingUtil.crashRs(UTIL, serverName, kill); AssignmentTestingUtil.waitForRegionToBeInTransition(UTIL, hri); UTIL.waitUntilNoRegionsInTransition(); if (withData) { assertEquals(NROWS, testGet(hri, NROWS)); } // region should be moved to another RS assertNotEquals(serverName, AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri)); if (++nkilled == (NUM_RS - 1)) { break; } } assertTrue("expected RSs to be killed", nkilled > 0); }
@Test public void testUpdateNonIndexedColumn() throws Exception { String tableName = "TBL_" + generateUniqueName(); getUtility().getHBaseAdmin().flush(TableName.valueOf(fullTableName)); conn.createStatement().executeUpdate("UPSERT INTO " + fullTableName + "(k,v1,v2) VALUES ('testKey','v1_4','v2_3')"); conn.commit();
Assert.assertTrue("Failed to start mini cluster in " + attempts + " attempts", successToStart); HTableDescriptor descriptor = new HTableDescriptor(table.getTableDescriptor()); descriptor.addCoprocessor(AggregateProtocolEndPoint.class.getName()); hbase.getHBaseAdmin().modifyTable("unittest",descriptor);
/** * Alter the table metadata and return modified value * @param driver * @param tableName * @return value of VERSIONS option for the table * @throws Exception */ private int verifyModificationTableMetadata(PhoenixSysCatCreationTestingDriver driver, String tableName) throws Exception { // Modify table metadata Connection conn = driver.getConnectionQueryServices(getJdbcUrl(), new Properties()).connect(getJdbcUrl(), new Properties()); conn.createStatement().execute("ALTER TABLE " + tableName + " SET VERSIONS = " + MODIFIED_MAX_VERSIONS); // Connect via a client that creates a new ConnectionQueryServices instance driver.resetCQS(); driver.getConnectionQueryServices(getJdbcUrl(), new Properties()).connect(getJdbcUrl(), new Properties()); HTableDescriptor descriptor = testUtil.getHBaseAdmin().getTableDescriptor(TableName.valueOf(tableName)); return descriptor.getFamily(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES).getMaxVersions(); }
/** * Adds the column family. * * @param tableName * the table name * @param columnFamily * the column family */ public void addColumnFamily(String tableName, String columnFamily) { try { utility.getHBaseAdmin().disableTable(tableName); utility.getHBaseAdmin().addColumn(tableName, new HColumnDescriptor(columnFamily)); utility.getHBaseAdmin().enableTable(tableName); while (utility.getHBaseAdmin().isTableEnabled(tableName)) { return; } } catch (InvalidFamilyOperationException ife) { logger.info("Column family:" + columnFamily + " already exist!", ife); } catch (IOException e) { logger.error("", e); } }
@Test public void testFullRestoreSetToOtherTable() throws Exception { assertTrue(names.size() == 1); assertTrue(names.get(0).equals(table1)); assertTrue(ret == 0); List<BackupInfo> backups = table.getBackupHistory(); assertTrue(backups.size() == 1); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1_restore)); assertEquals(TEST_UTIL.countRows(table1), TEST_UTIL.countRows(table1_restore)); TEST_UTIL.deleteTable(table1_restore); LOG.info("restore into other table is complete");
@Test public void testDisableCatalogTable() throws Exception { try { this.admin.disableTable(TableName.META_TABLE_NAME); fail("Expected to throw ConstraintException"); } catch (ConstraintException e) { } // Before the fix for HBASE-6146, the below table creation was failing as the hbase:meta table // actually getting disabled by the disableTable() call. HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(Bytes.toBytes(name.getMethodName()))); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf1")); htd.addFamily(hcd); TEST_UTIL.getHBaseAdmin().createTable(htd); }
/** * Verify that multiple tables are restored to new tables using overwrite. * * @throws Exception if doing the backup or an operation on the tables fails */ @Test public void testFullRestoreMultipleOverwriteCommand() throws Exception { LOG.info("create full backup image on multiple tables: command-line"); List<TableName> tables = Lists.newArrayList(table2, table3); String backupId = fullTableBackup(tables); assertTrue(checkSucceeded(backupId)); TableName[] restore_tableset = new TableName[] { table2, table3 }; // restore <backup_root_path> <backup_id> <tables> [tableMapping] String[] args = new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(restore_tableset, ","), "-o" }; // Run backup int ret = ToolRunner.run(conf1, new RestoreDriver(), args); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table2)); assertTrue(hba.tableExists(table3)); hba.close(); }
@Test public void TestIncBackupRestore() throws Exception { int ADD_ROWS = 99; final byte[] mobName = Bytes.toBytes("mob"); BackupRequest request = createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR); String backupIdFull = client.backupTables(request); assertTrue(checkSucceeded(backupIdFull)); Assert.assertEquals(HBaseTestingUtility.countRows(t1), NB_ROWS_IN_BATCH + ADD_ROWS + NB_ROWS_FAM3); LOG.debug("written " + ADD_ROWS + " rows to " + table1); t2.put(p2); Assert.assertEquals(NB_ROWS_IN_BATCH + 5, HBaseTestingUtility.countRows(t2)); t2.close(); LOG.debug("written " + 5 + " rows to " + table2); table1Desc.addFamily(new HColumnDescriptor(fam2Name)); assertTrue(checkSucceeded(backupIdIncMultiple2)); HBaseAdmin hAdmin = TEST_UTIL.getHBaseAdmin();
@Test public void testTableSplits() throws Exception { HBaseAdmin admin = getTestUtil().getHBaseAdmin(); byte[] tableName = "oneSplitTest".getBytes(); Assert.assertEquals(1, scans.size()); Assert.assertEquals("Regions didn't split as requested, wtf", 3, startsEnds.getFirst().length); internalSplitKeys = BackfillUtil.getSplitKeys(startsEnds); scans = HBaseBackfillMerger.scansThisCubeOnly(new byte[] {}, internalSplitKeys); Assert.assertEquals(3, scans.size());
@Test(timeout = 300000) public void testOfflineTableSnapshot() throws Exception { Admin admin = UTIL.getHBaseAdmin();
private void testCrashRsWithUserRegion(final boolean kill, final boolean withData) throws Exception { final int NROWS = 100; int nkilled = 0; for (RegionInfo hri: UTIL.getHBaseAdmin().getTableRegions(TEST_TABLE)) { ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri); if (AssignmentTestingUtil.isServerHoldingMeta(UTIL, serverName)) continue; if (withData) { testInsert(hri, NROWS); } // wait for regions to enter in transition and then to get out of transition AssignmentTestingUtil.crashRs(UTIL, serverName, kill); AssignmentTestingUtil.waitForRegionToBeInTransition(UTIL, hri); UTIL.waitUntilNoRegionsInTransition(); if (withData) { assertEquals(NROWS, testGet(hri, NROWS)); } // region should be moved to another RS assertNotEquals(serverName, AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri)); if (++nkilled == (NUM_RS - 1)) { break; } } assertTrue("expected RSs to be killed", nkilled > 0); }
@Test public void testFullRestoreSetToSameTable() throws Exception { assertTrue(names.size() == 1); assertTrue(names.get(0).equals(table1)); assertTrue(ret == 0); List<BackupInfo> backups = table.getBackupHistory(); String backupId = backups.get(0).getBackupId(); assertTrue(ret == 0); HBaseAdmin hba = TEST_UTIL.getHBaseAdmin(); assertTrue(hba.tableExists(table1)); assertEquals(count, TEST_UTIL.countRows(table1)); LOG.info("restore into same table is complete"); hba.close();
private Table createTable() throws IOException { TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor table = new HTableDescriptor(tableName); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); fam.setNewVersionBehavior(true); fam.setMaxVersions(3); table.addFamily(fam); TEST_UTIL.getHBaseAdmin().createTable(table); return TEST_UTIL.getConnection().getTable(tableName); }