commit 8289b58b97d476920f1b097a3ef46220b7a60ff7 Author: Bharath Krishna Date: Tue Oct 2 22:06:58 2018 -0700 HIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-20610 : TestDbNotificationListener should not use /tmp directoryHIVE-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..1a1239e71d7aa2fd693aad5b893e92aad9d4290d 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,7 +23,9 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.File; import java.lang.reflect.Field; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -119,6 +121,7 @@ private static MessageDeserializer md = null; private int startTime; private long firstEventId; + private final String testTempDir = Paths.get(System.getProperty("java.io.tmpdir"), "testDbNotif").toString(); private static List testsToSkipForReplV1BackwardCompatTesting = new ArrayList<>(Arrays.asList("cleanupNotifs", "cleanupNotificationWithError", "sqlTempTable")); @@ -300,7 +303,7 @@ public void tearDown() { public void createDatabase() throws Exception { String dbName = "createdb"; String dbName2 = "createdb2"; - String dbLocationUri = "file:/tmp"; + String dbLocationUri = testTempDir; String dbDescription = "no description"; Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); msClient.createDatabase(db); @@ -342,7 +345,7 @@ public void createDatabase() throws Exception { public void dropDatabase() throws Exception { String dbName = "dropdb"; String dbName2 = "dropdb2"; - String dbLocationUri = "file:/tmp"; + String dbLocationUri = testTempDir; String dbDescription = "no description"; Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters); msClient.createDatabase(db); @@ -391,7 +394,7 @@ public void createTable() throws Exception { String tblName = "createtable"; String tblName2 = "createtable2"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -445,7 +448,7 @@ public void alterTable() throws Exception { String defaultDbName = "default"; String tblName = "altertabletbl"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); FieldSchema col2 = new FieldSchema("col2", "int", "no comment"); List cols = new ArrayList(); @@ -504,7 +507,7 @@ public void dropTable() throws Exception { String tblName = "droptbl"; String tblName2 = "droptbl2"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -570,7 +573,7 @@ public void addPartition() throws Exception { String tblName = "addptn"; String tblName2 = "addptn2"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -638,7 +641,7 @@ public void alterPartition() throws Exception { String defaultDbName = "default"; String tblName = "alterptn"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -706,7 +709,7 @@ public void dropPartition() throws Exception { String defaultDbName = "default"; String tblName = "dropptn"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); List cols = new ArrayList(); cols.add(col1); @@ -783,28 +786,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, Paths.get(testTempDir , "1").toString(), "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, Paths.get(testTempDir, "2").toString(), "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, Paths.get(testTempDir, "1", "part=1").toString(), "input", "output", false, 0, serde, null, null, + emptyParameters); + StorageDescriptor sd2part = + new StorageDescriptor(cols, Paths.get(testTempDir, "1", "part=2").toString(), "input", "output", false, 0, serde, null, null, + emptyParameters); + StorageDescriptor sd3part = + new StorageDescriptor(cols, Paths.get(testTempDir, "1", "part=3").toString(), "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 +881,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 = Paths.get(testTempDir, "somewhere").toString(); + String funcResource2 = Paths.get(testTempDir, "somewhere2").toString(); Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource))); @@ -931,8 +939,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 = Paths.get(testTempDir, "somewhere").toString(); + String funcResource2 = Paths.get(testTempDir, "somewhere2").toString(); Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource))); @@ -982,7 +990,7 @@ public void insertTable() throws Exception { String defaultDbName = "default"; String tblName = "inserttbl"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; String fileAdded = "/warehouse/mytable/b1"; String checksumAdded = "1234"; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); @@ -1037,7 +1045,7 @@ public void insertPartition() throws Exception { String defaultDbName = "default"; String tblName = "insertptn"; String tblOwner = "me"; - String serdeLocation = "file:/tmp"; + String serdeLocation = testTempDir; String fileAdded = "/warehouse/mytable/b1"; String checksumAdded = "1234"; FieldSchema col1 = new FieldSchema("col1", "int", "no comment"); @@ -1101,11 +1109,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", testTempDir, emptyParameters); msClient.createDatabase(db); - db = new Database("db2", "no description", "file:/tmp", emptyParameters); + db = new Database("db2", "no description", testTempDir, emptyParameters); msClient.createDatabase(db); - db = new Database("db3", "no description", "file:/tmp", emptyParameters); + db = new Database("db3", "no description", testTempDir, emptyParameters); msClient.createDatabase(db); // Get notifications from metastore @@ -1117,9 +1125,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", testTempDir, emptyParameters); msClient.createDatabase(db); - db = new Database("f2", "no description", "file:/tmp", emptyParameters); + db = new Database("f2", "no description", testTempDir, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("f2"); @@ -1138,9 +1146,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", testTempDir, emptyParameters); msClient.createDatabase(db); - db = new Database("f11", "no description", "file:/tmp", emptyParameters); + db = new Database("f11", "no description", testTempDir, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("f11"); @@ -1364,7 +1372,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", testTempDir, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("cleanup1"); @@ -1384,7 +1392,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", testTempDir, emptyParameters); msClient.createDatabase(db); msClient.dropDatabase("cleanup1");