Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing test categories to integration tests #1937

Merged
merged 16 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import java.sql.Connection;
import java.sql.SQLException;
import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.category.TestCategoryConnection;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(TestCategoryConnection.class)
public class SnowflakeDriverIT extends AbstractDriverIT {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import java.sql.Types;
import java.util.Arrays;
import java.util.List;
import net.snowflake.client.category.TestCategoryResultSet;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(TestCategoryResultSet.class)
public class DatabaseMetaDataResultSetLatestIT extends BaseJDBCTest {

@Test(expected = SnowflakeLoggedFeatureNotSupportedException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void testProcessFileNames() throws Exception {
folder.newFile("TestFileB");

String folderName = folder.getRoot().getCanonicalPath();
String originalUserDir = System.getProperty("user.dir");
String originalUserHome = System.getProperty("user.home");
System.setProperty("user.dir", folderName);
System.setProperty("user.home", folderName);

Expand All @@ -58,6 +60,17 @@ public void testProcessFileNames() throws Exception {
assertTrue(files.contains(folderName + File.separator + "TestFileC"));
assertTrue(files.contains(folderName + File.separator + "TestFileD"));
assertTrue(files.contains(folderName + File.separator + "TestFileE~"));

sfc-gh-astachowski marked this conversation as resolved.
Show resolved Hide resolved
if (originalUserHome != null) {
System.setProperty("user.home", originalUserHome);
} else {
System.clearProperty("user.home");
}
if (originalUserDir != null) {
System.setProperty("user.dir", originalUserDir);
} else {
System.clearProperty("user.dir");
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

/** Tests for SnowflakeFileTransferAgent that require an active connection */
@Category(TestCategoryOthers.class)
public class FileUploaderLatestIT extends FileUploaderPrepIT {
public class FileUploaderLatestIT extends FileUploaderPrep {
private static final String OBJ_META_STAGE = "testObjMeta";
private ObjectMapper mapper = new ObjectMapper();
private static final String PUT_COMMAND = "put file:///dummy/path/file2.gz @testStage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.junit.rules.TemporaryFolder;

/** File uploader test prep reused by IT/connection tests and sessionless tests */
abstract class FileUploaderPrepIT extends BaseJDBCTest {
abstract class FileUploaderPrep extends BaseJDBCTest {
@Rule public TemporaryFolder folder = new TemporaryFolder();
private ObjectMapper mapper = new ObjectMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.junit.Test;

/** Tests for SnowflakeFileTransferAgent.expandFileNames. */
public class FileUploaderSessionlessTest extends FileUploaderPrepIT {
public class FileUploaderSessionlessTest extends FileUploaderPrep {

private ObjectMapper mapper = new ObjectMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import java.sql.Statement;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.category.TestCategoryStatement;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(TestCategoryStatement.class)
public class MaxLobSizeLatestIT extends BaseJDBCTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,40 @@
import java.sql.Statement;
import java.util.List;
import java.util.Properties;
import net.snowflake.client.category.TestCategoryCore;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

@Category(TestCategoryCore.class)
public class SnowflakeChunkDownloaderLatestIT extends BaseJDBCTest {
private static String originalProxyHost;
private static String originalProxyPort;
private static String originalNonProxyHosts;

@BeforeClass
public static void setUp() throws Exception {
originalProxyHost = System.getProperty("https.proxyHost");
originalProxyPort = System.getProperty("https.proxyPort");
originalNonProxyHosts = System.getProperty("https.nonProxyHosts");
}

private static void restoreProperty(String key, String value) {
if (value != null) {
System.setProperty(key, value);
} else {
System.clearProperty(key);
}
}

@AfterClass
public static void tearDown() throws Exception {
restoreProperty("https.proxyHost", originalProxyHost);
restoreProperty("https.proxyPort", originalProxyPort);
restoreProperty("https.nonProxyHosts", originalNonProxyHosts);
}
/**
* Tests that the chunk downloader uses the maxHttpRetries and doesn't enter and infinite loop of
* retries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.spy;

import com.amazonaws.services.kms.model.UnsupportedOperationException;
sfc-gh-mkubik marked this conversation as resolved.
Show resolved Hide resolved
import com.microsoft.azure.storage.blob.ListBlobItem;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.category.TestCategoryOthers;
import net.snowflake.client.core.SFSession;
import net.snowflake.client.core.SFStatement;
import net.snowflake.client.jdbc.BaseJDBCTest;
Expand All @@ -18,7 +22,9 @@
import net.snowflake.client.jdbc.SnowflakeSQLLoggedException;
import net.snowflake.common.core.RemoteStoreFileEncryptionMaterial;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(TestCategoryOthers.class)
public class SnowflakeAzureClientLatestIT extends BaseJDBCTest {
@Test
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
Expand All @@ -42,11 +48,11 @@ public void testAzureClientSetupInvalidEncryptionKeySize() throws SQLException {

@Test
public void testCloudExceptionTest() {
Iterable<ListBlobItem> mockList = null;
Iterable<ListBlobItem> mockList = new ArrayList<>();
AzureObjectSummariesIterator iterator = new AzureObjectSummariesIterator(mockList);
AzureObjectSummariesIterator spyIterator = spy(iterator);
UnsupportedOperationException ex =
assertThrows(UnsupportedOperationException.class, () -> spyIterator.remove());
assertEquals(ex.getMessage(), "remove() method not supported");
assertTrue(ex.getMessage().startsWith("remove() method not supported"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Properties;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.category.TestCategoryOthers;
import net.snowflake.client.core.SFSession;
import net.snowflake.client.core.SFStatement;
import net.snowflake.client.jdbc.BaseJDBCTest;
Expand All @@ -24,8 +25,10 @@
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

@Category(TestCategoryOthers.class)
public class SnowflakeS3ClientLatestIT extends BaseJDBCTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,33 @@
import java.util.Properties;
import java.util.logging.Level;
import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnWin;
import net.snowflake.client.category.TestCategoryOthers;
import net.snowflake.client.jdbc.SnowflakeSQLLoggedException;
import org.apache.commons.io.FileUtils;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;

@Category(TestCategoryOthers.class)
public class JDK14LoggerWithClientLatestIT extends AbstractDriverIT {

@Rule public TemporaryFolder tmpFolder = new TemporaryFolder();

String homePath = systemGetProperty("user.home");

@Test
public void testJDK14LoggingWithClientConfig() {
Path configFilePath = Paths.get("config.json");
String configJson = "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"logs\"}}";
@Ignore
public void testJDK14LoggingWithClientConfig() throws IOException {
File configFile = tmpFolder.newFile("config.json");
Path configFilePath = configFile.toPath();
File logFolder = tmpFolder.newFolder("logs");
Path logFolderPath = logFolder.toPath();
String configJson =
"{\"common\":{\"log_level\":\"debug\",\"log_path\":\"" + logFolderPath + "\"}}";
try {
Files.write(configFilePath, configJson.getBytes());
Properties properties = new Properties();
Expand All @@ -38,11 +53,8 @@ public void testJDK14LoggingWithClientConfig() {
Statement statement = connection.createStatement()) {
statement.executeQuery("select 1");

File file = new File("logs/jdbc/");
File file = new File(Paths.get(logFolderPath.toString(), "jdbc").toString());
assertTrue(file.exists());

Files.deleteIfExists(configFilePath);
FileUtils.deleteDirectory(new File("logs"));
}
} catch (IOException e) {
fail("testJDK14LoggingWithClientConfig failed");
Expand All @@ -62,11 +74,15 @@ public void testJDK14LoggingWithClientConfigInvalidConfigFilePath() throws SQLEx
}

@Test
public void testJDK14LoggingWithClientConfigPermissionError() throws IOException, SQLException {
Path configFilePath = Paths.get("config.json");
String configJson = "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"logs\"}}";
Path directoryPath = Files.createDirectory(Paths.get("logs"));
File directory = directoryPath.toFile();
@Ignore
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnWin.class)
public void testJDK14LoggingWithClientConfigPermissionError() throws IOException {
File configFile = tmpFolder.newFile("config.json");
Path configFilePath = configFile.toPath();
File directory = tmpFolder.newFolder("logs");
Path directoryPath = directory.toPath();
String configJson =
"{\"common\":{\"log_level\":\"debug\",\"log_path\":\"" + directoryPath + "\"}}";
HashSet<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.GROUP_READ);
Expand All @@ -77,9 +93,6 @@ public void testJDK14LoggingWithClientConfigPermissionError() throws IOException
Properties properties = new Properties();
properties.put("client_config_file", configFilePath.toString());
assertThrows(SQLException.class, () -> getConnection(properties));

Files.delete(configFilePath);
directory.delete();
}

@Test
Expand All @@ -99,11 +112,15 @@ public void testJDK14LoggerWithQuotesInMessage() {
}

@Test
@Ignore
public void testJDK14LoggingWithMissingLogPathClientConfig() throws Exception {
Path configFilePath = Paths.get("config.json");
File configFile = tmpFolder.newFile("config.json");
Path configFilePath = configFile.toPath();
String configJson = "{\"common\":{\"log_level\":\"debug\"}}";
Path home = tmpFolder.getRoot().toPath();
System.setProperty("user.home", home.toString());

Path homeLogPath = Paths.get(homePath, "jdbc");
Path homeLogPath = Paths.get(home.toString(), "jdbc");
Files.write(configFilePath, configJson.getBytes());
Properties properties = new Properties();
properties.put("client_config_file", configFilePath.toString());
Expand All @@ -119,21 +136,23 @@ public void testJDK14LoggingWithMissingLogPathClientConfig() throws Exception {
Files.deleteIfExists(configFilePath);
FileUtils.deleteDirectory(new File(homeLogPath.toString()));
}
} finally {
System.setProperty("user.home", homePath);
}
}

@Test
@Ignore
public void testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig() throws Exception {
System.clearProperty("user.home");

Path configFilePath = Paths.get("config.json");
File configFile = tmpFolder.newFile("config.json");
Path configFilePath = configFile.toPath();
String configJson = "{\"common\":{\"log_level\":\"debug\"}}";
Files.write(configFilePath, configJson.getBytes());
Properties properties = new Properties();
properties.put("client_config_file", configFilePath.toString());
try (Connection connection = getConnection(properties);
Statement statement = connection.createStatement()) {

try (Connection connection = getConnection(properties)) {
fail("testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig failed");
} catch (SnowflakeSQLLoggedException e) {
// Succeed
Expand Down
Loading