private void cleanUp(String dbName, String tableName, String typeName) throws Exception { if(dbName != null && tableName != null) { client.dropTable(dbName, tableName); } if(dbName != null) { silentDropDatabase(dbName); } if(typeName != null) { client.dropType(typeName); } }
silentDropDatabase(TEST_DB1_NAME);
/** * Test table objects can be retrieved in batches */ @Test public void testGetTableObjects() throws Exception { String dbName = "db"; List<String> tableNames = Arrays.asList("table1", "table2", "table3", "table4", "table5"); // Setup silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); for (String tableName : tableNames) { createTable(dbName, tableName); } createMaterializedView(dbName, "mv1", Sets.newHashSet("db.table1", "db.table2")); // Test List<Table> tableObjs = client.getTableObjectsByName(dbName, tableNames); // Verify assertEquals(tableNames.size(), tableObjs.size()); for(Table table : tableObjs) { assertTrue(tableNames.contains(table.getTableName().toLowerCase())); } // Cleanup client.dropDatabase(dbName, true, true, true); }
silentDropDatabase(dbName); throw e; } finally { silentDropDatabase(dbName);
throw e; } finally { silentDropDatabase(dbName);
try { silentDropDatabase(TEST_DB1_NAME); silentDropDatabase(TEST_DB1_NAME);
@Test public void testDBLocationChange() throws IOException, TException { final String dbName = "alterDbLocation"; String defaultUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/default_location.db"; String newUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/new_location.db"; new DatabaseBuilder() .setName(dbName) .setLocation(defaultUri) .create(client, conf); Database db = client.getDatabase(dbName); assertEquals("Incorrect default location of the database", warehouse.getDnsPath(new Path(defaultUri)).toString(), db.getLocationUri()); db.setLocationUri(newUri); client.alterDatabase(dbName, db); db = client.getDatabase(dbName); assertEquals("Incorrect new location of the database", warehouse.getDnsPath(new Path(newUri)).toString(), db.getLocationUri()); client.dropDatabase(dbName); silentDropDatabase(dbName); }
try { silentDropDatabase(TEST_DB1_NAME); silentDropDatabase(TEST_DB2_NAME); silentDropDatabase(TEST_DB1_NAME); silentDropDatabase(TEST_DB2_NAME); } catch (Throwable e) { System.err.println(StringUtils.stringifyException(e));
silentDropDatabase(dbName1); silentDropDatabase(dbName2);
silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName)
vals3.add("p13"); silentDropDatabase(dbName);
@Test public void testCreateTableSettingId() throws Exception { String dbName = "createDb"; String tblName = "createTbl"; client.dropTable(dbName, tblName); silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); Table table = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("foo", "string") .addCol("bar", "string") .build(conf); table.setId(1); try { client.createTable(table); Assert.fail("An error should happen when setting the id" + " to create a table"); } catch (InvalidObjectException e) { Assert.assertTrue(e.getMessage().contains("Id shouldn't be set")); Assert.assertTrue(e.getMessage().contains(tblName)); } }
@Test(expected = MetaException.class) public void testGetSchemaWithNoClassDefFoundError() throws TException { String dbName = "testDb"; String tblName = "testTable"; client.dropTable(dbName, tblName); silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); Table tbl = new TableBuilder() .setDbName(dbName) .setTableName(tblName) .addCol("name", ColumnType.STRING_TYPE_NAME, "") .setSerdeLib("no.such.class") .create(client, conf); client.getSchema(dbName, tblName); }
throw e; } finally { silentDropDatabase(dbName);
throw e; } finally { silentDropDatabase(dbName);
silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName)
silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName)
@Test public void testCreateAndGetTableWithDriver() throws Exception { String dbName = "createDb"; String tblName = "createTbl"; client.dropTable(dbName, tblName); silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName) .create(client, conf); createTable(dbName, tblName); Table tblRead = client.getTable(dbName, tblName); Assert.assertTrue(tblRead.isSetId()); long firstTableId = tblRead.getId(); createTable(dbName, tblName + "_2"); Table tblRead2 = client.getTable(dbName, tblName + "_2"); Assert.assertTrue(tblRead2.isSetId()); Assert.assertNotEquals(firstTableId, tblRead2.getId()); }
silentDropDatabase(dbName); new DatabaseBuilder() .setName(dbName)
/** * Test changing owner and owner type of a database */ @Test public void testDBOwnerChange() throws TException { final String dbName = "alterDbOwner"; final String user1 = "user1"; final String user2 = "user2"; final String role1 = "role1"; silentDropDatabase(dbName); Database db = new DatabaseBuilder() .setName(dbName) .setOwnerName(user1) .setOwnerType(PrincipalType.USER) .create(client, conf); checkDbOwnerType(dbName, user1, PrincipalType.USER); db.setOwnerName(user2); client.alterDatabase(dbName, db); checkDbOwnerType(dbName, user2, PrincipalType.USER); db.setOwnerName(role1); db.setOwnerType(PrincipalType.ROLE); client.alterDatabase(dbName, db); checkDbOwnerType(dbName, role1, PrincipalType.ROLE); }