commit 4a83740582cd332b1b10b4e753362e758c686dcd Author: Bharath Krishna Date: Tue Oct 2 14:38:35 2018 -0700 HIVE-20610 : TestDbNotificationListener should not use /tmp directory diff --git itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index 82429e36a575918d92a9b22bedcd63788ec51c5f..219bfce0dee15b47a2d17c8119d253ab43f9dfc4 100644 --- itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -119,6 +120,7 @@ private static MessageDeserializer md = null; private int startTime; private long firstEventId; + private final String TEST_TEMP_DIR = System.getProperty("java.io.tmpdir") + File.separator + "testDbNotif"; private static List testsToSkipForReplV1BackwardCompatTesting = new ArrayList<>(Arrays.asList("cleanupNotifs", "cleanupNotificationWithError", "sqlTempTable")); @@ -300,7 +302,7 @@ public void tearDown() { public void createDatabase() throws Exception { String dbName = "createdb"; String dbName2 = "createdb2"; - String dbLocationUri = "file:/tmp"; + String dbLocationUri = TEST_TEMP_DIR; String dbDescription = "no description"; Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); msClient.createDatabase(db); @@ -342,7 +344,7 @@ public void createDatabase() throws Exception { public void dropDatabase() throws Exception { String dbName = "dropdb"; String dbName2 = "dropdb2"; - String dbLocationUri = "file:/tmp"; + String dbLocationUri = TEST_TEMP_DIR; String dbDescription = "no description"; Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); msClient.createDatabase(db); @@ -391,7 +393,7 @@ public void createTable() throws Exception { String tblName = "createtable"; String tblName2 = "createtable2"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -445,7 +447,7 @@ public void alterTable() throws Exception { String defaultDbName = "default"; String tblName = "altertabletbl"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); FieldSchema col2 = new FieldSchema("col2", "int", "no comment"); List cols = new ArrayList(); @@ -504,7 +506,7 @@ public void dropTable() throws Exception { String tblName = "droptbl"; String tblName2 = "droptbl2"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -570,7 +572,7 @@ public void addPartition() throws Exception { String tblName = "addptn"; String tblName2 = "addptn2"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -638,7 +640,7 @@ public void alterPartition() throws Exception { String defaultDbName = "default"; String tblName = "alterptn"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -706,7 +708,7 @@ public void dropPartition() throws Exception { String defaultDbName = "default"; String tblName = "dropptn"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -783,28 +785,33 @@ public void exchangePartition() throws Exception { List partCols = new ArrayList(); partCols.add(new FieldSchema("part", "int", "")); SerDeInfo serde = new SerDeInfo("serde", "seriallib", null); - StorageDescriptor sd1 = new StorageDescriptor(cols, "file:/tmp/1", "input", "output", false, 0, - serde, null, null, emptyParameters); + StorageDescriptor sd1 = + new StorageDescriptor(cols, TEST_TEMP_DIR + File.separator + "1", "input", "output", false, 0, serde, null, + null, emptyParameters); Table tab1 = new Table("tab1", dbName, "me", startTime, startTime, 0, sd1, partCols, emptyParameters, null, null, null); msClient.createTable(tab1); NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null); assertEquals(1, rsp.getEventsSize()); // add_table - StorageDescriptor sd2 = new StorageDescriptor(cols, "file:/tmp/2", "input", "output", false, 0, - serde, null, null, emptyParameters); + StorageDescriptor sd2 = + new StorageDescriptor(cols, TEST_TEMP_DIR + File.separator + "2", "input", "output", false, 0, serde, null, + null, emptyParameters); Table tab2 = new Table("tab2", dbName, "me", startTime, startTime, 0, sd2, partCols, emptyParameters, null, null, null); // add_table msClient.createTable(tab2); rsp = msClient.getNextNotification(firstEventId + 1, 0, null); assertEquals(1, rsp.getEventsSize()); - StorageDescriptor sd1part = new StorageDescriptor(cols, "file:/tmp/1/part=1", "input", "output", false, 0, - serde, null, null, emptyParameters); - StorageDescriptor sd2part = new StorageDescriptor(cols, "file:/tmp/1/part=2", "input", "output", false, 0, - serde, null, null, emptyParameters); - StorageDescriptor sd3part = new StorageDescriptor(cols, "file:/tmp/1/part=3", "input", "output", false, 0, - serde, null, null, emptyParameters); + StorageDescriptor sd1part = + new StorageDescriptor(cols, TEST_TEMP_DIR + "/1/part=1", "input", "output", false, 0, serde, null, null, + emptyParameters); + StorageDescriptor sd2part = + new StorageDescriptor(cols, TEST_TEMP_DIR + "/1/part=2", "input", "output", false, 0, serde, null, null, + emptyParameters); + StorageDescriptor sd3part = + new StorageDescriptor(cols, TEST_TEMP_DIR + "/1/part=3", "input", "output", false, 0, serde, null, null, + emptyParameters); Partition part1 = new Partition(Arrays.asList("1"), "default", tab1.getTableName(), startTime, startTime, sd1part, emptyParameters); Partition part2 = new Partition(Arrays.asList("2"), "default", tab1.getTableName(), @@ -873,8 +880,8 @@ public void createFunction() throws Exception { String ownerName = "me"; String funcClass = "o.a.h.h.createfunc"; String funcClass2 = "o.a.h.h.createfunc2"; - String funcResource = "file:/tmp/somewhere"; - String funcResource2 = "file:/tmp/somewhere2"; + String funcResource = TEST_TEMP_DIR + File.separator + "somewhere"; + String funcResource2 = TEST_TEMP_DIR + File.separator + "somewhere2"; Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource))); @@ -931,8 +938,8 @@ public void dropFunction() throws Exception { String ownerName = "me"; String funcClass = "o.a.h.h.dropfunction"; String funcClass2 = "o.a.h.h.dropfunction2"; - String funcResource = "file:/tmp/somewhere"; - String funcResource2 = "file:/tmp/somewhere2"; + String funcResource = TEST_TEMP_DIR + File.separator + "somewhere"; + String funcResource2 = TEST_TEMP_DIR + File.separator + "somewhere2"; Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource))); @@ -982,7 +989,7 @@ public void insertTable() throws Exception { String defaultDbName = "default"; String tblName = "inserttbl"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; String fileAdded = "/warehouse/mytable/b1"; String checksumAdded = "1234"; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); @@ -1037,7 +1044,7 @@ public void insertPartition() throws Exception { String defaultDbName = "default"; String tblName = "insertptn"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = TEST_TEMP_DIR; String fileAdded = "/warehouse/mytable/b1"; String checksumAdded = "1234"; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); @@ -1101,11 +1108,11 @@ public void insertPartition() throws Exception { @Test public void getOnlyMaxEvents() throws Exception { - Database db = new Database("db1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("db1", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); - db = new Database("db2", "no description", "file:/tmp", emptyParameters); + db = new Database("db2", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); - db = new Database("db3", "no description", "file:/tmp", emptyParameters); + db = new Database("db3", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); // Get notifications from metastore @@ -1117,9 +1124,9 @@ public void getOnlyMaxEvents() throws Exception { @Test public void filter() throws Exception { - Database db = new Database("f1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("f1", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); - db = new Database("f2", "no description", "file:/tmp", emptyParameters); + db = new Database("f2", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("f2"); @@ -1138,9 +1145,9 @@ public boolean accept(NotificationEvent event) { @Test public void filterWithMax() throws Exception { - Database db = new Database("f10", "no description", "file:/tmp", emptyParameters); + Database db = new Database("f10", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); - db = new Database("f11", "no description", "file:/tmp", emptyParameters); + db = new Database("f11", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("f11"); @@ -1364,7 +1371,7 @@ private void verifyInsert(NotificationEvent event, String dbName, String tblName @Test public void cleanupNotifs() throws Exception { - Database db = new Database("cleanup1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("cleanup1", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("cleanup1"); @@ -1384,7 +1391,7 @@ public void cleanupNotifs() throws Exception { @Test public void cleanupNotificationWithError() throws Exception { - Database db = new Database("cleanup1", "no description", "file:/tmp", emptyParameters); + Database db = new Database("cleanup1", "no description", TEST_TEMP_DIR, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("cleanup1");