Skip to content

Commit

Permalink
add try with resources, fix log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-nl committed Jun 3, 2024
1 parent ccf8929 commit 74a6fcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private void checkLogFolderPermissions(Path path) throws SnowflakeSQLLoggedExcep
|| folderPermissions.contains(PosixFilePermission.OTHERS_WRITE)
|| folderPermissions.contains(PosixFilePermission.OTHERS_READ)
|| folderPermissions.contains(PosixFilePermission.OTHERS_EXECUTE)) {
logger.info(
logger.warn(
"Access permission for the logs directory '{}' is currently {} and is potentially "
+ "accessible to users other than the owner of the logs directory.",
path.toString(),
Expand All @@ -297,7 +297,7 @@ private void checkLogFolderPermissions(Path path) throws SnowflakeSQLLoggedExcep
sfSession,
ErrorCode.INTERNAL_ERROR,
String.format(
"Un-able to get permissions of log directory %s ,%s",
"Unable to get permissions of log directory %s ,%s",
path.toString(), ex.getMessage(), ex.getCause()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,26 @@ public void testJDK14LoggerWithQuotesInMessage() {
}

@Test
public void testJDK14LoggingWithMissingLogPathClientConfig() throws IOException {
public void testJDK14LoggingWithMissingLogPathClientConfig() throws Exception {
Path configFilePath = Paths.get("config.json");
String configJson = "{\"common\":{\"log_level\":\"debug\"}}";

Path homeLogPath = Paths.get(homePath, "jdbc");
try {
Files.write(configFilePath, configJson.getBytes());
Properties properties = new Properties();
properties.put("client_config_file", configFilePath.toString());
Connection connection = getConnection(properties);
connection.createStatement().executeQuery("select 1");
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 {
statement.executeQuery("select 1");

File file = new File(homeLogPath.toString());
assertTrue(file.exists());
} catch (IOException e) {
fail("testJDK14LoggingWithMissingLogPathClientConfig failed");
} catch (SQLException e) {
fail("testJDK14LoggingWithMissingLogPathClientConfig failed");
} catch (Exception e) {
fail("testJDK14LoggingWithMissingLogPathClientConfig failed");
} finally {
Files.deleteIfExists(configFilePath);
FileUtils.deleteDirectory(new File(homeLogPath.toString()));
File file = new File(homeLogPath.toString());
assertTrue(file.exists());

} finally {
Files.deleteIfExists(configFilePath);
FileUtils.deleteDirectory(new File(homeLogPath.toString()));
}
}
}

Expand All @@ -131,11 +128,11 @@ public void testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig() throws Exc

Path configFilePath = Paths.get("config.json");
String configJson = "{\"common\":{\"log_level\":\"debug\"}}";
try {
Files.write(configFilePath, configJson.getBytes());
Properties properties = new Properties();
properties.put("client_config_file", configFilePath.toString());
Connection connection = getConnection(properties);
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()) {

fail("testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig failed");
} catch (SnowflakeSQLLoggedException e) {
Expand Down

0 comments on commit 74a6fcb

Please sign in to comment.