Skip to content

Commit 85381e7

Browse files
SNOW-748294 Fix test failures (#1287)
moving test to latestIT, fixing gcs tests
1 parent 7fd2ffd commit 85381e7

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

src/test/java/net/snowflake/client/jdbc/FileUploaderLatestIT.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public void testGetObjectMetadataWithGCS() throws Exception {
125125
public void testGetObjectMetadataFileNotFoundWithGCS() throws Exception {
126126
Connection connection = null;
127127
try {
128-
connection = getConnection("gcpaccount");
128+
Properties paramProperties = new Properties();
129+
paramProperties.put("GCS_USE_DOWNSCOPED_CREDENTIAL", true);
130+
connection = getConnection("gcpaccount", paramProperties);
129131
Statement statement = connection.createStatement();
130132
statement.execute("CREATE OR REPLACE STAGE " + OBJ_META_STAGE);
131133

@@ -151,6 +153,7 @@ public void testGetObjectMetadataFileNotFoundWithGCS() throws Exception {
151153
assertTrue(
152154
"Wrong type of exception. Message: " + ex.getMessage(),
153155
ex instanceof StorageProviderException);
156+
assertTrue(ex.getMessage().matches(".*Blob.*not found in bucket.*"));
154157
} finally {
155158
if (connection != null) {
156159
connection.createStatement().execute("DROP STAGE if exists " + OBJ_META_STAGE);
@@ -164,7 +167,9 @@ public void testGetObjectMetadataFileNotFoundWithGCS() throws Exception {
164167
public void testGetObjectMetadataStorageExceptionWithGCS() throws Exception {
165168
Connection connection = null;
166169
try {
167-
connection = getConnection("gcpaccount");
170+
Properties paramProperties = new Properties();
171+
paramProperties.put("GCS_USE_DOWNSCOPED_CREDENTIAL", true);
172+
connection = getConnection("gcpaccount", paramProperties);
168173
Statement statement = connection.createStatement();
169174
statement.execute("CREATE OR REPLACE STAGE " + OBJ_META_STAGE);
170175

@@ -189,6 +194,7 @@ public void testGetObjectMetadataStorageExceptionWithGCS() throws Exception {
189194
assertTrue(
190195
"Wrong type of exception. Message: " + ex.getMessage(),
191196
ex instanceof StorageProviderException);
197+
assertTrue(ex.getMessage().matches(".*Permission.*denied.*"));
192198
} finally {
193199
if (connection != null) {
194200
connection.createStatement().execute("DROP STAGE if exists " + OBJ_META_STAGE);

src/test/java/net/snowflake/client/jdbc/StreamIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
*/
44
package net.snowflake.client.jdbc;
55

6-
import static org.junit.Assert.*;
6+
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assert.assertTrue;
78

89
import java.io.InputStream;
910
import java.io.StringWriter;

src/test/java/net/snowflake/client/jdbc/StreamLatestIT.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
*/
44
package net.snowflake.client.jdbc;
55

6-
import static org.junit.Assert.assertEquals;
7-
import static org.junit.Assert.fail;
6+
import static org.junit.Assert.*;
87

98
import java.nio.charset.StandardCharsets;
109
import java.sql.Connection;
1110
import java.sql.ResultSet;
1211
import java.sql.SQLException;
1312
import java.sql.Statement;
14-
import java.util.Arrays;
15-
import java.util.List;
13+
import java.util.Properties;
1614
import net.snowflake.client.ConditionalIgnoreRule;
1715
import net.snowflake.client.RunningOnGithubAction;
1816
import net.snowflake.client.category.TestCategoryOthers;
@@ -91,28 +89,30 @@ public void testUnusualStageName() throws Throwable {
9189

9290
@Test
9391
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
94-
public void testDownloadToStreamBlobNotFound() throws SQLException {
92+
public void testDownloadToStreamBlobNotFoundGCS() throws SQLException {
9593
final String DEST_PREFIX = TEST_UUID + "/testUploadStream";
9694
Connection connection = null;
9795
Statement statement = null;
98-
List<String> supportedAccounts = Arrays.asList("gcpaccount", "s3testaccount", "azureaccount");
99-
for (String accountName : supportedAccounts) {
100-
try {
101-
connection = getConnection(accountName);
102-
statement = connection.createStatement();
103-
connection
104-
.unwrap(SnowflakeConnection.class)
105-
.downloadStream("~", DEST_PREFIX + "/abc.gz", true);
106-
fail("should throw an exception for blob/key not found");
107-
} catch (Exception ex) {
108-
System.out.println("Negative test to hit expected exception: " + ex.getMessage());
109-
} finally {
110-
if (statement != null) {
111-
statement.execute("rm @~/" + DEST_PREFIX);
112-
statement.close();
113-
}
114-
closeSQLObjects(statement, connection);
96+
try {
97+
Properties paramProperties = new Properties();
98+
paramProperties.put("GCS_USE_DOWNSCOPED_CREDENTIAL", true);
99+
connection = getConnection("gcpaccount", paramProperties);
100+
statement = connection.createStatement();
101+
connection
102+
.unwrap(SnowflakeConnection.class)
103+
.downloadStream("~", DEST_PREFIX + "/abc.gz", true);
104+
fail("should throw a storage provider exception for blob not found");
105+
} catch (Exception ex) {
106+
assertTrue(ex instanceof SQLException);
107+
assertTrue(
108+
"Wrong exception message: " + ex.getMessage(),
109+
ex.getMessage().matches(".*Blob.*not found in bucket.*"));
110+
} finally {
111+
if (statement != null) {
112+
statement.execute("rm @~/" + DEST_PREFIX);
113+
statement.close();
115114
}
115+
closeSQLObjects(statement, connection);
116116
}
117117
}
118118
}

0 commit comments

Comments
 (0)