Skip to content

Commit

Permalink
Changed temporary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astachowski committed Oct 4, 2024
1 parent ed62767 commit c219985
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 135 deletions.
3 changes: 0 additions & 3 deletions src/test/java/net/snowflake/client/AbstractDriverIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down
9 changes: 4 additions & 5 deletions src/test/java/net/snowflake/client/core/EventHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/net/snowflake/client/core/EventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
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;
import java.util.zip.GZIPInputStream;
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
Expand All @@ -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";
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/net/snowflake/client/core/SFArrowResultSetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

/**
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/net/snowflake/client/core/SFTrustManagerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +38,8 @@ public void testUnitOCSPWithCustomCacheDirectory() throws IOException {
mockStatic(TrustManagerFactory.class);
MockedStatic<SnowflakeUtil> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/net/snowflake/client/jdbc/ConnectionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down
20 changes: 12 additions & 8 deletions src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit c219985

Please sign in to comment.