You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2022/02/08 05:33:53 UTC

[phoenix] branch 4.x updated: PHOENIX-6576 Do not use guava's Files.createTempDir()

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

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


The following commit(s) were added to refs/heads/4.x by this push:
     new 28c51ab  PHOENIX-6576 Do not use guava's Files.createTempDir()
28c51ab is described below

commit 28c51ab70329b89ddc9bd4ec9818fd4ff6aa8e54
Author: Istvan Toth <st...@apache.org>
AuthorDate: Thu Feb 3 17:39:50 2022 +0100

    PHOENIX-6576 Do not use guava's Files.createTempDir()
---
 .../org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java    |  3 +--
 .../java/org/apache/phoenix/query/QueryServicesTestImpl.java  | 11 +++++++++--
 .../src/test/java/org/apache/phoenix/util/TestUtil.java       |  9 ++++++++-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
index 0313b0c..1acec12 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
@@ -34,7 +34,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import org.apache.phoenix.thirdparty.com.google.common.io.Files;
 
 @Category(ParallelStatsDisabledTest.class)
 public class SpooledTmpFileDeleteIT extends ParallelStatsDisabledIT {
@@ -58,7 +57,7 @@ public class SpooledTmpFileDeleteIT extends ParallelStatsDisabledIT {
     @Before
     public void setup() throws Exception {
         tableName = generateUniqueName();
-        spoolDir = Files.createTempDir();
+        spoolDir = TestUtil.createTempDirectory().toFile();
         try (Connection conn = getConnection()) {
             Statement stmt = conn.createStatement();
             stmt.execute("CREATE TABLE " + tableName + " (ID varchar NOT NULL PRIMARY KEY) SPLIT ON ('EA','EZ')");
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
index ed6cc12..4c94dc1 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
@@ -20,10 +20,10 @@ package org.apache.phoenix.query;
 import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_SPOOL_DIRECTORY;
 import static org.apache.phoenix.query.QueryServicesOptions.withDefaults;
 
-import org.apache.phoenix.thirdparty.com.google.common.io.Files;
 import org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.TestUtil;
 import org.apache.tephra.TxConstants;
 
 
@@ -88,6 +88,13 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
     }
     
     private static QueryServicesOptions getDefaultServicesOptions() {
+        String txSnapshotDir;
+        try {
+            txSnapshotDir = TestUtil.createTempDirectory().toString();
+        } catch (Exception e) {
+            throw new RuntimeException("Could not create "
+                    + TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, e);
+        }
     	return withDefaults()
     	        .setSequenceCacheSize(DEFAULT_SEQUENCE_CACHE_SIZE)
     	        .setTransactionsEnabled(DEFAULT_TRANSACTIONS_ENABLED)
@@ -129,7 +136,7 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_RETRY_STRATEGY, "n-times")
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_ATTEMPTS, 1)
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, 60)
-                .set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, Files.createTempDir().getAbsolutePath())
+                .set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, txSnapshotDir)
                 .set(TxConstants.Manager.CFG_TX_TIMEOUT, DEFAULT_TXN_TIMEOUT_SECONDS)
                 .set(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, 5L)
                 ;
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index 5cb92f1..de0efcf 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -38,6 +38,9 @@ import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.ServerSocket;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.sql.Connection;
 import java.sql.Date;
 import java.sql.DriverManager;
@@ -1407,6 +1410,10 @@ public class TestUtil {
         }
     }
 
-
+    public static Path createTempDirectory() throws IOException {
+        // We cannot use java.nio.file.Files.createTempDirectory(null),
+        // because that caches the value of "java.io.tmpdir" on class load.
+        return Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), null);
+    }
 
 }