@Test(timeout = 60000) public void testNamespaceOperations() throws IOException { admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()); admin.createNamespace(NamespaceDescriptor.create(prefix + "ns2").build()); // create namespace that already exists runWithExpectedException( new Callable<Void>() { @Override public Void call() throws Exception { admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()); return null; } }, NamespaceExistException.class); // create a table in non-existing namespace runWithExpectedException( new Callable<Void>() { @Override public Void call() throws Exception { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("non_existing_namespace", "table1")); htd.addFamily(new HColumnDescriptor("family1")); admin.createTable(htd); return null; } }, NamespaceNotFoundException.class); // get descriptor for existing namespace admin.getNamespaceDescriptor(prefix + "ns1"); // get descriptor for non-existing namespace runWithExpectedException( new Callable<NamespaceDescriptor>() { @Override public NamespaceDescriptor call() throws Exception { return admin.getNamespaceDescriptor("non_existing_namespace"); } }, NamespaceNotFoundException.class); // delete descriptor for existing namespace admin.deleteNamespace(prefix + "ns2"); // delete descriptor for non-existing namespace runWithExpectedException( new Callable<Void>() { @Override public Void call() throws Exception { admin.deleteNamespace("non_existing_namespace"); return null; } }, NamespaceNotFoundException.class); // modify namespace descriptor for existing namespace NamespaceDescriptor ns1 = admin.getNamespaceDescriptor(prefix + "ns1"); ns1.setConfiguration("foo", "bar"); admin.modifyNamespace(ns1); // modify namespace descriptor for non-existing namespace runWithExpectedException( new Callable<Void>() { @Override public Void call() throws Exception { admin.modifyNamespace(NamespaceDescriptor.create("non_existing_namespace").build()); return null; } }, NamespaceNotFoundException.class); // get table descriptors for existing namespace HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(prefix + "ns1", "table1")); htd.addFamily(new HColumnDescriptor("family1")); admin.createTable(htd); HTableDescriptor[] htds = admin.listTableDescriptorsByNamespace(prefix + "ns1"); assertNotNull("Should have not returned null", htds); assertEquals("Should have returned non-empty array", 1, htds.length); // get table descriptors for non-existing namespace runWithExpectedException( new Callable<Void>() { @Override public Void call() throws Exception { admin.listTableDescriptorsByNamespace("non_existing_namespace"); return null; } }, NamespaceNotFoundException.class); // get table names for existing namespace TableName[] tableNames = admin.listTableNamesByNamespace(prefix + "ns1"); assertNotNull("Should have not returned null", tableNames); assertEquals("Should have returned non-empty array", 1, tableNames.length); // get table names for non-existing namespace runWithExpectedException( new Callable<Void>() { @Override public Void call() throws Exception { admin.listTableNamesByNamespace("non_existing_namespace"); return null; } }, NamespaceNotFoundException.class); }