@Test
  public void testNamespaceOperations() throws Exception {
    admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join();
    admin.createNamespace(NamespaceDescriptor.create(prefix + "ns2").build()).join();

    // create namespace that already exists
    runWithExpectedException(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join();
        return null;
      }
    }, NamespaceExistException.class);

    // create a table in non-existing namespace
    runWithExpectedException(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        TableDescriptorBuilder tableDescriptorBuilder =
          TableDescriptorBuilder.newBuilder(TableName.valueOf("non_existing_namespace", "table1"));
        ColumnFamilyDescriptor columnFamilyDescriptor =
          ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("family1")).build();
        tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
        admin.createTable(tableDescriptorBuilder.build()).join();
        return null;
      }
    }, NamespaceNotFoundException.class);

    // get descriptor for existing namespace
    NamespaceDescriptor ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
    assertEquals(prefix + "ns1", ns1.getName());

    // get descriptor for non-existing namespace
    runWithExpectedException(new Callable<NamespaceDescriptor>() {
      @Override
      public NamespaceDescriptor call() throws Exception {
        return admin.getNamespaceDescriptor("non_existing_namespace").get();
      }
    }, NamespaceNotFoundException.class);

    // delete descriptor for existing namespace
    admin.deleteNamespace(prefix + "ns2").join();

    // delete descriptor for non-existing namespace
    runWithExpectedException(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        admin.deleteNamespace("non_existing_namespace").join();
        return null;
      }
    }, NamespaceNotFoundException.class);

    // modify namespace descriptor for existing namespace
    ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
    ns1.setConfiguration("foo", "bar");
    admin.modifyNamespace(ns1).join();
    ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
    assertEquals("bar", ns1.getConfigurationValue("foo"));

    // 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()).join();
        return null;
      }
    }, NamespaceNotFoundException.class);

    admin.deleteNamespace(prefix + "ns1").join();
  }
Class to test asynchronous namespace admin operations.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNamespaceAdminApi.java