This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 43b0971388 PHOENIX-7081 Replace /tmp with {java.io.tmpdir} in tests
43b0971388 is described below

commit 43b0971388a5cf48a0ed898d75792ea5aa2d07cb
Author: Istvan Toth <[email protected]>
AuthorDate: Thu Oct 3 07:58:55 2024 +0200

    PHOENIX-7081 Replace /tmp with {java.io.tmpdir} in tests
    
    Co-authored-by: divneet-kaur <[email protected]>
---
 .../apache/phoenix/mapreduce/OrphanViewTool.java   |  7 ++---
 .../org/apache/phoenix/end2end/CreateTableIT.java  |  4 +--
 .../apache/phoenix/end2end/OrphanViewToolIT.java   | 31 ++++++++++++++++------
 .../end2end/ParameterizedIndexUpgradeToolIT.java   | 26 +++++++++++-------
 4 files changed, 45 insertions(+), 23 deletions(-)

diff --git 
a/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
 
b/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
index 736780ac6e..39d03be9e6 100644
--- 
a/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
+++ 
b/phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
@@ -39,6 +39,7 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -824,7 +825,7 @@ public class OrphanViewTool extends Configured implements 
Tool {
     private void readOrphanViews() throws Exception {
         String aLine;
         reader[VIEW] = new BufferedReader(new InputStreamReader(
-                new FileInputStream(inputPath + fileName[VIEW]), 
StandardCharsets.UTF_8));
+                new FileInputStream(Paths.get(inputPath, 
fileName[VIEW]).toFile()), StandardCharsets.UTF_8));
         while ((aLine = reader[VIEW].readLine()) != null) {
             Key key = new Key(aLine);
             orphanViewSet.put(key, new View(key));
@@ -835,7 +836,7 @@ public class OrphanViewTool extends Configured implements 
Tool {
         String aLine;
         for (byte i = VIEW+1; i < ORPHAN_TYPE_COUNT; i++) {
             reader[i] = new BufferedReader(new InputStreamReader(
-                    new FileInputStream(inputPath + fileName[i]), 
StandardCharsets.UTF_8));
+                    new FileInputStream(Paths.get(inputPath, 
fileName[i]).toFile()), StandardCharsets.UTF_8));
             while ((aLine = reader[i].readLine()) != null) {
                 String ends[] = aLine.split("-->");
                 removeLink(phoenixConnection, new Key(ends[0]), new 
Key(ends[1]), getLinkType(i));
@@ -893,7 +894,7 @@ public class OrphanViewTool extends Configured implements 
Tool {
             if (outputPath != null) {
                 // Create files to log orphan views and links
                 for (int i = VIEW; i < ORPHAN_TYPE_COUNT; i++) {
-                    File file = new File(outputPath + fileName[i]);
+                    File file = Paths.get(outputPath, fileName[i]).toFile();
                     if (file.exists()) {
                         file.delete();
                     }
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
index 879539473d..93a63dd233 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
@@ -1703,7 +1703,7 @@ public class CreateTableIT extends 
ParallelStatsDisabledIT {
             // Now roll back to the old indexing
             IndexUpgradeTool iut =
                     new IndexUpgradeTool(ROLLBACK_OP, tableName, null,
-                            "/tmp/index_upgrade_" + 
UUID.randomUUID().toString(), false, null,
+                        File.createTempFile("index_upgrade_", 
null).toString(), false, null,
                             false);
             iut.setConf(getUtility().getConfiguration());
             iut.prepareToolSetup();
@@ -1750,7 +1750,7 @@ public class CreateTableIT extends 
ParallelStatsDisabledIT {
             // Now roll back to the old indexing
             IndexUpgradeTool iut =
                     new IndexUpgradeTool(ROLLBACK_OP, tableName, null,
-                            "/tmp/index_upgrade_" + 
UUID.randomUUID().toString(), false, null,
+                        File.createTempFile("index_upgrade_", 
null).toString(), false, null,
                             false);
             iut.setConf(getUtility().getConfiguration());
             iut.prepareToolSetup();
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java
index f467442a1d..25e684f1d9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrphanViewToolIT.java
@@ -31,6 +31,9 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.LineNumberReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
@@ -68,11 +71,11 @@ public class OrphanViewToolIT extends BaseOwnClusterIT {
     private static final long grandChildCount = fanout * fanout;
     private static final long grandGrandChildCount = fanout * fanout * fanout;
 
-    private static final String filePath = "/tmp/";
-    private static final String viewFileName = "/tmp/" + 
OrphanViewTool.fileName[OrphanViewTool.VIEW];
-    private static final String physicalLinkFileName = "/tmp/" + 
OrphanViewTool.fileName[OrphanViewTool.PHYSICAL_TABLE_LINK];
-    private static final String parentLinkFileName = "/tmp/" + 
OrphanViewTool.fileName[OrphanViewTool.PARENT_TABLE_LINK];
-    private static final String childLinkFileName = "/tmp/" + 
OrphanViewTool.fileName[OrphanViewTool.CHILD_TABLE_LINK];
+    private static String tmpDir;
+    private static String viewFileName;
+    private static String physicalLinkFileName;
+    private static String parentLinkFileName;
+    private static String childLinkFileName;
 
     protected static String SCHEMA1 = "SCHEMA1";
     protected static String SCHEMA2 = "SCHEMA2";
@@ -134,13 +137,25 @@ public class OrphanViewToolIT extends BaseOwnClusterIT {
     @BeforeClass
     public static synchronized void doSetup() throws Exception {
         setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
+        //Create these after the minicluster has started, and overwritten 
java.io.tmpdir
+        tmpDir = 
Files.createTempDirectory(OrphanViewToolIT.class.getCanonicalName()).toString();
+        viewFileName = Paths.get(tmpDir, 
OrphanViewTool.fileName[OrphanViewTool.VIEW]).toString();
+        physicalLinkFileName =
+                Paths.get(tmpDir, 
OrphanViewTool.fileName[OrphanViewTool.PHYSICAL_TABLE_LINK])
+                        .toString();
+        parentLinkFileName =
+                Paths.get(tmpDir, 
OrphanViewTool.fileName[OrphanViewTool.PARENT_TABLE_LINK])
+                        .toString();
+        childLinkFileName =
+                Paths.get(tmpDir, 
OrphanViewTool.fileName[OrphanViewTool.CHILD_TABLE_LINK])
+                        .toString();
     }
 
     @AfterClass
     public static synchronized void cleanUp() throws Exception {
         boolean refCountLeaked = isAnyStoreRefCountLeaked();
         for (int i = OrphanViewTool.VIEW; i < 
OrphanViewTool.ORPHAN_TYPE_COUNT; i++) {
-            File file = new File(filePath + OrphanViewTool.fileName[i]);
+            File file = Paths.get(tmpDir, OrphanViewTool.fileName[i]).toFile();
             if (file.exists()) {
                 file.delete();
             }
@@ -454,11 +469,11 @@ public class OrphanViewToolIT extends BaseOwnClusterIT {
         final List<String> args = Lists.newArrayList();
         if (outputPath) {
             args.add("-op");
-            args.add(filePath);
+            args.add(tmpDir);
         }
         if (inputPath) {
             args.add("-ip");
-            args.add(filePath);
+            args.add(tmpDir);
         }
         if (clean) {
             args.add("-c");
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
index 2b2d35659d..86162ac03d 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java
@@ -56,6 +56,9 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
@@ -89,7 +92,7 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest 
{
     private static final String [] TRANSACTIONAL_TABLE_LIST = new String[1];
 
     private static String INPUT_LIST = "";
-    private static final String INPUT_FILE = 
"/tmp/input_file_index_upgrade.csv";
+    private Path tmpDir;
 
     private static Map<String, String> serverProps = 
Maps.newHashMapWithExpectedSize(1),
             clientProps = Maps.newHashMapWithExpectedSize(1);
@@ -105,7 +108,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
     private Connection connTenant;
     private Admin admin;
     private IndexUpgradeTool iut;
-    private static String tmpDir = System.getProperty("java.io.tmpdir");;
+    private static String systemTmpDir = System.getProperty("java.io.tmpdir");;
 
     @Mock
     private IndexTool indexToolMock;
@@ -115,7 +118,8 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
 
     @BeforeClass
     public static synchronized void saveTmp () throws Exception {
-        tmpDir = System.getProperty("java.io.tmpdir");
+        //The JVM will exit, so we don't need to restore after
+        systemTmpDir = System.getProperty("java.io.tmpdir");
     }
 
     @Before
@@ -144,6 +148,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
             optionsBuilder.append(" IMMUTABLE_ROWS=true");
         }
         tableDDLOptions = optionsBuilder.toString();
+        tmpDir = 
Files.createTempDirectory(ParameterizedIndexUpgradeToolIT.class.getCanonicalName());
     }
 
     private void setClusterProperties() {
@@ -153,7 +158,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
                 || Boolean.toString(!isNamespaceEnabled).equals(serverProps
                 .get(QueryServices.IS_NAMESPACE_MAPPING_ENABLED))) {
             tearDownMiniCluster(1);
-            System.setProperty("java.io.tmpdir", tmpDir);
+            System.setProperty("java.io.tmpdir", systemTmpDir);
         }
         //setting up properties for namespace
         clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED,
@@ -167,7 +172,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
                 Boolean.toString(!upgrade));
     }
 
-    private void prepareFullSetup() throws SQLException {
+    private void prepareFullSetup() throws SQLException, IOException {
         clearOldTableNames();
         String mockTableOne = "TEST." + generateUniqueName();
         TABLE_LIST[0] = mockTableOne;
@@ -305,7 +310,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
         conn.createStatement().execute("ALTER INDEX " + indexTwoMockOne + " ON 
" + mockTableOne +
             " DISABLE");
         iut = new IndexUpgradeTool(upgrade ? UPGRADE_OP : ROLLBACK_OP, 
INPUT_LIST,
-            null, "/tmp/index_upgrade_" + UUID.randomUUID().toString(),
+            null, Files.createTempFile(tmpDir, "index_upgrade_", 
null).toString(),
             true, indexToolMock, rebuild);
         iut.setConf(getUtility().getConfiguration());
         iut.setTest(true);
@@ -323,7 +328,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
         Arrays.fill(TRANSACTIONAL_INDEXES_LIST, null);
         Arrays.fill(TRANSACTIONAL_TABLE_LIST, null);
     }
-    private void prepareSimplifiedSetup() throws SQLException {
+    private void prepareSimplifiedSetup() throws SQLException, IOException {
         clearOldTableNames();
         String mockTableOne = "TEST." + generateUniqueName();
         INPUT_LIST = mockTableOne;
@@ -348,7 +353,7 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
             " (sal, a.name)");
         conn.commit();
         iut = new IndexUpgradeTool(upgrade ? UPGRADE_OP : ROLLBACK_OP, 
INPUT_LIST,
-            null, "/tmp/index_upgrade_" + UUID.randomUUID().toString(),
+            null,Files.createTempFile(tmpDir, "index_upgrade_", 
null).toString(),
             true, indexToolMock, rebuild);
         iut.setConf(getUtility().getConfiguration());
         iut.setTest(true);
@@ -510,12 +515,13 @@ public class ParameterizedIndexUpgradeToolIT extends 
BaseTest {
         validate(true, false);
 
         // test with input file parameter
-        BufferedWriter writer = new BufferedWriter(new FileWriter(new 
File(INPUT_FILE)));
+        Path inputPath = Paths.get(tmpDir.toString(), 
"input_file_index_upgrade.csv");
+        BufferedWriter writer = new BufferedWriter(new 
FileWriter(inputPath.toFile()));
         writer.write(INPUT_LIST);
         writer.close();
 
         iut.setInputTables(null);
-        iut.setInputFile(INPUT_FILE);
+        iut.setInputFile(inputPath.toString());
         iut.prepareToolSetup();
         status = iut.executeTool();
         Assert.assertEquals(0, status);

Reply via email to