diff --git a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java index a99268a..fcfd0b9 100644 --- a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -20,6 +20,12 @@ 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; @@ -43,13 +49,17 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hive.common.util.HiveVersionInfo; +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"; @@ -65,10 +75,10 @@ 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:", ""); @@ -78,23 +88,48 @@ public TestJdbcDriver2(String name) { .getProperty("test.service.standalone.server")); } - protected void setupConnection() throws SQLException { + + @BeforeClass + public static void oneTimeSetup() throws SQLException, ClassNotFoundException{ + Class.forName(driverName); + + Connection con1 = getConnection(); + DatabaseMetaData metadata = con1.getMetaData(); + + //drop databases created by other test cases + ResultSet databaseRes = metadata.getSchemas(); + Statement stmt = con1.createStatement(); + while(databaseRes.next()){ + String db = databaseRes.getString(1); + if(!db.equals("default")){ + System.err.println("Dropping database " + db); + stmt.execute("DROP DATABASE " + db + " CASCADE"); + } + } + stmt.close(); + con1.close(); + } + + + protected static Connection getConnection() throws SQLException { + Connection con1; if (standAloneServer) { // get connection - con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", + con1 = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "", ""); } else { - con = DriverManager.getConnection("jdbc:hive2://", "", ""); + con1 = DriverManager.getConnection("jdbc:hive2://", "", ""); } - assertNotNull("Connection is null", con); - assertFalse("Connection should not be closed", con.isClosed()); + assertNotNull("Connection is null", con1); + assertFalse("Connection should not be closed", con1.isClosed()); - Statement stmt = con.createStatement(); + Statement stmt = con1.createStatement(); assertNotNull("Statement is null", stmt); stmt.execute("set hive.support.concurrency = false"); stmt.close(); + return con1; } protected void resetConnection() throws SQLException { @@ -104,20 +139,17 @@ protected void resetConnection() throws SQLException { con = null; } - setupConnection(); + con = getConnection(); } catch (SQLException e) { e.printStackTrace(); throw e; } } - @Override - protected void setUp() throws Exception { - super.setUp(); - - Class.forName(driverName); + @Before + public void setUp() throws Exception { - setupConnection(); + con = getConnection(); Statement stmt = con.createStatement(); assertNotNull("Statement is null", stmt); @@ -131,7 +163,6 @@ protected void setUp() throws Exception { fail(ex.toString()); } - ResultSet res; // create table stmt.execute("create table " + tableName + " (under_col int comment 'the under column', value string) comment '" @@ -197,9 +228,8 @@ protected void setUp() throws Exception { +"' as select * from "+ tableName); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { // drop table Statement stmt = con.createStatement(); @@ -223,6 +253,7 @@ protected void tearDown() throws Exception { expectedException); } + @Test public void testBadURL() throws Exception { Class.forName(driverName); try{ @@ -236,6 +267,7 @@ public void testBadURL() throws Exception { } + @Test public void testDataTypes2() throws Exception { Statement stmt = con.createStatement(); @@ -251,6 +283,8 @@ public void testDataTypes2() throws Exception { } } + + @Test public void testErrorDiag() throws SQLException { Statement stmt = con.createStatement(); @@ -281,6 +315,7 @@ public void testErrorDiag() throws SQLException { * verify 'explain ...' resultset * @throws SQLException */ + @Test public void testExplainStmt() throws SQLException { Statement stmt = con.createStatement(); @@ -295,6 +330,7 @@ public void testExplainStmt() throws SQLException { assertTrue("Nothing returned explain", res.next()); } + @Test public void testPrepareStatement() { String sql = "from (select count(1) from " @@ -404,11 +440,13 @@ public void testPrepareStatement() { expectedException); } + @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) @@ -416,14 +454,17 @@ public final void testSelectAllPartioned() throws Exception { // (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 { @@ -435,6 +476,7 @@ public void testNullType() throws Exception { } } + @Test public void testDataTypes() throws Exception { Statement stmt = con.createStatement(); @@ -451,7 +493,7 @@ public void testDataTypes() throws Exception { // 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)); @@ -459,7 +501,7 @@ public void testDataTypes() throws Exception { 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)); @@ -473,7 +515,7 @@ public void testDataTypes() throws Exception { 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)); @@ -481,7 +523,7 @@ public void testDataTypes() throws Exception { 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)); @@ -496,7 +538,7 @@ public void testDataTypes() throws Exception { 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)); @@ -504,7 +546,7 @@ public void testDataTypes() throws Exception { 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)); @@ -611,6 +653,7 @@ private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throw assertTrue("Statement should be closed", stmt.isClosed()); } + @Test public void testErrorMessages() throws SQLException { String invalidSyntaxSQLState = "42000"; @@ -659,6 +702,7 @@ private void doTestErrorCase(String sql, String expectedMessage, exceptionFound); } + @Test public void testShowTables() throws SQLException { Statement stmt = con.createStatement(); assertNotNull("Statement is null", stmt); @@ -677,6 +721,7 @@ public void testShowTables() throws SQLException { + " not found in SHOW TABLES result set", testTableExists); } + @Test public void testMetaDataGetTables() throws SQLException { Map tests = new HashMap(); tests.put("test%jdbc%", new Object[]{"testhivejdbcdriver_table" @@ -731,6 +776,7 @@ public void testMetaDataGetTables() throws SQLException { assertEquals("Incorrect number of views found.", 1, cnt); } + @Test public void testMetaDataGetCatalogs() throws SQLException { ResultSet rs = (ResultSet)con.getMetaData().getCatalogs(); ResultSetMetaData resMeta = rs.getMetaData(); @@ -740,6 +786,7 @@ public void testMetaDataGetCatalogs() throws SQLException { assertFalse(rs.next()); } + @Test public void testMetaDataGetSchemas() throws SQLException { ResultSet rs = (ResultSet)con.getMetaData().getSchemas(); ResultSetMetaData resMeta = rs.getMetaData(); @@ -749,12 +796,11 @@ public void testMetaDataGetSchemas() throws SQLException { assertTrue(rs.next()); assertEquals("default", rs.getString(1)); -// assertNull(rs.getString(2)); - assertFalse(rs.next()); rs.close(); } + @Test public void testMetaDataGetTableTypes() throws SQLException { ResultSet rs = (ResultSet)con.getMetaData().getTableTypes(); @@ -776,6 +822,7 @@ public void testMetaDataGetTableTypes() throws SQLException { assertTrue("Found less tabletypes then we test for.", cnt >= tabletypes.size()); } + @Test public void testMetaDataGetColumns() throws SQLException { Map tests = new HashMap(); tests.put(new String[]{"testhivejdbcdriver\\_table", null}, 2); @@ -824,6 +871,7 @@ public void testMetaDataGetColumns() throws SQLException { /** * 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); @@ -881,6 +929,7 @@ public boolean next() throws SQLException { } */ + @Test public void testDescribeTable() throws SQLException { Statement stmt = con.createStatement(); assertNotNull("Statement is null", stmt); @@ -920,6 +969,7 @@ private boolean hasTable(String t, Statement stmt) throws SQLException { * Test if default database gets reset on connection reset * @throws SQLException */ + @Test public void testConnectionReset() throws SQLException { Statement stmt = null; @@ -957,6 +1007,7 @@ public void testConnectionReset() throws SQLException { } } + @Test public void testDatabaseMetaData() throws SQLException { DatabaseMetaData meta = con.getMetaData(); @@ -975,6 +1026,7 @@ public void testDatabaseMetaData() throws SQLException { assertTrue(meta.supportsAlterTableWithAddColumn()); } + @Test public void testResultSetMetaData() throws SQLException { Statement stmt = con.createStatement(); @@ -1201,6 +1253,7 @@ public void testResultSetMetaData() throws SQLException { {"jdbc:hive2://localhost/notdefault", "localhost", "10000", "notdefault"}, {"jdbc:hive2://foo:1243", "foo", "1243", "default"}}; + @Test public void testDriverProperties() throws SQLException { HiveDriver driver = new HiveDriver(); @@ -1226,6 +1279,7 @@ private static void assertDpi(DriverPropertyInfo dpi, String name, * validate schema generated by "set" command * @throws SQLException */ + @Test public void testSetCommand() throws SQLException { // execute set command String sql = "set -v"; @@ -1248,6 +1302,7 @@ public void testSetCommand() throws SQLException { * Validate error on closed resultset * @throws SQLException */ + @Test public void testPostClose() throws SQLException { Statement stmt = con.createStatement(); ResultSet res = stmt.executeQuery("select * from " + tableName); @@ -1265,6 +1320,7 @@ public void testPostClose() throws SQLException { * 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); @@ -1277,6 +1333,7 @@ public void testDuplicateColumnNameOrder() throws SQLException { * Test bad args to getXXX() * @throws SQLException */ + @Test public void testOutOfBoundCols() throws SQLException { Statement stmt = con.createStatement(); @@ -1302,6 +1359,7 @@ public void testOutOfBoundCols() throws SQLException { * 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 @@ -1319,6 +1377,7 @@ public void testBuiltInUDFCol() throws SQLException { * 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 @@ -1337,6 +1396,7 @@ public void testExprCol() throws SQLException { * test getProcedureColumns() * @throws SQLException */ + @Test public void testProcCols() throws SQLException { DatabaseMetaData dbmd = con.getMetaData(); assertNotNull(dbmd); @@ -1351,6 +1411,7 @@ public void testProcCols() throws SQLException { * test testProccedures() * @throws SQLException */ + @Test public void testProccedures() throws SQLException { DatabaseMetaData dbmd = con.getMetaData(); assertNotNull(dbmd); @@ -1365,6 +1426,7 @@ public void testProccedures() throws SQLException { * test getPrimaryKeys() * @throws SQLException */ + @Test public void testPrimaryKeys() throws SQLException { DatabaseMetaData dbmd = con.getMetaData(); assertNotNull(dbmd); @@ -1379,6 +1441,7 @@ public void testPrimaryKeys() throws SQLException { * test getImportedKeys() * @throws SQLException */ + @Test public void testImportedKeys() throws SQLException { DatabaseMetaData dbmd = con.getMetaData(); assertNotNull(dbmd); @@ -1393,6 +1456,7 @@ public void testImportedKeys() throws SQLException { * 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()); diff --git a/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java b/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java index 6490b89..69d1896 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java @@ -19,6 +19,7 @@ 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 @@ 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 @@ protected void setUp() throws Exception { 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 void testTableCheck() throws HiveException, MetaException, 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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.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.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotInMs()); Database db = new Database(); db.setName(dbName); @@ -125,18 +134,18 @@ public void testTableCheck() throws HiveException, MetaException, // 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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotInMs()); // remove the table folder fs = table.getPath().getFileSystem(hive.getConf()); @@ -145,26 +154,27 @@ public void testTableCheck() throws HiveException, MetaException, // 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.emptyList(), result.getTablesNotInMs());; assertEquals(1, result.getTablesNotOnFs().size()); assertEquals(tableName, result.getTablesNotOnFs().get(0)); - assertTrue(result.getPartitionsNotOnFs().isEmpty()); - assertTrue(result.getPartitionsNotInMs().isEmpty()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.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.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotInMs()); // create a new external table hive.dropTable(dbName, tableName); @@ -174,10 +184,10 @@ public void testTableCheck() throws HiveException, MetaException, // 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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotInMs()); } public void testPartitionsCheck() throws HiveException, MetaException, @@ -203,10 +213,10 @@ public void testPartitionsCheck() throws HiveException, MetaException, 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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotInMs()); List partitions = hive.getPartitions(table); assertEquals(2, partitions.size()); @@ -218,24 +228,24 @@ public void testPartitionsCheck() throws HiveException, MetaException, result = new CheckResult(); checker.checkMetastore(dbName, tableName, null, result); // missing one partition on fs - assertTrue(result.getTablesNotInMs().isEmpty()); - assertTrue(result.getTablesNotOnFs().isEmpty()); + assertEquals(Collections.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.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.emptyList(), result.getPartitionsNotInMs()); List> partsCopy = new ArrayList>(); 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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotInMs()); // put the other one back fs.mkdirs(partToRemovePath); @@ -244,15 +254,60 @@ public void testPartitionsCheck() throws HiveException, MetaException, 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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.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.emptyList(), result.getTablesNotInMs()); + assertEquals(Collections.emptyList(), result.getTablesNotOnFs()); + assertEquals(Collections.emptyList(), result.getPartitionsNotOnFs()); + assertEquals(Collections.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)); + } }