From c2199856b6b342893c36289b63d2cdca51ac9726 Mon Sep 17 00:00:00 2001 From: sfc-gh-astachowski Date: Fri, 4 Oct 2024 13:23:41 +0200 Subject: [PATCH] Changed temporary directories --- .../snowflake/client/AbstractDriverIT.java | 3 - .../client/config/SFPermissionsTest.java | 3 - .../client/core/EventHandlerTest.java | 9 ++- .../net/snowflake/client/core/EventTest.java | 11 ++-- .../client/core/IncidentUtilLatestIT.java | 10 +-- .../client/core/SFArrowResultSetIT.java | 13 ++-- .../client/core/SFTrustManagerIT.java | 3 + .../SFTrustManagerMockitoMockLatestIT.java | 8 +-- .../client/core/SecureStorageManagerTest.java | 4 -- .../snowflake/client/jdbc/ConnectionIT.java | 8 +-- .../client/jdbc/ConnectionLatestIT.java | 20 +++--- .../client/jdbc/CustomProxyLatestIT.java | 8 +-- .../jdbc/FileUploaderExpandFileNamesTest.java | 20 +++--- .../client/jdbc/FileUploaderPrepIT.java | 3 - .../jdbc/PutFileWithSpaceIncludedIT.java | 8 +-- ...akeAzureClientHandleExceptionLatestIT.java | 8 +-- .../client/jdbc/SnowflakeDriverIT.java | 34 ++++++---- .../client/jdbc/SnowflakeDriverLatestIT.java | 64 ++++++++++++------- ...flakeGcsClientHandleExceptionLatestIT.java | 8 +-- .../SnowflakeResultSetSerializableIT.java | 7 +- ...wflakeS3ClientHandleExceptionLatestIT.java | 8 +-- .../snowflake/client/jdbc/StatementIT.java | 8 +-- .../client/jdbc/StatementLatestIT.java | 8 +-- .../snowflake/client/jdbc/StreamLatestIT.java | 8 +-- 24 files changed, 149 insertions(+), 135 deletions(-) diff --git a/src/test/java/net/snowflake/client/AbstractDriverIT.java b/src/test/java/net/snowflake/client/AbstractDriverIT.java index 4a3acea23..3104ce7e9 100644 --- a/src/test/java/net/snowflake/client/AbstractDriverIT.java +++ b/src/test/java/net/snowflake/client/AbstractDriverIT.java @@ -24,12 +24,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; -import org.junit.Rule; /** Base test class with common constants, data structures and methods */ public class AbstractDriverIT { - // This is required to use ConditionalIgnore annotation. - @Rule public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(); public static final String DRIVER_CLASS = "net.snowflake.client.jdbc.SnowflakeDriver"; public static final String DRIVER_CLASS_COM = "com.snowflake.client.jdbc.SnowflakeDriver"; diff --git a/src/test/java/net/snowflake/client/config/SFPermissionsTest.java b/src/test/java/net/snowflake/client/config/SFPermissionsTest.java index 8c0771b43..7fffe8166 100644 --- a/src/test/java/net/snowflake/client/config/SFPermissionsTest.java +++ b/src/test/java/net/snowflake/client/config/SFPermissionsTest.java @@ -8,9 +8,7 @@ import java.nio.file.Paths; import java.nio.file.attribute.PosixFilePermissions; import java.util.stream.Stream; -import net.snowflake.client.ConditionalIgnoreRule; import net.snowflake.client.annotations.DontRunOnWindows; -import org.junit.Rule; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtensionContext; @@ -20,7 +18,6 @@ import org.junit.jupiter.params.provider.ArgumentsSource; public class SFPermissionsTest { - @Rule public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(); static class PermissionProvider implements ArgumentsProvider { diff --git a/src/test/java/net/snowflake/client/core/EventHandlerTest.java b/src/test/java/net/snowflake/client/core/EventHandlerTest.java index 28b710db0..8aa2aa23a 100644 --- a/src/test/java/net/snowflake/client/core/EventHandlerTest.java +++ b/src/test/java/net/snowflake/client/core/EventHandlerTest.java @@ -14,18 +14,17 @@ import java.util.logging.LogRecord; import java.util.zip.GZIPInputStream; import org.apache.commons.io.IOUtils; -import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; public class EventHandlerTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir File tmpFolder; @BeforeEach public void setUp() throws IOException { - tmpFolder.newFolder("snowflake_dumps"); - System.setProperty("snowflake.dump_path", tmpFolder.getRoot().getCanonicalPath()); + new File(tmpFolder, "snowflake_dumps").mkdirs(); + System.setProperty("snowflake.dump_path", tmpFolder.getCanonicalPath()); } @Test diff --git a/src/test/java/net/snowflake/client/core/EventTest.java b/src/test/java/net/snowflake/client/core/EventTest.java index cf6e7008a..7233b6dd8 100644 --- a/src/test/java/net/snowflake/client/core/EventTest.java +++ b/src/test/java/net/snowflake/client/core/EventTest.java @@ -14,21 +14,22 @@ import java.nio.file.Files; import java.util.zip.GZIPInputStream; import org.apache.commons.io.IOUtils; -import org.junit.Rule; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; public class EventTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private File homeDirectory; private File dmpDirectory; @BeforeEach public void setUp() throws IOException { - homeDirectory = tmpFolder.newFolder("homedir"); - dmpDirectory = tmpFolder.newFolder("homedir", "snowflake_dumps"); + homeDirectory = new File(tmpFolder, "homedir"); + homeDirectory.mkdirs(); + dmpDirectory = new File(homeDirectory, "snowflake_dumps"); + dmpDirectory.mkdirs(); } @AfterEach diff --git a/src/test/java/net/snowflake/client/core/IncidentUtilLatestIT.java b/src/test/java/net/snowflake/client/core/IncidentUtilLatestIT.java index ae3498ab9..caf332493 100644 --- a/src/test/java/net/snowflake/client/core/IncidentUtilLatestIT.java +++ b/src/test/java/net/snowflake/client/core/IncidentUtilLatestIT.java @@ -8,6 +8,7 @@ import static net.snowflake.client.core.IncidentUtil.INC_DUMP_FILE_NAME; import static org.junit.Assert.assertEquals; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.StringWriter; @@ -15,14 +16,13 @@ import net.snowflake.client.category.TestCategoryCore; import net.snowflake.client.jdbc.BaseJDBCTest; import org.apache.commons.io.IOUtils; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; @Category(TestCategoryCore.class) public class IncidentUtilLatestIT extends BaseJDBCTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private static final String FILE_NAME = "sf_incident_123456.dmp.gz"; @Test @@ -34,7 +34,9 @@ public void testOneLinerDescription() { /** Tests dumping JVM metrics for the current process */ @Test public void testDumpVmMetrics() throws IOException { - String dumpPath = tmpFolder.newFolder().getCanonicalPath(); + File dumpDir = new File(tmpFolder, "dump"); + dumpDir.mkdirs(); + String dumpPath = dumpDir.getCanonicalPath(); System.setProperty("snowflake.dump_path", dumpPath); String incidentId = "123456"; diff --git a/src/test/java/net/snowflake/client/core/SFArrowResultSetIT.java b/src/test/java/net/snowflake/client/core/SFArrowResultSetIT.java index 93395b3f9..1059faffd 100644 --- a/src/test/java/net/snowflake/client/core/SFArrowResultSetIT.java +++ b/src/test/java/net/snowflake/client/core/SFArrowResultSetIT.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.Random; -import net.snowflake.client.ConditionalIgnoreRule; import net.snowflake.client.annotations.DontRunOnThinJar; import net.snowflake.client.category.TestCategoryArrow; import net.snowflake.client.jdbc.ArrowResultChunk; @@ -63,17 +62,12 @@ import org.apache.arrow.vector.types.pojo.Schema; import org.apache.arrow.vector.util.Text; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; @Category(TestCategoryArrow.class) public class SFArrowResultSetIT extends BaseJDBCWithSharedConnectionIT { - - /** Necessary to conditional ignore tests */ - @Rule public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(); - private Random random = new Random(); /** @@ -83,7 +77,7 @@ public class SFArrowResultSetIT extends BaseJDBCWithSharedConnectionIT { protected BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); /** temporary folder to store result files */ - @Rule public TemporaryFolder resultFolder = new TemporaryFolder(); + @TempDir private File tempDir; /** Test the case that all results are returned in first chunk */ @Test @@ -380,7 +374,8 @@ Object[][] generateData(Schema schema, int rowCount) { File createArrowFile(String fileName, Schema schema, Object[][] data, int rowsPerRecordBatch) throws IOException { - File file = resultFolder.newFile(fileName); + File file = new File(tempDir, fileName); + file.createNewFile(); VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator); try (ArrowWriter writer = diff --git a/src/test/java/net/snowflake/client/core/SFTrustManagerIT.java b/src/test/java/net/snowflake/client/core/SFTrustManagerIT.java index b1a520452..16e2495fd 100644 --- a/src/test/java/net/snowflake/client/core/SFTrustManagerIT.java +++ b/src/test/java/net/snowflake/client/core/SFTrustManagerIT.java @@ -119,6 +119,7 @@ public void testOcspWithFileCache(String host) throws Throwable { System.setProperty( SFTrustManager.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED, Boolean.FALSE.toString()); File ocspCacheFile = new File(tmpFolder, "ocsp-cache"); + ocspCacheFile.createNewFile(); HttpClient client = HttpUtil.buildHttpClient( new HttpClientSettingsKey(OCSPMode.FAIL_CLOSED), @@ -135,6 +136,7 @@ public void testOcspWithServerCache(String host) throws Throwable { System.setProperty( SFTrustManager.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED, Boolean.TRUE.toString()); File ocspCacheFile = new File(tmpFolder, "ocsp-cache"); + ocspCacheFile.createNewFile(); HttpClient client = HttpUtil.buildHttpClient( new HttpClientSettingsKey(OCSPMode.FAIL_CLOSED), @@ -154,6 +156,7 @@ public void testOcspWithoutServerCache(String host) throws Throwable { System.setProperty( SFTrustManager.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED, Boolean.FALSE.toString()); File ocspCacheFile = new File(tmpFolder, "ocsp-cache"); + ocspCacheFile.createNewFile(); HttpClient client = HttpUtil.buildHttpClient( new HttpClientSettingsKey(OCSPMode.FAIL_OPEN), diff --git a/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java b/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java index 0d6598ff1..ca9515ece 100644 --- a/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java +++ b/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java @@ -16,17 +16,16 @@ import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryCore; import net.snowflake.client.jdbc.SnowflakeUtil; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.mockito.MockedStatic; @Category(TestCategoryCore.class) public class SFTrustManagerMockitoMockLatestIT { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; /* * Test SF_OCSP_RESPONSE_CACHE_DIR environment variable changes the @@ -39,7 +38,8 @@ public void testUnitOCSPWithCustomCacheDirectory() throws IOException { mockStatic(TrustManagerFactory.class); MockedStatic mockedSnowflakeUtil = mockStatic(SnowflakeUtil.class)) { - File cacheFolder = tmpFolder.newFolder(); + File cacheFolder = new File(tmpFolder, "cache"); + cacheFolder.mkdirs(); mockedSnowflakeUtil .when(() -> TestUtil.systemGetEnv("SF_OCSP_RESPONSE_CACHE_DIR")) .thenReturn(cacheFolder.getCanonicalPath()); diff --git a/src/test/java/net/snowflake/client/core/SecureStorageManagerTest.java b/src/test/java/net/snowflake/client/core/SecureStorageManagerTest.java index fe9ceb50c..538b87ca0 100644 --- a/src/test/java/net/snowflake/client/core/SecureStorageManagerTest.java +++ b/src/test/java/net/snowflake/client/core/SecureStorageManagerTest.java @@ -16,10 +16,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import net.snowflake.client.ConditionalIgnoreRule; import net.snowflake.client.annotations.RunOnLinux; import net.snowflake.client.annotations.RunOnWindowsOrMac; -import org.junit.Rule; import org.junit.jupiter.api.Test; class MockAdvapi32Lib implements SecureStorageWindowsManager.Advapi32Lib { @@ -213,8 +211,6 @@ Pointer getPointer() { } public class SecureStorageManagerTest { - // This is required to use ConditionalIgnore annotation - @Rule public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(); private static final String host = "fakeHost"; private static final String user = "fakeUser"; diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java index c944f8742..5feac7a46 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java @@ -51,11 +51,10 @@ import net.snowflake.common.core.SqlState; import org.apache.commons.codec.binary.Base64; import org.junit.Assert; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** Connection integration tests */ @Category(TestCategoryConnection.class) @@ -70,7 +69,7 @@ public class ConnectionIT extends BaseJDBCTest { String errorMessage = null; - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; @Test public void testSimpleConnection() throws SQLException { @@ -372,7 +371,8 @@ public void testDataSourceOktaSerialization() throws Exception { ResultSet resultSet = statement.executeQuery("select 1")) { resultSet.next(); assertThat("select 1", resultSet.getInt(1), equalTo(1)); - File serializedFile = tmpFolder.newFile("serializedStuff.ser"); + File serializedFile = new File(tmpFolder, "serializedStuff.ser"); + serializedFile.createNewFile(); // serialize datasource object into a file try (FileOutputStream outputFile = new FileOutputStream(serializedFile); ObjectOutputStream out = new ObjectOutputStream(outputFile)) { diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java index 2969e4cb7..4c876580e 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java @@ -70,13 +70,12 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.StringEntity; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** * Connection integration tests for the latest JDBC driver. This doesn't work for the oldest @@ -86,7 +85,7 @@ */ @Category(TestCategoryConnection.class) public class ConnectionLatestIT extends BaseJDBCTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private static final SFLogger logger = SFLoggerFactory.getLogger(ConnectionLatestIT.class); private boolean defaultState; @@ -195,7 +194,8 @@ public void putGetStatementsHaveQueryID() throws Throwable { try (Connection con = getConnection(); Statement statement = con.createStatement()) { String sourceFilePath = getFullPathFileInResource(TEST_DATA_FILE); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); statement.execute("CREATE OR REPLACE STAGE testPutGet_stage"); SnowflakeStatement snowflakeStatement = statement.unwrap(SnowflakeStatement.class); @@ -232,7 +232,8 @@ public void putGetStatementsHaveQueryIDEvenWhenFail() throws Throwable { try (Connection con = getConnection(); Statement statement = con.createStatement()) { String sourceFilePath = getFullPathFileInResource(TEST_DATA_FILE); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); SnowflakeStatement snowflakeStatement = statement.unwrap(SnowflakeStatement.class); try { @@ -736,7 +737,8 @@ public void testKeyPairFileDataSourceSerialization() throws Exception { connectAndExecuteSelect1(ds); - File serializedFile = tmpFolder.newFile("serializedStuff.ser"); + File serializedFile = new File(tmpFolder, "serializedStuff.ser"); + serializedFile.createNewFile(); // serialize datasource object into a file try (FileOutputStream outputFile = new FileOutputStream(serializedFile); ObjectOutputStream out = new ObjectOutputStream(outputFile)) { @@ -781,7 +783,8 @@ public void testKeyPairBase64DataSourceSerialization() throws Exception { connectAndExecuteSelect1(ds); - File serializedFile = tmpFolder.newFile("serializedStuff.ser"); + File serializedFile = new File(tmpFolder, "serializedStuff.ser"); + serializedFile.createNewFile(); // serialize datasource object into a file try (FileOutputStream outputFile = new FileOutputStream(serializedFile); ObjectOutputStream out = new ObjectOutputStream(outputFile)) { @@ -1031,7 +1034,8 @@ public void testBasicDataSourceSerialization() throws Exception { connectAndExecuteSelect1(ds); - File serializedFile = tmpFolder.newFile("serializedStuff.ser"); + File serializedFile = new File(tmpFolder, "serializedStuff.ser"); + serializedFile.createNewFile(); // serialize datasource object into a file try (FileOutputStream outputFile = new FileOutputStream(serializedFile); ObjectOutputStream out = new ObjectOutputStream(outputFile)) { diff --git a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java index 47eb170ae..c5e23f0cf 100644 --- a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java @@ -24,11 +24,10 @@ import net.snowflake.client.core.HttpUtil; import net.snowflake.client.core.SFSession; import net.snowflake.common.core.SqlState; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; // To run these tests, you must: // 1.) Start up a proxy connection. The simplest ways are via Squid or BurpSuite. Confluence doc on @@ -39,7 +38,7 @@ @Category(TestCategoryOthers.class) public class CustomProxyLatestIT { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; /** * Before running this test, change the user and password to appropriate values. Set up 2 @@ -725,7 +724,8 @@ public PasswordAuthentication getPasswordAuthentication() { String TEST_DATA_FILE = "orders_100.csv"; String sourceFilePath = getFullPathFileInResource(TEST_DATA_FILE); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; assertTrue( diff --git a/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java b/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java index df2206b41..3c862f34d 100644 --- a/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java +++ b/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java @@ -24,22 +24,20 @@ import java.util.stream.IntStream; import net.snowflake.client.core.OCSPMode; import org.junit.Assert; -import org.junit.Rule; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** Tests for SnowflakeFileTransferAgent.expandFileNames */ public class FileUploaderExpandFileNamesTest { - @Rule public TemporaryFolder folder = new TemporaryFolder(); - @Rule public TemporaryFolder secondFolder = new TemporaryFolder(); + @TempDir private File folder; private String localFSFileSep = systemGetProperty("file.separator"); @Test public void testProcessFileNames() throws Exception { - folder.newFile("TestFileA"); - folder.newFile("TestFileB"); + new File(folder, "TestFileA").createNewFile(); + new File(folder, "TestFileB").createNewFile(); - String folderName = folder.getRoot().getCanonicalPath(); + String folderName = folder.getCanonicalPath(); System.setProperty("user.dir", folderName); System.setProperty("user.home", folderName); @@ -150,8 +148,8 @@ public int read() throws IOException { */ @Test public void testFileListingDoesNotFailOnMissingFilesOfAnotherPattern() throws Exception { - folder.newFolder("TestFiles"); - String folderName = folder.getRoot().getCanonicalPath(); + new File(folder, "TestFiles").mkdirs(); + String folderName = folder.getCanonicalPath(); int filePatterns = 10; int filesPerPattern = 100; @@ -211,8 +209,8 @@ public void testFileListingDoesNotFailOnMissingFilesOfAnotherPattern() throws Ex @Test public void testFileListingDoesNotFailOnNotExistingDirectory() throws Exception { - folder.newFolder("TestFiles"); - String folderName = folder.getRoot().getCanonicalPath(); + new File(folder, "TestFiles").mkdirs(); + String folderName = folder.getCanonicalPath(); String[] locations = { folderName + localFSFileSep + "foo*", }; diff --git a/src/test/java/net/snowflake/client/jdbc/FileUploaderPrepIT.java b/src/test/java/net/snowflake/client/jdbc/FileUploaderPrepIT.java index 1ecd2893d..9a9f488e2 100644 --- a/src/test/java/net/snowflake/client/jdbc/FileUploaderPrepIT.java +++ b/src/test/java/net/snowflake/client/jdbc/FileUploaderPrepIT.java @@ -8,13 +8,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Arrays; import java.util.List; -import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; -import org.junit.rules.TemporaryFolder; /** File uploader test prep reused by IT/connection tests and sessionless tests */ abstract class FileUploaderPrepIT extends BaseJDBCTest { - @Rule public TemporaryFolder folder = new TemporaryFolder(); private ObjectMapper mapper = new ObjectMapper(); private final String exampleS3JsonStringWithStageEndpoint = diff --git a/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java b/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java index 3acc64ef1..bee798dd9 100644 --- a/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java @@ -17,15 +17,14 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.io.IOUtils; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; @Category(TestCategoryOthers.class) public class PutFileWithSpaceIncludedIT extends BaseJDBCTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; /** Test PUT command to send a data file, which file name contains a space. */ @Test @@ -43,7 +42,8 @@ public void putFileWithSpaceIncluded() throws Exception { assertNotNull(AWS_SECRET_KEY); assertNotNull(AWS_KEY_ID); - File dataFolder = tmpFolder.newFolder(); + File dataFolder = new File(tmpFolder, "data"); + dataFolder.mkdirs(); String tarFile = getFullPathFileInResource("snow-13400.tar"); FileInputStream fis = new FileInputStream(tarFile); TarArchiveInputStream tis = new TarArchiveInputStream(fis); diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java index b7419eb70..53733cdc5 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java @@ -22,18 +22,17 @@ import net.snowflake.client.core.SFStatement; import net.snowflake.client.jdbc.cloud.storage.SnowflakeAzureClient; import org.junit.Assert; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; /** Test for SnowflakeAzureClient handle exception function */ @Category(TestCategoryOthers.class) public class SnowflakeAzureClientHandleExceptionLatestIT extends AbstractDriverIT { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private Connection connection; private SFStatement sfStatement; private SFSession sfSession; @@ -210,7 +209,8 @@ public void errorNoSpaceLeftOnDevice() { assertThrows( SnowflakeSQLException.class, () -> { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String getCommand = "get @testPutGet_stage/" diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java index 589e578eb..0e728adef 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java @@ -56,13 +56,12 @@ import net.snowflake.common.core.ClientAuthnDTO; import net.snowflake.common.core.SqlState; import org.apache.commons.io.FileUtils; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** General integration tests */ @Category(TestCategoryOthers.class) @@ -73,10 +72,10 @@ public class SnowflakeDriverIT extends BaseJDBCTest { private static String ORDERS_JDBC = "ORDERS_JDBC"; - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private ObjectMapper mapper = new ObjectMapper(); - @Rule public TemporaryFolder tmpFolder2 = new TemporaryFolder(); + @TempDir public File tmpFolder2; public String testStageName = String.format("test_stage_%s", UUID.randomUUID().toString()).replaceAll("-", "_"); @@ -748,7 +747,8 @@ public void testPutWithWildcardGCP() throws Throwable { // replace file name with wildcard character sourceFilePath = sourceFilePath.replace("orders_100.csv", "orders_10*.csv"); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; statement.execute("alter session set ENABLE_GCP_PUT_EXCEPTION_FOR_OLD_DRIVERS=false"); @@ -813,18 +813,21 @@ public void testPutGetLargeFileGCP() throws Throwable { try (Connection connection = getConnection("gcpaccount"); Statement statement = connection.createStatement()) { try { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; - File largeTempFile = tmpFolder.newFile("largeFile.csv"); + File largeTempFile = new File(tmpFolder, "largeFile.csv"); + largeTempFile.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(largeTempFile))) { bw.write("Creating large test file for GCP PUT/GET test"); bw.write(System.lineSeparator()); bw.write("Creating large test file for GCP PUT/GET test"); bw.write(System.lineSeparator()); } - File largeTempFile2 = tmpFolder.newFile("largeFile2.csv"); + File largeTempFile2 = new File(tmpFolder, "largeFile2.csv"); + largeTempFile2.createNewFile(); String sourceFilePath = largeTempFile.getCanonicalPath(); @@ -888,12 +891,14 @@ public void testPutGetLargeFileGCP() throws Throwable { @DontRunOnGithubActions public void testPutOverwrite() throws Throwable { // create 2 files: an original, and one that will overwrite the original - File file1 = tmpFolder.newFile("testfile.csv"); + File file1 = new File(tmpFolder, "testfile.csv"); + file1.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(file1))) { bw.write("Writing original file content. This should get overwritten."); } - File file2 = tmpFolder2.newFile("testfile.csv"); + File file2 = new File(tmpFolder2, "testfile.csv"); + file2.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(file2))) { bw.write("This is all new! This should be the result of the overwriting."); } @@ -901,7 +906,8 @@ public void testPutOverwrite() throws Throwable { String sourceFilePathOriginal = file1.getCanonicalPath(); String sourceFilePathOverwrite = file2.getCanonicalPath(); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; @@ -2640,7 +2646,8 @@ public void testPutGet() throws Throwable { try { String sourceFilePath = getFullPathFileInResource(TEST_DATA_FILE); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; @@ -2695,7 +2702,8 @@ public void testPutGetToUnencryptedStage() throws Throwable { try { String sourceFilePath = getFullPathFileInResource(TEST_DATA_FILE); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java index ac62a677c..d86e34364 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java @@ -58,11 +58,10 @@ import net.snowflake.common.core.SqlState; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** * General JDBC tests for the latest JDBC driver. This doesn't work for the oldest supported driver. @@ -72,8 +71,8 @@ */ @Category(TestCategoryOthers.class) public class SnowflakeDriverLatestIT extends BaseJDBCTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); - @Rule public TemporaryFolder tmpFolder2 = new TemporaryFolder(); + @TempDir private File tmpFolder; + @TempDir private File tmpFolder2; public String testStageName = String.format("test_stage_%s", UUID.randomUUID().toString()).replaceAll("-", "_"); @@ -204,7 +203,8 @@ public void testPutThreshold() throws SQLException { @Test @Disabled public void testGCPFileTransferMetadataWithOneFile() throws Throwable { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); try (Connection connection = getConnection("gcpaccount"); @@ -286,7 +286,8 @@ public void testGCPFileTransferMetadataWithOneFile() throws Throwable { @Test @DontRunOnGithubActions public void testAzureS3FileTransferMetadataWithOneFile() throws Throwable { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); List supportedAccounts = Arrays.asList("s3testaccount", "azureaccount"); @@ -392,7 +393,8 @@ public void testGCPFileTransferMetadataNegativeOnlySupportPut() throws Throwable SFSession sfSession = connection.unwrap(SnowflakeConnectionV1.class).getSfSession(); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String getCommand = "get @" + testStageName + " file://" + destFolderCanonicalPath; @@ -491,19 +493,22 @@ public void testGetPropertyInfo() throws SQLException { public void testPutOverwriteFalseNoDigest() throws Throwable { // create 2 files: an original, and one that will overwrite the original - File file1 = tmpFolder.newFile("testfile.csv"); + File file1 = new File(tmpFolder, "testfile.csv"); + file1.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(file1))) { bw.write("Writing original file content. This should get overwritten."); } - File file2 = tmpFolder2.newFile("testfile.csv"); + File file2 = new File(tmpFolder2, "testfile.csv"); + file2.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(file2))) { bw.write("This is all new! This should be the result of the overwriting."); } String sourceFilePathOriginal = file1.getCanonicalPath(); String sourceFilePathOverwrite = file2.getCanonicalPath(); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; @@ -568,7 +573,8 @@ public void testPutOverwriteFalseNoDigest() throws Throwable { public void testPutDisable() throws Throwable { // create a file - File file = tmpFolder.newFile("testfile99.csv"); + File file = new File(tmpFolder, "testfile99.csv"); + file.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) { bw.write("This content won't be uploaded as PUT is disabled."); } @@ -602,7 +608,8 @@ public void testPutDisable() throws Throwable { public void testGetDisable() throws Throwable { // create a folder - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); Properties paramProperties = new Properties(); @@ -1041,7 +1048,8 @@ public void testPutGetGcsDownscopedCredentialWithDisabledDefaultCredentials() th private void putAndGetFile(Statement statement) throws Throwable { String sourceFilePath = getFullPathFileInResource(TEST_DATA_FILE_2); - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; @@ -1095,18 +1103,21 @@ public void testPutGetLargeFileGCSDownscopedCredential() throws Throwable { try (Connection connection = getConnection("gcpaccount", paramProperties); Statement statement = connection.createStatement()) { try { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; - File largeTempFile = tmpFolder.newFile("largeFile.csv"); + File largeTempFile = new File(tmpFolder, "largeFile.csv"); + largeTempFile.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(largeTempFile))) { bw.write("Creating large test file for GCP PUT/GET test"); bw.write(System.lineSeparator()); bw.write("Creating large test file for GCP PUT/GET test"); bw.write(System.lineSeparator()); } - File largeTempFile2 = tmpFolder.newFile("largeFile2.csv"); + File largeTempFile2 = new File(tmpFolder, "largeFile2.csv"); + largeTempFile2.createNewFile(); String sourceFilePath = largeTempFile.getCanonicalPath(); @@ -1171,18 +1182,21 @@ public void testPutGetLargeFileAzure() throws Throwable { try (Connection connection = getConnection("azureaccount", paramProperties); Statement statement = connection.createStatement()) { try { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String destFolderCanonicalPathWithSeparator = destFolderCanonicalPath + File.separator; - File largeTempFile = tmpFolder.newFile("largeFile.csv"); + File largeTempFile = new File(tmpFolder, "largeFile.csv"); + largeTempFile.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(largeTempFile))) { bw.write("Creating large test file for Azure PUT/GET test"); bw.write(System.lineSeparator()); bw.write("Creating large test file for Azure PUT/GET test"); bw.write(System.lineSeparator()); } - File largeTempFile2 = tmpFolder.newFile("largeFile2.csv"); + File largeTempFile2 = new File(tmpFolder, "largeFile2.csv"); + largeTempFile2.createNewFile(); String sourceFilePath = largeTempFile.getCanonicalPath(); @@ -1261,7 +1275,8 @@ private void copyContentFrom(File file1, File file2) throws Exception { @Test @DontRunOnGithubActions public void testPutS3RegionalUrl() throws Throwable { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); List supportedAccounts = Arrays.asList("s3testaccount", "azureaccount"); @@ -1482,7 +1497,8 @@ public void testNoSpaceLeftOnDeviceException() { @Test @Disabled // ignored until SNOW-1616480 is resolved public void testUploadWithGCSPresignedUrlWithoutConnection() throws Throwable { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); // set parameter for presignedUrl upload instead of downscoped token Properties paramProperties = new Properties(); @@ -1548,7 +1564,8 @@ public void testUploadWithGCSDownscopedCredentialWithoutConnection() throws Thro } private void uploadWithGCSDownscopedCredentialWithoutConnection() throws Throwable { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); Properties paramProperties = new Properties(); paramProperties.put("GCS_USE_DOWNSCOPED_CREDENTIAL", true); @@ -1741,7 +1758,8 @@ public void testHTAPStatementParameterCaching() throws SQLException { @Test @DontRunOnGithubActions public void testS3PutInGS() throws Throwable { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); Properties paramProperties = new Properties(); try (Connection connection = getConnection("s3testaccount", paramProperties); diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java index 143200800..3497b1adc 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java @@ -19,18 +19,17 @@ import net.snowflake.client.core.SFStatement; import net.snowflake.client.jdbc.cloud.storage.SnowflakeGCSClient; import org.junit.Assert; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; /** Test for SnowflakeGcsClient handle exception function, only work with latest driver */ @Category(TestCategoryOthers.class) public class SnowflakeGcsClientHandleExceptionLatestIT extends AbstractDriverIT { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private Connection connection; private SFStatement sfStatement; private SFSession sfSession; @@ -190,7 +189,8 @@ public void errorNoSpaceLeftOnDevice() { assertThrows( SnowflakeSQLException.class, () -> { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String getCommand = "get @testPutGet_stage/" diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeResultSetSerializableIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeResultSetSerializableIT.java index 24dacbb4e..a7df9c7da 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeResultSetSerializableIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeResultSetSerializableIT.java @@ -22,16 +22,15 @@ import javax.annotation.Nullable; import net.snowflake.client.annotations.DontRunOnGithubActions; import net.snowflake.client.category.TestCategoryResultSet; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** SnowflakeResultSetSerializable tests */ @Category(TestCategoryResultSet.class) public class SnowflakeResultSetSerializableIT extends BaseJDBCTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private static boolean developPrint = false; @@ -120,7 +119,7 @@ private List serializeResultSet( SnowflakeResultSetSerializable entry = resultSetChunks.get(i); // Write object to file - String tmpFileName = tmpFolder.getRoot().getPath() + "_result_" + i + "." + fileNameAppendix; + String tmpFileName = tmpFolder.getPath() + "_result_" + i + "." + fileNameAppendix; try (FileOutputStream fo = new FileOutputStream(tmpFileName); ObjectOutputStream so = new ObjectOutputStream(fo)) { so.writeObject(entry); diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java index b2792ae55..17e68f85e 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java @@ -26,18 +26,17 @@ import net.snowflake.client.jdbc.cloud.storage.SnowflakeS3Client; import net.snowflake.client.jdbc.cloud.storage.StageInfo; import org.junit.Assert; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; /** Test for SnowflakeS3Client handle exception function */ @Category(TestCategoryOthers.class) public class SnowflakeS3ClientHandleExceptionLatestIT extends AbstractDriverIT { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; private Connection connection; private SFStatement sfStatement; private SFSession sfSession; @@ -228,7 +227,8 @@ public void errorNoSpaceLeftOnDevice() { assertThrows( SnowflakeSQLException.class, () -> { - File destFolder = tmpFolder.newFolder(); + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); String destFolderCanonicalPath = destFolder.getCanonicalPath(); String getCommand = "get @testPutGet_stage/" diff --git a/src/test/java/net/snowflake/client/jdbc/StatementIT.java b/src/test/java/net/snowflake/client/jdbc/StatementIT.java index a3e8ea921..4eadfa5cb 100644 --- a/src/test/java/net/snowflake/client/jdbc/StatementIT.java +++ b/src/test/java/net/snowflake/client/jdbc/StatementIT.java @@ -30,11 +30,10 @@ import net.snowflake.client.jdbc.telemetry.TelemetryClient; import net.snowflake.common.core.SqlState; import org.awaitility.Awaitility; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** Statement tests */ @Category(TestCategoryStatement.class) @@ -49,7 +48,7 @@ public static Connection getConnection() throws SQLException { return conn; } - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; @Test public void testFetchDirection() throws SQLException { @@ -361,7 +360,8 @@ public void testExecuteBatch() throws Exception { "put file://" + getFullPathFileInResource(TEST_DATA_FILE) + " @%test_batch auto_compress=false"); - File tempFolder = tmpFolder.newFolder("test_downloads_folder"); + File tempFolder = new File(tmpFolder, "test_downloads_folder"); + tempFolder.mkdirs(); statement.addBatch("get @%test_batch file://" + tempFolder.getCanonicalPath()); rowCounts = statement.executeBatch(); diff --git a/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java b/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java index 7bb9f41db..62137da18 100644 --- a/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/StatementLatestIT.java @@ -28,10 +28,9 @@ import net.snowflake.client.core.ParameterBindingDTO; import net.snowflake.client.core.SFSession; import net.snowflake.client.core.bind.BindUploader; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** * Statement integration tests for the latest JDBC driver. This doesn't work for the oldest @@ -51,7 +50,7 @@ public static Connection getConnection() throws SQLException { return conn; } - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; @Test public void testExecuteCreateAndDrop() throws SQLException { @@ -84,7 +83,8 @@ public void testExecuteCreateAndDrop() throws SQLException { @Test @DontRunOnGithubActions public void testCopyAndUpload() throws Exception { - File tempFolder = tmpFolder.newFolder("test_downloads_folder"); + File tempFolder = new File(tmpFolder, "test_downloads_folder"); + tempFolder.mkdirs(); List accounts = Arrays.asList(null, "s3testaccount", "azureaccount", "gcpaccount"); for (int i = 0; i < accounts.size(); i++) { String fileName = "test_copy.csv"; diff --git a/src/test/java/net/snowflake/client/jdbc/StreamLatestIT.java b/src/test/java/net/snowflake/client/jdbc/StreamLatestIT.java index b16aa264c..17743a048 100644 --- a/src/test/java/net/snowflake/client/jdbc/StreamLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/StreamLatestIT.java @@ -22,11 +22,10 @@ import net.snowflake.client.annotations.DontRunOnGithubActions; import net.snowflake.client.category.TestCategoryOthers; import org.apache.commons.io.IOUtils; -import org.junit.Rule; import org.junit.experimental.categories.Category; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; /** * Stream API tests for the latest JDBC driver. This doesn't work for the oldest supported driver. @@ -37,7 +36,7 @@ @Category(TestCategoryOthers.class) public class StreamLatestIT extends BaseJDBCTest { - @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir private File tmpFolder; /** * Test Upload Stream with atypical stage names @@ -201,7 +200,8 @@ public void testSpecialCharactersInFileName() throws SQLException, IOException { Statement statement = connection.createStatement()) { try { // Create a temporary file with special characters in the name and write to it - File specialCharFile = tmpFolder.newFile("(special char@).txt"); + File specialCharFile = new File(tmpFolder, "(special char@).txt"); + specialCharFile.createNewFile(); try (BufferedWriter bw = new BufferedWriter(new FileWriter(specialCharFile))) { bw.write("Creating test file for downloadStream test"); }