|
3 | 3 | */
|
4 | 4 | package net.snowflake.client.jdbc;
|
5 | 5 |
|
6 |
| -import static org.junit.Assert.assertEquals; |
7 |
| -import static org.junit.Assert.fail; |
| 6 | +import static org.junit.Assert.*; |
8 | 7 |
|
9 | 8 | import java.nio.charset.StandardCharsets;
|
10 | 9 | import java.sql.Connection;
|
11 | 10 | import java.sql.ResultSet;
|
12 | 11 | import java.sql.SQLException;
|
13 | 12 | import java.sql.Statement;
|
14 |
| -import java.util.Arrays; |
15 |
| -import java.util.List; |
| 13 | +import java.util.Properties; |
16 | 14 | import net.snowflake.client.ConditionalIgnoreRule;
|
17 | 15 | import net.snowflake.client.RunningOnGithubAction;
|
18 | 16 | import net.snowflake.client.category.TestCategoryOthers;
|
@@ -91,28 +89,30 @@ public void testUnusualStageName() throws Throwable {
|
91 | 89 |
|
92 | 90 | @Test
|
93 | 91 | @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
|
94 |
| - public void testDownloadToStreamBlobNotFound() throws SQLException { |
| 92 | + public void testDownloadToStreamBlobNotFoundGCS() throws SQLException { |
95 | 93 | final String DEST_PREFIX = TEST_UUID + "/testUploadStream";
|
96 | 94 | Connection connection = null;
|
97 | 95 | 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(); |
115 | 114 | }
|
| 115 | + closeSQLObjects(statement, connection); |
116 | 116 | }
|
117 | 117 | }
|
118 | 118 | }
|
0 commit comments