From 8fb4e63629a0e271e40f4275f2224554d5e7f61d Mon Sep 17 00:00:00 2001 From: sfc-gh-astachowski Date: Tue, 12 Nov 2024 10:57:54 +0100 Subject: [PATCH] Moved throw assertions to relevant lines --- .../client/config/SFPermissionsTest.java | 54 +++---- .../DatabaseMetaDataResultSetLatestIT.java | 32 ++--- .../client/jdbc/RestRequestTest.java | 136 +++++++++--------- ...akeAzureClientHandleExceptionLatestIT.java | 81 +++++------ .../client/jdbc/SnowflakeDriverIT.java | 12 +- .../client/jdbc/SnowflakeDriverLatestIT.java | 78 +++++----- ...flakeGcsClientHandleExceptionLatestIT.java | 83 +++++------ ...wflakeS3ClientHandleExceptionLatestIT.java | 93 ++++++------ .../storage/GcmEncryptionProviderTest.java | 34 ++--- ...ypesGetStringArrowJsonCompatibilityIT.java | 5 +- .../jdbc/telemetryOOB/TelemetryServiceIT.java | 17 +-- .../log/JDK14LoggerWithClientLatestIT.java | 9 +- 12 files changed, 289 insertions(+), 345 deletions(-) diff --git a/src/test/java/net/snowflake/client/config/SFPermissionsTest.java b/src/test/java/net/snowflake/client/config/SFPermissionsTest.java index f7c6b0863..f5e41e260 100644 --- a/src/test/java/net/snowflake/client/config/SFPermissionsTest.java +++ b/src/test/java/net/snowflake/client/config/SFPermissionsTest.java @@ -7,44 +7,13 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.PosixFilePermissions; -import java.util.stream.Stream; import net.snowflake.client.annotations.DontRunOnWindows; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.provider.CsvSource; public class SFPermissionsTest { - - static class PermissionProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(ExtensionContext context) throws Exception { - return Stream.of( - Arguments.of("rwx------", false), - Arguments.of("rw-------", false), - Arguments.of("r-x------", false), - Arguments.of("r--------", false), - Arguments.of("rwxrwx---", true), - Arguments.of("rwxrw----", true), - Arguments.of("rwxr-x---", false), - Arguments.of("rwxr-----", false), - Arguments.of("rwx-wx---", true), - Arguments.of("rwx-w----", true), - Arguments.of("rwx--x---", false), - Arguments.of("rwx---rwx", true), - Arguments.of("rwx---rw-", true), - Arguments.of("rwx---r-x", false), - Arguments.of("rwx---r--", false), - Arguments.of("rwx----wx", true), - Arguments.of("rwx----w-", true), - Arguments.of("rwx-----x", false)); - } - } - Path configFilePath = Paths.get("config.json"); String configJson = "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"logs\"}}"; @@ -59,7 +28,26 @@ public void cleanupConfigFile() throws IOException { } @ParameterizedTest - @ArgumentsSource(PermissionProvider.class) + @CsvSource({ + "rwx------,false", + "rw-------,false", + "r-x------,false", + "r--------,false", + "rwxrwx---,true", + "rwxrw----,true", + "rwxr-x---,false", + "rwxr-----,false", + "rwx-wx---,true", + "rwx-w----,true", + "rwx--x---,false", + "rwx---rwx,true", + "rwx---rw-,true", + "rwx---r-x,false", + "rwx---r--,false", + "rwx----wx,true", + "rwx----w-,true", + "rwx-----x,false" + }) @DontRunOnWindows public void testLogDirectoryPermissions(String permission, boolean isSucceed) throws IOException { // TODO: SNOW-1503722 Change to check for thrown exceptions diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultSetLatestIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultSetLatestIT.java index 2da8b2776..2a62be5a2 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultSetLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataResultSetLatestIT.java @@ -25,23 +25,21 @@ public class DatabaseMetaDataResultSetLatestIT extends BaseJDBCTest { @Test public void testGetObjectNotSupported() throws SQLException { - assertThrows( - SnowflakeLoggedFeatureNotSupportedException.class, - () -> { - try (Connection con = getConnection(); - Statement st = con.createStatement()) { - Object[][] rows = {{1.2F}}; - List columnNames = Arrays.asList("float"); - List columnTypeNames = Arrays.asList("FLOAT"); - List columnTypes = Arrays.asList(Types.FLOAT); - try (ResultSet resultSet = - new SnowflakeDatabaseMetaDataResultSet( - columnNames, columnTypeNames, columnTypes, rows, st)) { - resultSet.next(); - assertEquals(1.2F, resultSet.getObject(1)); - } - } - }); + try (Connection con = getConnection(); + Statement st = con.createStatement()) { + Object[][] rows = {{1.2F}}; + List columnNames = Arrays.asList("float"); + List columnTypeNames = Arrays.asList("FLOAT"); + List columnTypes = Arrays.asList(Types.FLOAT); + try (ResultSet resultSet = + new SnowflakeDatabaseMetaDataResultSet( + columnNames, columnTypeNames, columnTypes, rows, st)) { + resultSet.next(); + assertThrows( + SnowflakeLoggedFeatureNotSupportedException.class, + () -> assertEquals(1.2F, resultSet.getObject(1))); + } + } } /** Added in > 3.17.0 */ diff --git a/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java b/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java index 3c55638cb..7318454e0 100644 --- a/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java +++ b/src/test/java/net/snowflake/client/jdbc/RestRequestTest.java @@ -458,42 +458,38 @@ public CloseableHttpResponse answer(InvocationOnMock invocation) throws Throwabl } @Test - public void testMaxRetriesExceeded() { - assertThrows( - SnowflakeSQLException.class, - () -> { - boolean telemetryEnabled = TelemetryService.getInstance().isEnabled(); - - CloseableHttpClient client = mock(CloseableHttpClient.class); - when(client.execute(any(HttpUriRequest.class))) - .thenAnswer( - new Answer() { - int callCount = 0; - - @Override - public CloseableHttpResponse answer(InvocationOnMock invocation) - throws Throwable { - callCount += 1; - if (callCount >= 4) { - return successResponse(); - } else { - return socketTimeoutResponse(); - } - } - }); - - try { - TelemetryService.disable(); - execute(client, "fakeurl.com/?requestId=abcd-1234", 0, 0, 0, true, false, 1); - fail("testMaxRetries"); - } finally { - if (telemetryEnabled) { - TelemetryService.enable(); - } else { - TelemetryService.disable(); - } - } - }); + public void testMaxRetriesExceeded() throws IOException { + boolean telemetryEnabled = TelemetryService.getInstance().isEnabled(); + + CloseableHttpClient client = mock(CloseableHttpClient.class); + when(client.execute(any(HttpUriRequest.class))) + .thenAnswer( + new Answer() { + int callCount = 0; + + @Override + public CloseableHttpResponse answer(InvocationOnMock invocation) throws Throwable { + callCount += 1; + if (callCount >= 4) { + return successResponse(); + } else { + return socketTimeoutResponse(); + } + } + }); + + try { + TelemetryService.disable(); + assertThrows( + SnowflakeSQLException.class, + () -> execute(client, "fakeurl.com/?requestId=abcd-1234", 0, 0, 0, true, false, 1)); + } finally { + if (telemetryEnabled) { + TelemetryService.enable(); + } else { + TelemetryService.disable(); + } + } } @Test @@ -520,42 +516,38 @@ public CloseableHttpResponse answer(InvocationOnMock invocationOnMock) } @Test - public void testLoginMaxRetries() { - assertThrows( - SnowflakeSQLException.class, - () -> { - boolean telemetryEnabled = TelemetryService.getInstance().isEnabled(); - - CloseableHttpClient client = mock(CloseableHttpClient.class); - when(client.execute(any(HttpUriRequest.class))) - .thenAnswer( - new Answer() { - int callCount = 0; - - @Override - public CloseableHttpResponse answer(InvocationOnMock invocation) - throws Throwable { - callCount += 1; - if (callCount >= 4) { - return retryLoginResponse(); - } else { - return socketTimeoutResponse(); - } - } - }); - - try { - TelemetryService.disable(); - execute(client, "/session/v1/login-request", 0, 0, 0, true, false, 1); - fail("testMaxRetries"); - } finally { - if (telemetryEnabled) { - TelemetryService.enable(); - } else { - TelemetryService.disable(); - } - } - }); + public void testLoginMaxRetries() throws IOException { + boolean telemetryEnabled = TelemetryService.getInstance().isEnabled(); + + CloseableHttpClient client = mock(CloseableHttpClient.class); + when(client.execute(any(HttpUriRequest.class))) + .thenAnswer( + new Answer() { + int callCount = 0; + + @Override + public CloseableHttpResponse answer(InvocationOnMock invocation) throws Throwable { + callCount += 1; + if (callCount >= 4) { + return retryLoginResponse(); + } else { + return socketTimeoutResponse(); + } + } + }); + + try { + TelemetryService.disable(); + assertThrows( + SnowflakeSQLException.class, + () -> execute(client, "/session/v1/login-request", 0, 0, 0, true, false, 1)); + } finally { + if (telemetryEnabled) { + TelemetryService.enable(); + } else { + TelemetryService.disable(); + } + } } @Test diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java index 495ba6570..b1d975000 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeAzureClientHandleExceptionLatestIT.java @@ -161,38 +161,36 @@ public void errorInvalidKey() { @DontRunOnGithubActions public void errorInterruptedException() throws SQLException { // Can still retry, no error thrown + try { + spyingClient.handleStorageException( + new InterruptedException(), 0, "upload", sfSession, command, null); + } catch (Exception e) { + fail("Should not have exception here"); + } + Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); assertThrows( SnowflakeSQLException.class, - () -> { - try { + () -> spyingClient.handleStorageException( - new InterruptedException(), 0, "upload", sfSession, command, null); - } catch (Exception e) { - fail("Should not have exception here"); - } - Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); - spyingClient.handleStorageException( - new InterruptedException(), 26, "upload", sfSession, command, null); - }); + new InterruptedException(), 26, "upload", sfSession, command, null)); } @Test @DontRunOnGithubActions - public void errorSocketTimeoutException() { + public void errorSocketTimeoutException() throws SnowflakeSQLException { + // Can still retry, no error thrown + try { + spyingClient.handleStorageException( + new SocketTimeoutException(), 0, "upload", sfSession, command, null); + } catch (Exception e) { + fail("Should not have exception here"); + } + Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); assertThrows( SnowflakeSQLException.class, - () -> { - // Can still retry, no error thrown - try { + () -> spyingClient.handleStorageException( - new SocketTimeoutException(), 0, "upload", sfSession, command, null); - } catch (Exception e) { - fail("Should not have exception here"); - } - Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); - spyingClient.handleStorageException( - new SocketTimeoutException(), 26, "upload", sfSession, command, null); - }); + new SocketTimeoutException(), 26, "upload", sfSession, command, null)); } @Test @@ -207,30 +205,25 @@ public void errorUnknownException() { @Test @DontRunOnGithubActions - public void errorNoSpaceLeftOnDevice() { + public void errorNoSpaceLeftOnDevice() throws IOException { + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); + String destFolderCanonicalPath = destFolder.getCanonicalPath(); + String getCommand = + "get @testPutGet_stage/" + TEST_DATA_FILE + " 'file://" + destFolderCanonicalPath + "'"; assertThrows( SnowflakeSQLException.class, - () -> { - File destFolder = new File(tmpFolder, "dest"); - destFolder.mkdirs(); - String destFolderCanonicalPath = destFolder.getCanonicalPath(); - String getCommand = - "get @testPutGet_stage/" - + TEST_DATA_FILE - + " 'file://" - + destFolderCanonicalPath - + "'"; - spyingClient.handleStorageException( - new StorageException( - "", - Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, - new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), - 0, - "download", - null, - getCommand, - null); - }); + () -> + spyingClient.handleStorageException( + new StorageException( + "", + Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, + new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), + 0, + "download", + null, + getCommand, + null)); } @AfterEach diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java index 0d98e7689..49fd1b7e5 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverIT.java @@ -2747,14 +2747,10 @@ public void testPutGetToUnencryptedStage() throws Throwable { /** Prepare statement will fail if the connection is already closed. */ @Test - public void testNotClosedSession() { - assertThrows( - SQLException.class, - () -> { - Connection connection = getConnection(); - connection.close(); - connection.prepareStatement("select 1"); - }); + public void testNotClosedSession() throws SQLException { + Connection connection = getConnection(); + connection.close(); + assertThrows(SnowflakeSQLException.class, () -> connection.prepareStatement("select 1")); } @Test diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java index 453cfb6ca..b879facc5 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java @@ -1450,49 +1450,43 @@ public void testAzureS3UploadStreamingIngestFileMetadata() throws Throwable { } @Test - public void testNoSpaceLeftOnDeviceException() { - assertThrows( - SnowflakeSQLException.class, - () -> { - List supportedAccounts = - Arrays.asList("gcpaccount", "s3testaccount", "azureaccount"); - for (String accountName : supportedAccounts) { - try (Connection connection = getConnection(accountName)) { - SFSession sfSession = connection.unwrap(SnowflakeConnectionV1.class).getSfSession(); - try (Statement statement = connection.createStatement()) { - try { - SFStatement sfStatement = - statement.unwrap(SnowflakeStatementV1.class).getSfStatement(); - statement.execute("CREATE OR REPLACE STAGE testPutGet_stage"); - statement.execute( - "PUT file://" - + getFullPathFileInResource(TEST_DATA_FILE) - + " @testPutGet_stage"); - String command = "get @testPutGet_stage/" + TEST_DATA_FILE + " 'file:///tmp'"; - SnowflakeFileTransferAgent sfAgent = - new SnowflakeFileTransferAgent(command, sfSession, sfStatement); - StageInfo info = sfAgent.getStageInfo(); - SnowflakeStorageClient client = - StorageClientFactory.getFactory() - .createClient(info, 1, null, /* session= */ null); - - client.handleStorageException( - new StorageException( - client.getMaxRetries(), - Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, - new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), - client.getMaxRetries(), - "download", - null, - command, - null); - } finally { - statement.execute("DROP STAGE if exists testPutGet_stage"); - } - } - } + public void testNoSpaceLeftOnDeviceException() throws SQLException { + List supportedAccounts = Arrays.asList("gcpaccount", "s3testaccount", "azureaccount"); + for (String accountName : supportedAccounts) { + try (Connection connection = getConnection(accountName)) { + SFSession sfSession = connection.unwrap(SnowflakeConnectionV1.class).getSfSession(); + try (Statement statement = connection.createStatement()) { + try { + SFStatement sfStatement = statement.unwrap(SnowflakeStatementV1.class).getSfStatement(); + statement.execute("CREATE OR REPLACE STAGE testPutGet_stage"); + statement.execute( + "PUT file://" + getFullPathFileInResource(TEST_DATA_FILE) + " @testPutGet_stage"); + String command = "get @testPutGet_stage/" + TEST_DATA_FILE + " 'file:///tmp'"; + SnowflakeFileTransferAgent sfAgent = + new SnowflakeFileTransferAgent(command, sfSession, sfStatement); + StageInfo info = sfAgent.getStageInfo(); + SnowflakeStorageClient client = + StorageClientFactory.getFactory().createClient(info, 1, null, /* session= */ null); + + assertThrows( + SnowflakeSQLException.class, + () -> + client.handleStorageException( + new StorageException( + client.getMaxRetries(), + Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, + new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), + client.getMaxRetries(), + "download", + null, + command, + null)); + } finally { + statement.execute("DROP STAGE if exists testPutGet_stage"); } - }); + } + } + } } @Test diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java index 8776285cc..144424c36 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeGcsClientHandleExceptionLatestIT.java @@ -129,39 +129,37 @@ public void errorInvalidKey() { @Test @DontRunOnGithubActions public void errorInterruptedException() throws SQLException { + // Can still retry, no error thrown + try { + spyingClient.handleStorageException( + new InterruptedException(), 0, "upload", sfSession, command, null); + } catch (Exception e) { + fail("Should not have exception here"); + } + Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); assertThrows( SnowflakeSQLException.class, - () -> { - // Can still retry, no error thrown - try { + () -> spyingClient.handleStorageException( - new InterruptedException(), 0, "upload", sfSession, command, null); - } catch (Exception e) { - fail("Should not have exception here"); - } - Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); - spyingClient.handleStorageException( - new InterruptedException(), 26, "upload", sfSession, command, null); - }); + new InterruptedException(), 26, "upload", sfSession, command, null)); } @Test @DontRunOnGithubActions - public void errorSocketTimeoutException() { + public void errorSocketTimeoutException() throws SnowflakeSQLException { // Can still retry, no error thrown + try { + spyingClient.handleStorageException( + new SocketTimeoutException(), 0, "upload", sfSession, command, null); + } catch (Exception e) { + fail("Should not have exception here"); + } + Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); assertThrows( SnowflakeSQLException.class, - () -> { - try { + () -> spyingClient.handleStorageException( - new SocketTimeoutException(), 0, "upload", sfSession, command, null); - } catch (Exception e) { - fail("Should not have exception here"); - } - Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); - spyingClient.handleStorageException( - new SocketTimeoutException(), 26, "upload", sfSession, command, null); - }); + new SocketTimeoutException(), 26, "upload", sfSession, command, null)); } @Test @@ -187,30 +185,25 @@ public void errorWithNullSession() { @Test @DontRunOnGithubActions - public void errorNoSpaceLeftOnDevice() { + public void errorNoSpaceLeftOnDevice() throws IOException { + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); + String destFolderCanonicalPath = destFolder.getCanonicalPath(); + String getCommand = + "get @testPutGet_stage/" + TEST_DATA_FILE + " 'file://" + destFolderCanonicalPath + "'"; assertThrows( - SnowflakeSQLException.class, - () -> { - File destFolder = new File(tmpFolder, "dest"); - destFolder.mkdirs(); - String destFolderCanonicalPath = destFolder.getCanonicalPath(); - String getCommand = - "get @testPutGet_stage/" - + TEST_DATA_FILE - + " 'file://" - + destFolderCanonicalPath - + "'"; - spyingClient.handleStorageException( - new StorageException( - maxRetry, - Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, - new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), - 0, - "download", - null, - getCommand, - null); - }); + SQLException.class, + () -> + spyingClient.handleStorageException( + new StorageException( + maxRetry, + Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, + new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), + 0, + "download", + null, + getCommand, + null)); } @AfterEach diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java index 04ec5e673..ec7356eed 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeS3ClientHandleExceptionLatestIT.java @@ -164,40 +164,38 @@ public void errorInvalidKey() { @Test @DontRunOnGithubActions - public void errorInterruptedException() { + public void errorInterruptedException() throws SnowflakeSQLException { // Can still retry, no error thrown + try { + spyingClient.handleStorageException( + new InterruptedException(), 0, "upload", sfSession, command, null); + } catch (Exception e) { + fail("Should not have exception here"); + } + Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); assertThrows( SnowflakeSQLException.class, - () -> { - try { + () -> spyingClient.handleStorageException( - new InterruptedException(), 0, "upload", sfSession, command, null); - } catch (Exception e) { - fail("Should not have exception here"); - } - Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); - spyingClient.handleStorageException( - new InterruptedException(), 26, "upload", sfSession, command, null); - }); + new InterruptedException(), 26, "upload", sfSession, command, null)); } @Test @DontRunOnGithubActions - public void errorSocketTimeoutException() { + public void errorSocketTimeoutException() throws SnowflakeSQLException { + // Can still retry, no error thrown + try { + spyingClient.handleStorageException( + new SocketTimeoutException(), 0, "upload", sfSession, command, null); + } catch (Exception e) { + fail("Should not have exception here"); + } + Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); assertThrows( SnowflakeSQLException.class, - () -> { - // Can still retry, no error thrown - try { + () -> spyingClient.handleStorageException( - new SocketTimeoutException(), 0, "upload", sfSession, command, null); - } catch (Exception e) { - fail("Should not have exception here"); - } - Mockito.verify(spyingClient, Mockito.never()).renew(Mockito.anyMap()); - spyingClient.handleStorageException( - new SocketTimeoutException(), 26, "upload", sfSession, command, null); - }); + new SocketTimeoutException(), 26, "upload", sfSession, command, null)); } @Test @@ -213,42 +211,35 @@ public void errorUnknownException() { @Test @DontRunOnGithubActions public void errorRenewExpiredNullSession() { + // Unauthenticated, renew is called. + AmazonS3Exception ex = new AmazonS3Exception("unauthenticated"); + ex.setErrorCode(EXPIRED_AWS_TOKEN_ERROR_CODE); assertThrows( SnowflakeSQLException.class, - () -> { - // Unauthenticated, renew is called. - AmazonS3Exception ex = new AmazonS3Exception("unauthenticated"); - ex.setErrorCode(EXPIRED_AWS_TOKEN_ERROR_CODE); - spyingClient.handleStorageException(ex, 0, "upload", null, command, null); - }); + () -> spyingClient.handleStorageException(ex, 0, "upload", null, command, null)); } @Test @DontRunOnGithubActions - public void errorNoSpaceLeftOnDevice() { + public void errorNoSpaceLeftOnDevice() throws IOException { + File destFolder = new File(tmpFolder, "dest"); + destFolder.mkdirs(); + String destFolderCanonicalPath = destFolder.getCanonicalPath(); + String getCommand = + "get @testPutGet_stage/" + TEST_DATA_FILE + " 'file://" + destFolderCanonicalPath + "'"; assertThrows( SnowflakeSQLException.class, - () -> { - File destFolder = new File(tmpFolder, "dest"); - destFolder.mkdirs(); - String destFolderCanonicalPath = destFolder.getCanonicalPath(); - String getCommand = - "get @testPutGet_stage/" - + TEST_DATA_FILE - + " 'file://" - + destFolderCanonicalPath - + "'"; - spyingClient.handleStorageException( - new StorageException( - maxRetry, - Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, - new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), - 0, - "download", - null, - getCommand, - null); - }); + () -> + spyingClient.handleStorageException( + new StorageException( + maxRetry, + Constants.NO_SPACE_LEFT_ON_DEVICE_ERR, + new IOException(Constants.NO_SPACE_LEFT_ON_DEVICE_ERR)), + 0, + "download", + null, + getCommand, + null)); } @AfterEach diff --git a/src/test/java/net/snowflake/client/jdbc/cloud/storage/GcmEncryptionProviderTest.java b/src/test/java/net/snowflake/client/jdbc/cloud/storage/GcmEncryptionProviderTest.java index 9c34c2c06..f883324d3 100644 --- a/src/test/java/net/snowflake/client/jdbc/cloud/storage/GcmEncryptionProviderTest.java +++ b/src/test/java/net/snowflake/client/jdbc/cloud/storage/GcmEncryptionProviderTest.java @@ -138,21 +138,21 @@ public void testDecryptStreamWithInvalidKey() throws Exception { InputStream plainTextStream = new ByteArrayInputStream(plainText); byte[] cipherText = encryptStream(plainTextStream, dataAad, keyAad); + + byte[] encryptedKey = encKeyArgumentCaptor.getValue(); + encryptedKey[0] = (byte) ((encryptedKey[0] + 1) % 255); assertThrows( AEADBadTagException.class, - () -> { - byte[] encryptedKey = encKeyArgumentCaptor.getValue(); - encryptedKey[0] = (byte) ((encryptedKey[0] + 1) % 255); - IOUtils.toByteArray( - GcmEncryptionProvider.decryptStream( - new ByteArrayInputStream(cipherText), - Base64.getEncoder().encodeToString(encryptedKey), - Base64.getEncoder().encodeToString(dataIvDataArgumentCaptor.getValue()), - Base64.getEncoder().encodeToString(keyIvDataArgumentCaptor.getValue()), - encMat, - dataAad == null ? "" : Base64.getEncoder().encodeToString(dataAad), - keyAad == null ? "" : Base64.getEncoder().encodeToString(keyAad))); - }); + () -> + IOUtils.toByteArray( + GcmEncryptionProvider.decryptStream( + new ByteArrayInputStream(cipherText), + Base64.getEncoder().encodeToString(encryptedKey), + Base64.getEncoder().encodeToString(dataIvDataArgumentCaptor.getValue()), + Base64.getEncoder().encodeToString(keyIvDataArgumentCaptor.getValue()), + encMat, + dataAad == null ? "" : Base64.getEncoder().encodeToString(dataAad), + keyAad == null ? "" : Base64.getEncoder().encodeToString(keyAad)))); } @Test @@ -160,12 +160,12 @@ public void testDecryptStreamWithInvalidDataIV() throws Exception { InputStream plainTextStream = new ByteArrayInputStream(plainText); byte[] cipherText = encryptStream(plainTextStream, dataAad, keyAad); + byte[] dataIvBase64 = dataIvDataArgumentCaptor.getValue(); + dataIvBase64[0] = (byte) ((dataIvBase64[0] + 1) % 255); IOException ioException = assertThrows( IOException.class, () -> { - byte[] dataIvBase64 = dataIvDataArgumentCaptor.getValue(); - dataIvBase64[0] = (byte) ((dataIvBase64[0] + 1) % 255); IOUtils.toByteArray( GcmEncryptionProvider.decryptStream( new ByteArrayInputStream(cipherText), @@ -184,11 +184,11 @@ public void testDecryptStreamWithInvalidKeyIV() throws Exception { InputStream plainTextStream = new ByteArrayInputStream(plainText); byte[] cipherText = encryptStream(plainTextStream, dataAad, keyAad); + byte[] keyIvBase64 = keyIvDataArgumentCaptor.getValue(); + keyIvBase64[0] = (byte) ((keyIvBase64[0] + 1) % 255); assertThrows( AEADBadTagException.class, () -> { - byte[] keyIvBase64 = keyIvDataArgumentCaptor.getValue(); - keyIvBase64[0] = (byte) ((keyIvBase64[0] + 1) % 255); IOUtils.toByteArray( GcmEncryptionProvider.decryptStream( new ByteArrayInputStream(cipherText), diff --git a/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringArrowJsonCompatibilityIT.java b/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringArrowJsonCompatibilityIT.java index 2d5f46468..2245a2647 100644 --- a/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringArrowJsonCompatibilityIT.java +++ b/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringArrowJsonCompatibilityIT.java @@ -9,8 +9,8 @@ import net.snowflake.client.annotations.DontRunOnGithubActions; import net.snowflake.client.category.TestTags; import net.snowflake.client.jdbc.ResultSetFormatType; -import net.snowflake.client.providers.ResultFormatProvider; import net.snowflake.client.providers.ProvidersUtil; +import net.snowflake.client.providers.ResultFormatProvider; import net.snowflake.client.providers.SnowflakeArgumentsProvider; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -156,7 +156,8 @@ private static class DataProvider extends SnowflakeArgumentsProvider { @Override protected List rawArguments(ExtensionContext context) { - return ProvidersUtil.cartesianProduct(context, new ResultFormatProvider(), new SampleProvider()); + return ProvidersUtil.cartesianProduct( + context, new ResultFormatProvider(), new SampleProvider()); } } } diff --git a/src/test/java/net/snowflake/client/jdbc/telemetryOOB/TelemetryServiceIT.java b/src/test/java/net/snowflake/client/jdbc/telemetryOOB/TelemetryServiceIT.java index 6684ae510..e3999bf6a 100644 --- a/src/test/java/net/snowflake/client/jdbc/telemetryOOB/TelemetryServiceIT.java +++ b/src/test/java/net/snowflake/client/jdbc/telemetryOOB/TelemetryServiceIT.java @@ -395,16 +395,13 @@ public void testSnowflakeSQLLoggedExceptionIBTelemetry() throws SQLException { *

After running test, check for telemetry message in client_telemetry_v table. */ @Test - public void testSqlFeatureNotSupportedExceptionIBTelemetry() { + public void testSqlFeatureNotSupportedExceptionIBTelemetry() throws SQLException { // make a connection to initialize telemetry instance - assertThrows( - SQLFeatureNotSupportedException.class, - () -> { - try (Connection con = getConnection()) { - Statement statement = con.createStatement(); - // try to execute a statement that throws a SQLFeatureNotSupportedException - statement.execute("select 1", new int[] {}); - } - }); + try (Connection con = getConnection()) { + Statement statement = con.createStatement(); + // try to execute a statement that throws a SQLFeatureNotSupportedException + assertThrows( + SQLFeatureNotSupportedException.class, () -> statement.execute("select 1", new int[] {})); + } } } diff --git a/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java b/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java index 9e3442cbe..731e630ce 100644 --- a/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java +++ b/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java @@ -20,6 +20,7 @@ import net.snowflake.client.AbstractDriverIT; import net.snowflake.client.annotations.DontRunOnWindows; import net.snowflake.client.category.TestTags; +import net.snowflake.client.jdbc.SnowflakeSQLException; import net.snowflake.client.jdbc.SnowflakeSQLLoggedException; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Disabled; @@ -64,12 +65,12 @@ public void testJDK14LoggingWithClientConfig() throws IOException { @Test public void testJDK14LoggingWithClientConfigInvalidConfigFilePath() { + Path configFilePath = Paths.get("invalid.json"); + Properties properties = new Properties(); + properties.put("client_config_file", configFilePath.toString()); assertThrows( - SQLException.class, + SnowflakeSQLException.class, () -> { - Path configFilePath = Paths.get("invalid.json"); - Properties properties = new Properties(); - properties.put("client_config_file", configFilePath.toString()); try (Connection connection = getConnection(properties)) { connection.createStatement().executeQuery("select 1"); }