/** * Remove specified namespace from the acl table. */ static void removeNamespacePermissions(Configuration conf, String namespace, Table t) throws IOException{ Delete d = new Delete(Bytes.toBytes(toNamespaceEntry(namespace))); if (LOG.isDebugEnabled()) { LOG.debug("Removing permissions of removed namespace "+ namespace); } try { t.delete(d); } finally { t.close(); } }
/** * Test read only tables * @throws Exception */ @Test public void testReadOnlyTable() throws Exception { final TableName name = TableName.valueOf(this.name.getMethodName()); Table table = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); byte[] value = Bytes.toBytes("somedata"); // This used to use an empty row... That must have been a bug Put put = new Put(value); put.addColumn(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value); table.put(put); table.close(); }
/** * For HADOOP-2579 * @throws IOException */ @Test (expected=TableExistsException.class) public void testTableExistsExceptionWithATable() throws IOException { final TableName name = TableName.valueOf(this.name.getMethodName()); TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY).close(); TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); }
private void createTableWithNonDefaultProperties() throws Exception { final long startTime = System.currentTimeMillis(); final String sourceTableNameAsString = STRING_TABLE_NAME + startTime; originalTableName = TableName.valueOf(sourceTableNameAsString); // enable replication on a column family HColumnDescriptor maxVersionsColumn = new HColumnDescriptor(MAX_VERSIONS_FAM); HColumnDescriptor bloomFilterColumn = new HColumnDescriptor(BLOOMFILTER_FAM); HColumnDescriptor dataBlockColumn = new HColumnDescriptor(COMPRESSED_FAM); HColumnDescriptor blockSizeColumn = new HColumnDescriptor(BLOCKSIZE_FAM); maxVersionsColumn.setMaxVersions(MAX_VERSIONS); bloomFilterColumn.setBloomFilterType(BLOOM_TYPE); dataBlockColumn.setDataBlockEncoding(DATA_BLOCK_ENCODING_TYPE); blockSizeColumn.setBlocksize(BLOCK_SIZE); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(sourceTableNameAsString)); htd.addFamily(maxVersionsColumn); htd.addFamily(bloomFilterColumn); htd.addFamily(dataBlockColumn); htd.addFamily(blockSizeColumn); htd.setValue(TEST_CUSTOM_VALUE, TEST_CUSTOM_VALUE); htd.setConfiguration(TEST_CONF_CUSTOM_VALUE, TEST_CONF_CUSTOM_VALUE); assertTrue(htd.getConfiguration().size() > 0); admin.createTable(htd); Table original = UTIL.getConnection().getTable(originalTableName); originalTableName = TableName.valueOf(sourceTableNameAsString); originalTableDescriptor = admin.getTableDescriptor(originalTableName); originalTableDescription = originalTableDescriptor.toStringCustomizedValues(); original.close(); }
@Test public void testNegativeMemstoreSize() throws IOException, InterruptedException { boolean IOEthrown = false; Table table = null; try { table = TEST_UTIL.getConnection().getTable(TableName.valueOf(tableName)); // Adding data Put put1 = new Put(Bytes.toBytes("row1")); put1.addColumn(family, qualifier, Bytes.toBytes("Value1")); table.put(put1); Put put2 = new Put(Bytes.toBytes("row2")); put2.addColumn(family, qualifier, Bytes.toBytes("Value2")); table.put(put2); table.put(put2); } catch (IOException e) { IOEthrown = true; } finally { Assert.assertFalse("Shouldn't have thrown an exception", IOEthrown); if (table != null) { table.close(); } } }
/** * Not really restarting the master. Simulate it by clear of new region * state since it is not persisted, will be lost after master restarts. */ @Test public void testMergeAndRestartingMaster() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); // Create table and load data. Table table = createTableAndLoadData(MASTER, tableName); try { MyMasterRpcServices.enabled.set(true); // Merge 1st and 2nd region mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1); } finally { MyMasterRpcServices.enabled.set(false); } table.close(); }
@Test public void testCoprocessorError() throws Exception { Configuration configuration = new Configuration(util.getConfiguration()); // Make it not retry forever configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); Table table = util.getConnection().getTable(TEST_TABLE); try { CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]); TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol); service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance()); fail("Should have thrown an exception"); } catch (ServiceException e) { } finally { table.close(); } }
/** * Returns all rows from the hbase:meta table. * * @throws IOException When reading the rows fails. */ public List<byte[]> getMetaTableRows() throws IOException { // TODO: Redo using MetaTableAccessor class Table t = getConnection().getTable(TableName.META_TABLE_NAME); List<byte[]> rows = new ArrayList<>(); ResultScanner s = t.getScanner(new Scan()); for (Result result : s) { LOG.info("getMetaTableRows: row -> " + Bytes.toStringBinary(result.getRow())); rows.add(result.getRow()); } s.close(); t.close(); return rows; }
public void testRegionReplicaReplication(int regionReplication) throws Exception { // test region replica replication. Create a table with single region, write some data // ensure that data is replicated to the secondary region TableName tableName = TableName.valueOf("testRegionReplicaReplicationWithReplicas_" + regionReplication); HTableDescriptor htd = HTU.createTableDescriptor(tableName.toString()); htd.setRegionReplication(regionReplication); HTU.getAdmin().createTable(htd); TableName tableNameNoReplicas = TableName.valueOf("testRegionReplicaReplicationWithReplicas_NO_REPLICAS"); HTU.deleteTableIfAny(tableNameNoReplicas); HTU.createTable(tableNameNoReplicas, HBaseTestingUtility.fam1); Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration()); Table table = connection.getTable(tableName); Table tableNoReplicas = connection.getTable(tableNameNoReplicas); try { // load some data to the non-replicated table HTU.loadNumericRows(tableNoReplicas, HBaseTestingUtility.fam1, 6000, 7000); // load the data to the table HTU.loadNumericRows(table, HBaseTestingUtility.fam1, 0, 1000); verifyReplication(tableName, regionReplication, 0, 1000); } finally { table.close(); tableNoReplicas.close(); HTU.deleteTableIfAny(tableNameNoReplicas); connection.close(); } }
/** * do a single put that is bypassed by a RegionObserver * @throws Exception */ @Test public void testSimple() throws Exception { Table t = util.getConnection().getTable(tableName); Put p = new Put(row1); p.addColumn(test, dummy, dummy); // before HBASE-4331, this would throw an exception t.put(p); checkRowAndDelete(t,row1,0); t.close(); }
/** * Can't enable a table if the table isn't in disabled state * @throws IOException */ @Test (expected=TableNotDisabledException.class) public void testTableNotDisabledExceptionWithATable() throws IOException { final TableName name = TableName.valueOf(this.name.getMethodName()); Table t = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); try { this.admin.enableTable(name); }finally { t.close(); } }
/** * Ensure when we go to top level index pages that we get redirected to an info-server specific status * page. */ @Test public void testInfoServersRedirect() throws Exception { // give the cluster time to start up UTIL.getConnection().getTable(TableName.META_TABLE_NAME).close(); int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort(); assertContainsContent(new URL("http://localhost:" + port + "/index.html"), "master-status"); port = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer() .getInfoServer().getPort(); assertContainsContent(new URL("http://localhost:" + port + "/index.html"), "rs-status"); }
/** * Test for hadoop-1581 'HBASE: Unopenable tablename bug'. * @throws Exception */ @Test public void testTableNameClash() throws Exception { final String name = this.name.getMethodName(); HTableDescriptor htd1 = new HTableDescriptor(TableName.valueOf(name + "SOMEUPPERCASE")); HTableDescriptor htd2 = new HTableDescriptor(TableName.valueOf(name)); htd1.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); htd2.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(htd1); admin.createTable(htd2); // Before fix, below would fail throwing a NoServerForRegionException. TEST_UTIL.getConnection().getTable(htd2.getTableName()).close(); }
@Test(expected = DoNotRetryIOException.class) public void testScanOnCorruptHFile() throws IOException { TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor htd = new HTableDescriptor(tableName); htd.addCoprocessor(CorruptHFileCoprocessor.class.getName()); htd.addFamily(new HColumnDescriptor(FAMILY_NAME)); Table table = TEST_UTIL.createTable(htd, null); try { loadTable(table, 1); scan(table); } finally { table.close(); } }