@Override
  public boolean dropNamespace(Namespace namespace) {
    Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels()));

    if (!isNamespace(nsPath) || namespace.isEmpty()) {
      return false;
    }

    try {
      if (fs.listStatusIterator(nsPath).hasNext()) {
        throw new NamespaceNotEmptyException("Namespace %s is not empty.", namespace);
      }

      return fs.delete(nsPath, false /* recursive */);
    } catch (IOException e) {
      throw new RuntimeIOException(e, "Namespace delete failed: %s", namespace);
    }
  }
@Test
  public void testDropNamespace() throws IOException {
    String warehouseLocation = tableDir.getAbsolutePath();
    HadoopCatalog catalog = new HadoopCatalog();
    catalog.setConf(new Configuration());
    catalog.initialize(
        "hadoop", ImmutableMap.of(CatalogProperties.WAREHOUSE_LOCATION, warehouseLocation));
    Namespace namespace1 = Namespace.of("db");
    Namespace namespace2 = Namespace.of("db", "ns1");

    TableIdentifier tbl1 = TableIdentifier.of(namespace1, "tbl1");
    TableIdentifier tbl2 = TableIdentifier.of(namespace2, "tbl1");

    Lists.newArrayList(tbl1, tbl2)
        .forEach(t -> catalog.createTable(t, SCHEMA, PartitionSpec.unpartitioned()));

    assertThatThrownBy(() -> catalog.dropNamespace(Namespace.of("db")))
        .isInstanceOf(NamespaceNotEmptyException.class)
        .hasMessage("Namespace " + namespace1 + " is not empty.");
    assertThat(catalog.dropNamespace(Namespace.of("db2")))
        .as("Should fail to drop namespace that doesn't exist")
        .isFalse();
    assertThat(catalog.dropTable(tbl1)).isTrue();
    assertThat(catalog.dropTable(tbl2)).isTrue();
    assertThat(catalog.dropNamespace(namespace2)).isTrue();
    assertThat(catalog.dropNamespace(namespace1)).isTrue();
    String metaLocation = warehouseLocation + "/" + "db";
    FileSystem fs = Util.getFs(new Path(metaLocation), catalog.getConf());
    assertThat(fs.isDirectory(new Path(metaLocation))).isFalse();
  }