You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2013/10/04 20:54:53 UTC
svn commit: r1529259 - in /hive/branches/branch-0.12:
jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java
Author: thejas
Date: Fri Oct 4 18:54:53 2013
New Revision: 1529259
URL: http://svn.apache.org/r1529259
Log:
HIVE-4542 : TestJdbcDriver2.testMetaDataGetSchemas fails because of unexpected database (Vaibhav Gumashta & Thejas Nair via Ashutosh Chauhan)
Modified:
hive/branches/branch-0.12/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
hive/branches/branch-0.12/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java
Modified: hive/branches/branch-0.12/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.12/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java?rev=1529259&r1=1529258&r2=1529259&view=diff
==============================================================================
--- hive/branches/branch-0.12/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java (original)
+++ hive/branches/branch-0.12/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java Fri Oct 4 18:54:53 2013
@@ -20,6 +20,12 @@ package org.apache.hive.jdbc;
import static org.apache.hadoop.hive.ql.exec.ExplainTask.EXPL_COLUMN_NAME;
import static org.apache.hadoop.hive.ql.processors.SetProcessor.SET_COLUMN_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -39,8 +45,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
-import junit.framework.TestCase;
-
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.TableType;
@@ -50,13 +54,17 @@ import org.apache.hive.service.cli.opera
import org.apache.hive.service.cli.operation.ClassicTableTypeMapping.ClassicTableTypes;
import org.apache.hive.service.cli.operation.HiveTableTypeMapping;
import org.apache.hive.service.cli.operation.TableTypeMappingFactory.TableTypeMappings;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* TestJdbcDriver2
*
*/
-public class TestJdbcDriver2 extends TestCase {
+public class TestJdbcDriver2 {
private static final String driverName = "org.apache.hive.jdbc.HiveDriver";
private static final String tableName = "testHiveJdbcDriver_Table";
private static final String tableComment = "Simple table";
@@ -72,10 +80,10 @@ public class TestJdbcDriver2 extends Tes
private final Path dataFilePath;
private final Path dataTypeDataFilePath;
private Connection con;
- private boolean standAloneServer = false;
+ private static boolean standAloneServer = false;
+ private static final float floatCompareDelta = 0.0001f;
- public TestJdbcDriver2(String name) {
- super(name);
+ public TestJdbcDriver2() {
conf = new HiveConf(TestJdbcDriver2.class);
String dataFileDir = conf.get("test.data.files").replace('\\', '/')
.replace("c:", "");
@@ -85,19 +93,36 @@ public class TestJdbcDriver2 extends Tes
.getProperty("test.service.standalone.server"));
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeClass
+ public static void setUpBeforeClass() throws SQLException, ClassNotFoundException{
Class.forName(driverName);
- if (standAloneServer) {
- // get connection
- con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default",
- "", "");
- } else {
- con = DriverManager.getConnection("jdbc:hive2://", "", "");
+ Connection con1 = getConnection();
+
+ Statement stmt1 = con1.createStatement();
+ assertNotNull("Statement is null", stmt1);
+
+ stmt1.execute("set hive.support.concurrency = false");
+
+ DatabaseMetaData metadata = con1.getMetaData();
+
+ // Drop databases created by other test cases
+ ResultSet databaseRes = metadata.getSchemas();
+
+ while(databaseRes.next()){
+ String db = databaseRes.getString(1);
+ if(!db.equals("default")){
+ System.err.println("Dropping database " + db);
+ stmt1.execute("DROP DATABASE " + db + " CASCADE");
+ }
}
- assertNotNull("Connection is null", con);
- assertFalse("Connection should not be closed", con.isClosed());
+ stmt1.close();
+ con1.close();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ con = getConnection();
+
Statement stmt = con.createStatement();
assertNotNull("Statement is null", stmt);
@@ -110,7 +135,6 @@ public class TestJdbcDriver2 extends Tes
fail(ex.toString());
}
- ResultSet res;
// create table
stmt.execute("create table " + tableName
+ " (under_col int comment 'the under column', value string) comment '"
@@ -179,10 +203,23 @@ public class TestJdbcDriver2 extends Tes
+"' as select * from "+ tableName);
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ private static Connection getConnection() throws SQLException {
+ Connection con1;
+ if (standAloneServer) {
+ // get connection
+ con1 = DriverManager.getConnection("jdbc:hive2://localhost:10000/default",
+ "", "");
+ } else {
+ con1 = DriverManager.getConnection("jdbc:hive2://", "", "");
+ }
+ assertNotNull("Connection is null", con1);
+ assertFalse("Connection should not be closed", con1.isClosed());
+ return con1;
+ }
+
+ @After
+ public void tearDown() throws Exception {
// drop table
Statement stmt = con.createStatement();
assertNotNull("Statement is null", stmt);
@@ -205,6 +242,7 @@ public class TestJdbcDriver2 extends Tes
expectedException);
}
+ @Test
public void testBadURL() throws Exception {
checkBadUrl("jdbc:hive2://localhost:10000;principal=test");
checkBadUrl("jdbc:hive2://localhost:10000;" +
@@ -223,6 +261,7 @@ public class TestJdbcDriver2 extends Tes
}
}
+ @Test
public void testDataTypes2() throws Exception {
Statement stmt = con.createStatement();
@@ -238,6 +277,8 @@ public class TestJdbcDriver2 extends Tes
}
}
+
+ @Test
public void testErrorDiag() throws SQLException {
Statement stmt = con.createStatement();
@@ -268,6 +309,7 @@ public class TestJdbcDriver2 extends Tes
* verify 'explain ...' resultset
* @throws SQLException
*/
+ @Test
public void testExplainStmt() throws SQLException {
Statement stmt = con.createStatement();
@@ -276,12 +318,15 @@ public class TestJdbcDriver2 extends Tes
"c1*2, sentences(null, null, null) as b from " + dataTypeTableName + " limit 1");
ResultSetMetaData md = res.getMetaData();
- assertEquals(md.getColumnCount(), 1); // only one result column
- assertEquals(md.getColumnLabel(1), EXPL_COLUMN_NAME); // verify the column name
+ // only one result column
+ assertEquals(md.getColumnCount(), 1);
+ // verify the column name
+ assertEquals(md.getColumnLabel(1), EXPL_COLUMN_NAME);
//verify that there is data in the resultset
assertTrue("Nothing returned explain", res.next());
}
+ @Test
public void testPrepareStatement() {
String sql = "from (select count(1) from "
@@ -398,6 +443,7 @@ public class TestJdbcDriver2 extends Tes
* of PreparedStatement interface
* @throws Exception
*/
+ @Test
public void testExecutePreparedStatement() throws Exception {
String key = "testKey";
String val1 = "val1";
@@ -433,11 +479,13 @@ public class TestJdbcDriver2 extends Tes
assertEquals("Conf value should be set by execute()", expectedVal, result);
}
+ @Test
public final void testSelectAll() throws Exception {
doTestSelectAll(tableName, -1, -1); // tests not setting maxRows (return all)
doTestSelectAll(tableName, 0, -1); // tests setting maxRows to 0 (return all)
}
+ @Test
public final void testSelectAllPartioned() throws Exception {
doTestSelectAll(partitionedTableName, -1, -1); // tests not setting maxRows
// (return all)
@@ -445,14 +493,17 @@ public class TestJdbcDriver2 extends Tes
// (return all)
}
+ @Test
public final void testSelectAllMaxRows() throws Exception {
doTestSelectAll(tableName, 100, -1);
}
+ @Test
public final void testSelectAllFetchSize() throws Exception {
doTestSelectAll(tableName, 100, 20);
}
+ @Test
public void testNullType() throws Exception {
Statement stmt = con.createStatement();
try {
@@ -466,6 +517,7 @@ public class TestJdbcDriver2 extends Tes
// executeQuery should always throw a SQLException,
// when it executes a non-ResultSet query (like create)
+ @Test
public void testExecuteQueryException() throws Exception {
Statement stmt = con.createStatement();
try {
@@ -506,6 +558,7 @@ public class TestJdbcDriver2 extends Tes
fail(e.toString());
}
+ @Test
public void testNullResultSet() throws Exception {
List<String> setupQueries = new ArrayList<String>();
String testQuery;
@@ -541,6 +594,7 @@ public class TestJdbcDriver2 extends Tes
stmt.close();
}
+ @Test
public void testCloseResultSet() throws Exception {
Statement stmt = con.createStatement();
@@ -574,6 +628,7 @@ public class TestJdbcDriver2 extends Tes
assertTrue(stmt.isClosed());
}
+ @Test
public void testDataTypes() throws Exception {
Statement stmt = con.createStatement();
@@ -590,7 +645,7 @@ public class TestJdbcDriver2 extends Tes
// getXXX returns 0 for numeric types, false for boolean and null for other
assertEquals(0, res.getInt(1));
assertEquals(false, res.getBoolean(2));
- assertEquals(0d, res.getDouble(3));
+ assertEquals(0d, res.getDouble(3), floatCompareDelta);
assertEquals(null, res.getString(4));
assertEquals(null, res.getString(5));
assertEquals(null, res.getString(6));
@@ -598,7 +653,7 @@ public class TestJdbcDriver2 extends Tes
assertEquals(null, res.getString(8));
assertEquals(0, res.getByte(9));
assertEquals(0, res.getShort(10));
- assertEquals(0f, res.getFloat(11));
+ assertEquals(0f, res.getFloat(11), floatCompareDelta);
assertEquals(0L, res.getLong(12));
assertEquals(null, res.getString(13));
assertEquals(null, res.getString(14));
@@ -615,7 +670,7 @@ public class TestJdbcDriver2 extends Tes
assertTrue(res.next());
assertEquals(-1, res.getInt(1));
assertEquals(false, res.getBoolean(2));
- assertEquals(-1.1d, res.getDouble(3));
+ assertEquals(-1.1d, res.getDouble(3), floatCompareDelta);
assertEquals("", res.getString(4));
assertEquals("[]", res.getString(5));
assertEquals("{}", res.getString(6));
@@ -623,7 +678,7 @@ public class TestJdbcDriver2 extends Tes
assertEquals("{\"r\":null,\"s\":null,\"t\":null}", res.getString(8));
assertEquals(-1, res.getByte(9));
assertEquals(-1, res.getShort(10));
- assertEquals(-1.0f, res.getFloat(11));
+ assertEquals(-1.0f, res.getFloat(11), floatCompareDelta);
assertEquals(-1, res.getLong(12));
assertEquals("[]", res.getString(13));
assertEquals("{}", res.getString(14));
@@ -641,7 +696,7 @@ public class TestJdbcDriver2 extends Tes
assertTrue(res.next());
assertEquals(1, res.getInt(1));
assertEquals(true, res.getBoolean(2));
- assertEquals(1.1d, res.getDouble(3));
+ assertEquals(1.1d, res.getDouble(3), floatCompareDelta);
assertEquals("1", res.getString(4));
assertEquals("[1,2]", res.getString(5));
assertEquals("{1:\"x\",2:\"y\"}", res.getString(6));
@@ -649,7 +704,7 @@ public class TestJdbcDriver2 extends Tes
assertEquals("{\"r\":\"a\",\"s\":9,\"t\":2.2}", res.getString(8));
assertEquals(1, res.getByte(9));
assertEquals(1, res.getShort(10));
- assertEquals(1.0f, res.getFloat(11));
+ assertEquals(1.0f, res.getFloat(11), floatCompareDelta);
assertEquals(1, res.getLong(12));
assertEquals("[[\"a\",\"b\"],[\"c\",\"d\"]]", res.getString(13));
assertEquals("{1:{11:12,13:14},2:{21:22}}", res.getString(14));
@@ -759,6 +814,7 @@ public class TestJdbcDriver2 extends Tes
assertTrue("Statement should be closed", stmt.isClosed());
}
+ @Test
public void testErrorMessages() throws SQLException {
String invalidSyntaxSQLState = "42000";
@@ -807,6 +863,7 @@ public class TestJdbcDriver2 extends Tes
exceptionFound);
}
+ @Test
public void testShowTables() throws SQLException {
Statement stmt = con.createStatement();
assertNotNull("Statement is null", stmt);
@@ -825,10 +882,12 @@ public class TestJdbcDriver2 extends Tes
+ " not found in SHOW TABLES result set", testTableExists);
}
+ @Test
public void testMetaDataGetTables() throws SQLException {
getTablesTest(ClassicTableTypes.TABLE.toString(), ClassicTableTypes.VIEW.toString());
}
+ @Test
public void testMetaDataGetTablesHive() throws SQLException {
Statement stmt = con.createStatement();
stmt.execute("set " + HiveConf.ConfVars.HIVE_SERVER2_TABLE_TYPE_MAPPING.varname +
@@ -836,6 +895,7 @@ public class TestJdbcDriver2 extends Tes
getTablesTest(TableType.MANAGED_TABLE.toString(), TableType.VIRTUAL_VIEW.toString());
}
+ @Test
public void testMetaDataGetTablesClassic() throws SQLException {
Statement stmt = con.createStatement();
stmt.execute("set " + HiveConf.ConfVars.HIVE_SERVER2_TABLE_TYPE_MAPPING.varname +
@@ -907,6 +967,7 @@ public class TestJdbcDriver2 extends Tes
assertEquals("Incorrect number of views found.", 1, cnt);
}
+ @Test
public void testMetaDataGetCatalogs() throws SQLException {
ResultSet rs = (ResultSet)con.getMetaData().getCatalogs();
ResultSetMetaData resMeta = rs.getMetaData();
@@ -916,6 +977,7 @@ public class TestJdbcDriver2 extends Tes
assertFalse(rs.next());
}
+ @Test
public void testMetaDataGetSchemas() throws SQLException {
ResultSet rs = (ResultSet)con.getMetaData().getSchemas();
ResultSetMetaData resMeta = rs.getMetaData();
@@ -925,20 +987,21 @@ public class TestJdbcDriver2 extends Tes
assertTrue(rs.next());
assertEquals("default", rs.getString(1));
- // assertNull(rs.getString(2));
assertFalse(rs.next());
rs.close();
}
- //test default table types returned in
+ // test default table types returned in
// Connection.getMetaData().getTableTypes()
+ @Test
public void testMetaDataGetTableTypes() throws SQLException {
metaDataGetTableTypeTest(new ClassicTableTypeMapping().getTableTypeNames());
}
- //test default table types returned in
+ // test default table types returned in
// Connection.getMetaData().getTableTypes() when type config is set to "HIVE"
+ @Test
public void testMetaDataGetHiveTableTypes() throws SQLException {
Statement stmt = con.createStatement();
stmt.execute("set " + HiveConf.ConfVars.HIVE_SERVER2_TABLE_TYPE_MAPPING.varname +
@@ -947,8 +1010,9 @@ public class TestJdbcDriver2 extends Tes
metaDataGetTableTypeTest(new HiveTableTypeMapping().getTableTypeNames());
}
- //test default table types returned in
+ // test default table types returned in
// Connection.getMetaData().getTableTypes() when type config is set to "CLASSIC"
+ @Test
public void testMetaDataGetClassicTableTypes() throws SQLException {
Statement stmt = con.createStatement();
stmt.execute("set " + HiveConf.ConfVars.HIVE_SERVER2_TABLE_TYPE_MAPPING.varname +
@@ -979,6 +1043,7 @@ public class TestJdbcDriver2 extends Tes
assertTrue("Found less tabletypes then we test for.", cnt >= tabletypes.size());
}
+ @Test
public void testMetaDataGetColumns() throws SQLException {
Map<String[], Integer> tests = new HashMap<String[], Integer>();
tests.put(new String[]{"testhivejdbcdriver\\_table", null}, 2);
@@ -1027,6 +1092,7 @@ public class TestJdbcDriver2 extends Tes
/**
* Validate the Metadata for the result set of a metadata getColumns call.
*/
+ @Test
public void testMetaDataGetColumnsMetaData() throws SQLException {
ResultSet rs = (ResultSet)con.getMetaData().getColumns(null, null
, "testhivejdbcdriver\\_table", null);
@@ -1084,6 +1150,7 @@ public class TestJdbcDriver2 extends Tes
}
*/
+ @Test
public void testDescribeTable() throws SQLException {
Statement stmt = con.createStatement();
assertNotNull("Statement is null", stmt);
@@ -1102,6 +1169,7 @@ public class TestJdbcDriver2 extends Tes
assertFalse("More results found than expected", res.next());
}
+ @Test
public void testDatabaseMetaData() throws SQLException {
DatabaseMetaData meta = con.getMetaData();
@@ -1120,12 +1188,13 @@ public class TestJdbcDriver2 extends Tes
assertTrue(meta.supportsAlterTableWithAddColumn());
}
+ @Test
public void testResultSetMetaData() throws SQLException {
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery(
"select c1, c2, c3, c4, c5 as a, c6, c7, c8, c9, c10, c11, c12, " +
- "c1*2, sentences(null, null, null) as b, c17, c18, c20, c21 from " + dataTypeTableName +
+ "c1*2, sentences(null, null, null) as b, c17, c18, c20, c21 from " + dataTypeTableName +
" limit 1");
ResultSetMetaData meta = res.getMetaData();
@@ -1370,6 +1439,7 @@ public class TestJdbcDriver2 extends Tes
"server", "10002", "db"},
};
+ @Test
public void testDriverProperties() throws SQLException {
HiveDriver driver = new HiveDriver();
for (String[] testValues : URL_PROPERTIES) {
@@ -1386,12 +1456,13 @@ public class TestJdbcDriver2 extends Tes
"user=foo;password=bar?" +
"hive.server2.transport.mode=http;" +
"hive.server2.thrift.http.path=hs2", "server", "10002", "db", "http", "hs2"},
- {"jdbc:hive2://server:10000/testdb;" +
- "user=foo;password=bar?" +
- "hive.server2.transport.mode=binary;" +
- "hive.server2.thrift.http.path=", "server", "10000", "testdb", "binary", ""},
+ {"jdbc:hive2://server:10000/testdb;" +
+ "user=foo;password=bar?" +
+ "hive.server2.transport.mode=binary;" +
+ "hive.server2.thrift.http.path=", "server", "10000", "testdb", "binary", ""},
};
+ @Test
public void testParseUrlHttpMode() throws SQLException {
HiveDriver driver = new HiveDriver();
for (String[] testValues : HTTP_URL_PROPERTIES) {
@@ -1416,6 +1487,7 @@ public class TestJdbcDriver2 extends Tes
* validate schema generated by "set" command
* @throws SQLException
*/
+ @Test
public void testSetCommand() throws SQLException {
// execute set command
String sql = "set -v";
@@ -1438,6 +1510,7 @@ public class TestJdbcDriver2 extends Tes
* Validate error on closed resultset
* @throws SQLException
*/
+ @Test
public void testPostClose() throws SQLException {
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select * from " + tableName);
@@ -1455,6 +1528,7 @@ public class TestJdbcDriver2 extends Tes
* The JDBC spec says when you have duplicate column names,
* the first one should be returned.
*/
+ @Test
public void testDuplicateColumnNameOrder() throws SQLException {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1 AS a, 2 AS a from " + tableName);
@@ -1467,6 +1541,7 @@ public class TestJdbcDriver2 extends Tes
* Test bad args to getXXX()
* @throws SQLException
*/
+ @Test
public void testOutOfBoundCols() throws SQLException {
Statement stmt = con.createStatement();
@@ -1492,6 +1567,7 @@ public class TestJdbcDriver2 extends Tes
* Verify selecting using builtin UDFs
* @throws SQLException
*/
+ @Test
public void testBuiltInUDFCol() throws SQLException {
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select c12, bin(c12) from " + dataTypeTableName
@@ -1509,6 +1585,7 @@ public class TestJdbcDriver2 extends Tes
* Verify selecting named expression columns
* @throws SQLException
*/
+ @Test
public void testExprCol() throws SQLException {
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select c1+1 as col1, length(c4) as len from " + dataTypeTableName
@@ -1527,6 +1604,7 @@ public class TestJdbcDriver2 extends Tes
* test getProcedureColumns()
* @throws SQLException
*/
+ @Test
public void testProcCols() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
@@ -1541,6 +1619,7 @@ public class TestJdbcDriver2 extends Tes
* test testProccedures()
* @throws SQLException
*/
+ @Test
public void testProccedures() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
@@ -1555,6 +1634,7 @@ public class TestJdbcDriver2 extends Tes
* test getPrimaryKeys()
* @throws SQLException
*/
+ @Test
public void testPrimaryKeys() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
@@ -1569,6 +1649,7 @@ public class TestJdbcDriver2 extends Tes
* test getImportedKeys()
* @throws SQLException
*/
+ @Test
public void testImportedKeys() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
@@ -1583,12 +1664,10 @@ public class TestJdbcDriver2 extends Tes
* If the Driver implementation understands the URL, it will return a Connection object;
* otherwise it returns null
*/
+ @Test
public void testInvalidURL() throws Exception {
HiveDriver driver = new HiveDriver();
Connection conn = driver.connect("jdbc:derby://localhost:10000/default", new Properties());
assertNull(conn);
}
-
-
-
}
Modified: hive/branches/branch-0.12/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.12/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java?rev=1529259&r1=1529258&r2=1529259&view=diff
==============================================================================
--- hive/branches/branch-0.12/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java (original)
+++ hive/branches/branch-0.12/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java Fri Oct 4 18:54:53 2013
@@ -19,6 +19,7 @@ package org.apache.hadoop.hive.ql.metada
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,8 +48,8 @@ public class TestHiveMetaStoreChecker ex
private FileSystem fs;
private HiveMetaStoreChecker checker = null;
- private final String dbName = "dbname";
- private final String tableName = "tablename";
+ private final String dbName = "testhivemetastorechecker_db";
+ private final String tableName = "testhivemetastorechecker_table";
private final String partDateName = "partdate";
private final String partCityName = "partcity";
@@ -76,17 +77,25 @@ public class TestHiveMetaStoreChecker ex
part2.put(partCityName, "stockholm");
parts.add(part2);
+ //cleanup just in case something is left over from previous run
+ dropDbTable();
+ }
+
+ private void dropDbTable() {
// cleanup
- hive.dropTable(dbName, tableName, true, true);
try {
- hive.dropDatabase(dbName);
+ hive.dropTable(dbName, tableName, true, true);
+ hive.dropDatabase(dbName, true, true, true);
} catch (NoSuchObjectException e) {
// ignore
+ } catch (HiveException e) {
+ // ignore
}
}
@Override
protected void tearDown() throws Exception {
+ dropDbTable();
super.tearDown();
Hive.closeCurrent();
}
@@ -97,19 +106,19 @@ public class TestHiveMetaStoreChecker ex
CheckResult result = new CheckResult();
checker.checkMetastore(dbName, null, null, result);
// we haven't added anything so should return an all ok
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
// check table only, should not exist in ms
result = new CheckResult();
checker.checkMetastore(dbName, tableName, null, result);
assertEquals(1, result.getTablesNotInMs().size());
assertEquals(tableName, result.getTablesNotInMs().get(0));
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
Database db = new Database();
db.setName(dbName);
@@ -125,18 +134,18 @@ public class TestHiveMetaStoreChecker ex
// first check all (1) tables
result = new CheckResult();
checker.checkMetastore(dbName, null, null, result);
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
// then let's check the one we know about
result = new CheckResult();
checker.checkMetastore(dbName, tableName, null, result);
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
// remove the table folder
fs = table.getPath().getFileSystem(hive.getConf());
@@ -145,26 +154,27 @@ public class TestHiveMetaStoreChecker ex
// now this shouldn't find the path on the fs
result = new CheckResult();
checker.checkMetastore(dbName, tableName, null, result);
- assertTrue(result.getTablesNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());;
assertEquals(1, result.getTablesNotOnFs().size());
assertEquals(tableName, result.getTablesNotOnFs().get(0));
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
// put it back and one additional table
fs.mkdirs(table.getPath());
Path fakeTable = table.getPath().getParent().suffix(
Path.SEPARATOR + "faketable");
fs.mkdirs(fakeTable);
+ fs.deleteOnExit(fakeTable);
// find the extra table
result = new CheckResult();
checker.checkMetastore(dbName, null, null, result);
assertEquals(1, result.getTablesNotInMs().size());
assertEquals(fakeTable.getName(), result.getTablesNotInMs().get(0));
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
// create a new external table
hive.dropTable(dbName, tableName);
@@ -174,10 +184,10 @@ public class TestHiveMetaStoreChecker ex
// should return all ok
result = new CheckResult();
checker.checkMetastore(dbName, null, null, result);
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
}
public void testPartitionsCheck() throws HiveException, MetaException,
@@ -203,10 +213,10 @@ public class TestHiveMetaStoreChecker ex
CheckResult result = new CheckResult();
checker.checkMetastore(dbName, tableName, null, result);
// all is well
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
List<Partition> partitions = hive.getPartitions(table);
assertEquals(2, partitions.size());
@@ -218,24 +228,24 @@ public class TestHiveMetaStoreChecker ex
result = new CheckResult();
checker.checkMetastore(dbName, tableName, null, result);
// missing one partition on fs
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
assertEquals(1, result.getPartitionsNotOnFs().size());
assertEquals(partToRemove.getName(), result.getPartitionsNotOnFs().get(0)
.getPartitionName());
assertEquals(partToRemove.getTable().getTableName(), result
.getPartitionsNotOnFs().get(0).getTableName());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
List<Map<String, String>> partsCopy = new ArrayList<Map<String, String>>();
partsCopy.add(partitions.get(1).getSpec());
// check only the partition that exists, all should be well
result = new CheckResult();
checker.checkMetastore(dbName, tableName, partsCopy, result);
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotInMs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs());
// put the other one back
fs.mkdirs(partToRemovePath);
@@ -244,15 +254,60 @@ public class TestHiveMetaStoreChecker ex
Path fakePart = new Path(table.getDataLocation().toString(),
"fakepartition=fakevalue");
fs.mkdirs(fakePart);
+ fs.deleteOnExit(fakePart);
checker.checkMetastore(dbName, tableName, null, result);
// one extra partition
- assertTrue(result.getTablesNotInMs().isEmpty());
- assertTrue(result.getTablesNotOnFs().isEmpty());
- assertTrue(result.getPartitionsNotOnFs().isEmpty());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
assertEquals(1, result.getPartitionsNotInMs().size());
assertEquals(fakePart.getName(), result.getPartitionsNotInMs().get(0)
.getPartitionName());
+
+ // cleanup
+ hive.dropTable(dbName, tableName, true, true);
+ hive.createTable(table);
+ result = new CheckResult();
+ checker.checkMetastore(dbName, null, null, result);
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotInMs());
+ assertEquals(Collections.<String>emptyList(), result.getTablesNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotOnFs());
+ assertEquals(Collections.<String>emptyList(), result.getPartitionsNotInMs()); //--0e
+ System.err.println("Test completed - partition check");
+
}
+ public void testDataDeletion() throws HiveException, MetaException,
+ IOException, TException, AlreadyExistsException, NoSuchObjectException {
+
+ Database db = new Database();
+ db.setName(dbName);
+ hive.createDatabase(db);
+
+ Table table = new Table(dbName, tableName);
+ table.setDbName(dbName);
+ table.setInputFormatClass(TextInputFormat.class);
+ table.setOutputFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ table.setPartCols(partCols);
+
+ hive.createTable(table);
+ table = hive.getTable(dbName, tableName);
+
+ Path fakeTable = table.getPath().getParent().suffix(
+ Path.SEPARATOR + "faketable");
+ fs = fakeTable.getFileSystem(hive.getConf());
+ fs.mkdirs(fakeTable);
+ fs.deleteOnExit(fakeTable);
+
+ Path fakePart = new Path(table.getDataLocation().toString(),
+ "fakepartition=fakevalue");
+ fs.mkdirs(fakePart);
+ fs.deleteOnExit(fakePart);
+
+ hive.dropTable(dbName, tableName, true, true);
+ assertFalse(fs.exists(fakePart));
+ hive.dropDatabase(dbName);
+ assertFalse(fs.exists(fakeTable));
+ }
}