@Override public Void call() throws Exception { admin.deleteNamespace("non_existing_namespace"); return null; } }, NamespaceNotFoundException.class);
@Override public void deleteNamespace(String name) throws TIOError, TException { try { connectionCache.getAdmin().deleteNamespace(name); } catch (IOException e) { throw getTIOError(e); } }
public static void deleteNamespace(HBaseTestingUtility testUtil, String namespace) throws Exception { testUtil.getAdmin().deleteNamespace(namespace); }
/** * Invokes Admin#disableTable, Admin#deleteTable, and Admin#deleteNamespace to * disable/delete Table and delete Namespace. * * @param admin Standard Admin object * @throws IOException If IO problem is encountered */ static void deleteNamespaceAndTable(final Admin admin) throws IOException { if (admin.tableExists(MY_TABLE_NAME)) { System.out.println("Disabling/deleting Table [" + MY_TABLE_NAME.getNameAsString() + "]."); admin.disableTable(MY_TABLE_NAME); // Disable a table before deleting it. admin.deleteTable(MY_TABLE_NAME); } if (namespaceExists(admin, MY_NAMESPACE_NAME)) { System.out.println("Deleting Namespace [" + MY_NAMESPACE_NAME + "]."); admin.deleteNamespace(MY_NAMESPACE_NAME); } } }
@Test public void testDeleteReservedNS() throws Exception { boolean exceptionCaught = false; try { admin.deleteNamespace(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR); } catch (IOException exp) { LOG.warn(exp.toString(), exp); exceptionCaught = true; } finally { assertTrue(exceptionCaught); } try { admin.deleteNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR); } catch (IOException exp) { LOG.warn(exp.toString(), exp); exceptionCaught = true; } finally { assertTrue(exceptionCaught); } }
@AfterClass public static void afterClass() throws Exception { UTIL.getAdmin().deleteNamespace(TEST_NAMESPACE); UTIL.getAdmin().deleteNamespace(TEST_NAMESPACE2); UTIL.shutdownMiniCluster(); }
public void deleteNamespaceIfNecessary() throws IOException { for (NamespaceDescriptor desc : TEST_UTIL.getAdmin().listNamespaceDescriptors()) { if(desc.getName().startsWith(tablePrefix)) { admin.deleteNamespace(desc.getName()); } } }
@AfterClass public static void tearDownAfterClass() throws Exception { admin1.disableTable(tabAName); admin1.deleteTable(tabAName); admin1.disableTable(tabBName); admin1.deleteTable(tabBName); admin2.disableTable(tabAName); admin2.deleteTable(tabAName); admin2.disableTable(tabBName); admin2.deleteTable(tabBName); admin1.deleteNamespace(ns1); admin1.deleteNamespace(ns2); admin2.deleteNamespace(ns1); admin2.deleteNamespace(ns2); connection1.close(); connection2.close(); TestReplicationBase.tearDownAfterClass(); }
@Before public void beforeMethod() throws IOException { for (HTableDescriptor desc : admin.listTables(prefix+".*")) { admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); } for (NamespaceDescriptor ns : admin.listNamespaceDescriptors()) { if (ns.getName().startsWith(prefix)) { admin.deleteNamespace(ns.getName()); } } }
@Test public void testDeleteRow() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); table.put(new Put(HelloHBase.MY_ROW_ID). addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz"))); HelloHBase.deleteRow(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#deleteRow failed to delete row.", true, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); } }
@Test public void testDeleteRow() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); table.put(new Put(HelloHBase.MY_ROW_ID). addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz"))); HelloHBase.deleteRow(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#deleteRow failed to delete row.", true, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); } }
@Test public void createRemoveTest() throws Exception { String nsName = prefix + "_" + name.getMethodName(); LOG.info(name.getMethodName()); //create namespace and verify admin.createNamespace(NamespaceDescriptor.create(nsName).build()); assertEquals(3, admin.listNamespaceDescriptors().length); //remove namespace and verify admin.deleteNamespace(nsName); assertEquals(2, admin.listNamespaceDescriptors().length); }
@Test public void testPutRowToTable() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); HelloHBase.putRowToTable(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#putRowToTable failed to store row.", false, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); }
@Test public void testPutRowToTable() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); HelloHBase.putRowToTable(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#putRowToTable failed to store row.", false, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); }
@Test public void testEditsDroppedWithDroppedTableNS() throws Exception { // also try with a namespace Connection connection1 = ConnectionFactory.createConnection(conf1); try (Admin admin1 = connection1.getAdmin()) { admin1.createNamespace(NamespaceDescriptor.create("NS").build()); } Connection connection2 = ConnectionFactory.createConnection(conf2); try (Admin admin2 = connection2.getAdmin()) { admin2.createNamespace(NamespaceDescriptor.create("NS").build()); } testEditsBehindDroppedTable(true, "NS:test_dropped"); try (Admin admin1 = connection1.getAdmin()) { admin1.deleteNamespace("NS"); } try (Admin admin2 = connection2.getAdmin()) { admin2.deleteNamespace("NS"); } }
@Test public void testNamespaceExists() throws Exception { final String NONEXISTENT_NAMESPACE = "xyzpdq_nonexistent"; final String EXISTING_NAMESPACE = "pdqxyz_myExistingNamespace"; boolean exists; Admin admin = TEST_UTIL.getAdmin(); exists = HelloHBase.namespaceExists(admin, NONEXISTENT_NAMESPACE); assertEquals("#namespaceExists failed: found nonexistent namespace.", false, exists); admin.createNamespace(NamespaceDescriptor.create(EXISTING_NAMESPACE).build()); exists = HelloHBase.namespaceExists(admin, EXISTING_NAMESPACE); assertEquals("#namespaceExists failed: did NOT find existing namespace.", true, exists); admin.deleteNamespace(EXISTING_NAMESPACE); }
@Test public void testNamespaceExists() throws Exception { final String NONEXISTENT_NAMESPACE = "xyzpdq_nonexistent"; final String EXISTING_NAMESPACE = "pdqxyz_myExistingNamespace"; boolean exists; Admin admin = TEST_UTIL.getAdmin(); exists = HelloHBase.namespaceExists(admin, NONEXISTENT_NAMESPACE); assertEquals("#namespaceExists failed: found nonexistent namespace.", false, exists); admin.createNamespace(NamespaceDescriptor.create(EXISTING_NAMESPACE).build()); exists = HelloHBase.namespaceExists(admin, EXISTING_NAMESPACE); assertEquals("#namespaceExists failed: did NOT find existing namespace.", true, exists); admin.deleteNamespace(EXISTING_NAMESPACE); }
@Test public void testCreateNamespaceAndTable() throws Exception { Admin admin = TEST_UTIL.getAdmin(); HelloHBase.createNamespaceAndTable(admin); boolean namespaceExists = HelloHBase.namespaceExists(admin, HelloHBase.MY_NAMESPACE_NAME); assertEquals("#createNamespaceAndTable failed to create namespace.", true, namespaceExists); boolean tableExists = admin.tableExists(HelloHBase.MY_TABLE_NAME); assertEquals("#createNamespaceAndTable failed to create table.", true, tableExists); admin.disableTable(HelloHBase.MY_TABLE_NAME); admin.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); }
@Test public void testCreateNamespaceAndTable() throws Exception { Admin admin = TEST_UTIL.getAdmin(); HelloHBase.createNamespaceAndTable(admin); boolean namespaceExists = HelloHBase.namespaceExists(admin, HelloHBase.MY_NAMESPACE_NAME); assertEquals("#createNamespaceAndTable failed to create namespace.", true, namespaceExists); boolean tableExists = admin.tableExists(HelloHBase.MY_TABLE_NAME); assertEquals("#createNamespaceAndTable failed to create table.", true, tableExists); admin.disableTable(HelloHBase.MY_TABLE_NAME); admin.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); }
@After public void cleanup() throws Exception, KeeperException { for (HTableDescriptor table : ADMIN.listTables()) { ADMIN.disableTable(table.getTableName()); deleteTable(table.getTableName()); } for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) { if (ns.getName().startsWith(prefix)) { ADMIN.deleteNamespace(ns.getName()); } } assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster() .getMasterQuotaManager().isQuotaInitialized()); }