Search in sources :

Example 1 with HCatDatabase

use of org.apache.hive.hcatalog.api.HCatDatabase in project hive by apache.

the class TestCommands method testDropDatabaseCommand.

@Test
public void testDropDatabaseCommand() throws HCatException, CommandNeedRetryException {
    String dbName = "cmd_testdb";
    int evid = 999;
    Command testCmd = new DropDatabaseCommand(dbName, evid);
    assertEquals(evid, testCmd.getEventId());
    assertEquals(1, testCmd.get().size());
    assertEquals(true, testCmd.isRetriable());
    assertEquals(false, testCmd.isUndoable());
    CommandTestUtils.testCommandSerialization(testCmd);
    client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE);
    client.createDatabase(HCatCreateDBDesc.create(dbName).ifNotExists(false).build());
    HCatDatabase db = client.getDatabase(dbName);
    assertNotNull(db);
    LOG.info("About to run :" + testCmd.get().get(0));
    driver.run(testCmd.get().get(0));
    Exception onfe = null;
    try {
        HCatDatabase db_del = client.getDatabase(dbName);
    } catch (Exception e) {
        onfe = e;
    }
    assertNotNull(onfe);
    assertTrue(onfe instanceof ObjectNotFoundException);
}
Also used : HCatDatabase(org.apache.hive.hcatalog.api.HCatDatabase) Command(org.apache.hive.hcatalog.api.repl.Command) ObjectNotFoundException(org.apache.hive.hcatalog.api.ObjectNotFoundException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HCatException(org.apache.hive.hcatalog.common.HCatException) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException) ObjectNotFoundException(org.apache.hive.hcatalog.api.ObjectNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with HCatDatabase

use of org.apache.hive.hcatalog.api.HCatDatabase in project hive by apache.

the class TestCommands method testNoopReplEximCommands.

@Test
public void testNoopReplEximCommands() throws CommandNeedRetryException, IOException {
    // repl noop export on non-existant table, has repl.noop, does not error
    // import repl noop dump, no error
    int evid = 333;
    String exportLocation = TEST_PATH + File.separator + "testNoopReplExim";
    String dbName = "doesNotExist" + System.currentTimeMillis();
    String tableName = "nope" + System.currentTimeMillis();
    ExportCommand noopExportCmd = new ExportCommand(dbName, tableName, null, exportLocation, false, evid);
    LOG.info("About to run :" + noopExportCmd.get().get(0));
    CommandProcessorResponse ret = driver.run(noopExportCmd.get().get(0));
    assertEquals(ret.getResponseCode() + ":" + ret.getErrorMessage(), null, ret.getException());
    List<String> exportPaths = noopExportCmd.cleanupLocationsAfterEvent();
    assertEquals(1, exportPaths.size());
    String metadata = getMetadataContents(exportPaths.get(0));
    LOG.info("Export returned the following _metadata contents:");
    LOG.info(metadata);
    assertTrue(metadata + "did not match \"repl.noop\"=\"true\"", metadata.matches(".*\"repl.noop\":\"true\".*"));
    ImportCommand noopImportCmd = new ImportCommand(dbName, tableName, null, exportLocation, false, evid);
    LOG.info("About to run :" + noopImportCmd.get().get(0));
    CommandProcessorResponse ret2 = driver.run(noopImportCmd.get().get(0));
    assertEquals(ret2.getResponseCode() + ":" + ret2.getErrorMessage(), null, ret2.getException());
    Exception onfe = null;
    try {
        HCatDatabase d_doesNotExist = client.getDatabase(dbName);
    } catch (Exception e) {
        onfe = e;
    }
    assertNotNull(onfe);
    assertTrue(onfe instanceof ObjectNotFoundException);
}
Also used : HCatDatabase(org.apache.hive.hcatalog.api.HCatDatabase) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) ObjectNotFoundException(org.apache.hive.hcatalog.api.ObjectNotFoundException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HCatException(org.apache.hive.hcatalog.common.HCatException) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException) ObjectNotFoundException(org.apache.hive.hcatalog.api.ObjectNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 CommandNeedRetryException (org.apache.hadoop.hive.ql.CommandNeedRetryException)2 HCatDatabase (org.apache.hive.hcatalog.api.HCatDatabase)2 ObjectNotFoundException (org.apache.hive.hcatalog.api.ObjectNotFoundException)2 HCatException (org.apache.hive.hcatalog.common.HCatException)2 Test (org.junit.Test)2 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)1 Command (org.apache.hive.hcatalog.api.repl.Command)1