예제 #1
0
  @Test
  public void createTableTest() throws IOException, InterruptedException {
    String testName = "createTableTest";
    String nsName = prefix + "_" + testName;
    LOG.info(testName);

    HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(nsName + ":my_table"));
    HColumnDescriptor colDesc = new HColumnDescriptor("my_cf");
    desc.addFamily(colDesc);
    try {
      admin.createTable(desc);
      fail("Expected no namespace exists exception");
    } catch (NamespaceNotFoundException ex) {
    }
    // create table and in new namespace
    admin.createNamespace(NamespaceDescriptor.create(nsName).build());
    admin.createTable(desc);
    TEST_UTIL.waitTableAvailable(desc.getTableName().getName(), 10000);
    FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
    assertTrue(
        fs.exists(
            new Path(
                master.getMasterFileSystem().getRootDir(),
                new Path(
                    HConstants.BASE_NAMESPACE_DIR,
                    new Path(nsName, desc.getTableName().getQualifierAsString())))));
    assertEquals(1, admin.listTables().length);

    // verify non-empty namespace can't be removed
    try {
      admin.deleteNamespace(nsName);
      fail("Expected non-empty namespace constraint exception");
    } catch (Exception ex) {
      LOG.info("Caught expected exception: " + ex);
    }

    // sanity check try to write and read from table
    Table table = TEST_UTIL.getConnection().getTable(desc.getTableName());
    Put p = new Put(Bytes.toBytes("row1"));
    p.add(Bytes.toBytes("my_cf"), Bytes.toBytes("my_col"), Bytes.toBytes("value1"));
    table.put(p);
    // flush and read from disk to make sure directory changes are working
    admin.flush(desc.getTableName());
    Get g = new Get(Bytes.toBytes("row1"));
    assertTrue(table.exists(g));

    // normal case of removing namespace
    TEST_UTIL.deleteTable(desc.getTableName());
    admin.deleteNamespace(nsName);
  }
    @Override
    void perform() throws IOException {
      NamespaceDescriptor selected = selectNamespace(namespaceMap);
      if (selected == null) {
        return;
      }

      Admin admin = connection.getAdmin();
      try {
        String namespaceName = selected.getName();
        LOG.info("Deleting namespace :" + selected);
        admin.deleteNamespace(namespaceName);
        try {
          if (admin.getNamespaceDescriptor(namespaceName) != null) {
            // the namespace still exists.
            Assert.assertTrue("Namespace: " + selected + " was not deleted", false);
          } else {
            LOG.info("Deleted namespace :" + selected);
          }
        } catch (NamespaceNotFoundException nsnfe) {
          // This is expected result
          LOG.info("Deleted namespace :" + selected);
        }
      } catch (Exception e) {
        LOG.warn("Caught exception in action: " + this.getClass());
        throw e;
      } finally {
        admin.close();
      }
      verifyNamespaces();
    }
예제 #3
0
 @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());
     }
   }
 }
예제 #4
0
  @Test
  public void testDeleteReservedNS() throws Exception {
    boolean exceptionCaught = false;
    try {
      admin.deleteNamespace(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR);
    } catch (IOException exp) {
      LOG.warn(exp);
      exceptionCaught = true;
    } finally {
      assertTrue(exceptionCaught);
    }

    try {
      admin.deleteNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR);
    } catch (IOException exp) {
      LOG.warn(exp);
      exceptionCaught = true;
    } finally {
      assertTrue(exceptionCaught);
    }
  }
  @Override
  public void cleanUpCluster() throws Exception {
    if (!keepObjectsAtTheEnd) {
      Admin admin = util.getAdmin();
      admin.disableTables("ittable-\\d+");
      admin.deleteTables("ittable-\\d+");
      NamespaceDescriptor[] nsds = admin.listNamespaceDescriptors();
      for (NamespaceDescriptor nsd : nsds) {
        if (nsd.getName().matches("itnamespace\\d+")) {
          LOG.info("Removing namespace=" + nsd.getName());
          admin.deleteNamespace(nsd.getName());
        }
      }
    }

    enabledTables.clear();
    disabledTables.clear();
    deletedTables.clear();
    namespaceMap.clear();

    Connection connection = getConnection();
    connection.close();
    super.cleanUpCluster();
  }
예제 #6
0
  @Test
  public void createRemoveTest() throws Exception {
    String testName = "createRemoveTest";
    String nsName = prefix + "_" + testName;
    LOG.info(testName);

    // create namespace and verify
    admin.createNamespace(NamespaceDescriptor.create(nsName).build());
    assertEquals(3, admin.listNamespaceDescriptors().length);
    TEST_UTIL.waitFor(
        60000,
        new Waiter.Predicate<Exception>() {
          @Override
          public boolean evaluate() throws Exception {
            return zkNamespaceManager.list().size() == 3;
          }
        });
    assertNotNull(zkNamespaceManager.get(nsName));
    // remove namespace and verify
    admin.deleteNamespace(nsName);
    assertEquals(2, admin.listNamespaceDescriptors().length);
    assertEquals(2, zkNamespaceManager.list().size());
    assertNull(zkNamespaceManager.get(nsName));
  }
예제 #7
0
  @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);
  }