Skip to content

Commit

Permalink
Run downloadToStream() test on azure and S3 accounts (#1285)
Browse files Browse the repository at this point in the history
run downloadStream test on azure and S3 accounts
  • Loading branch information
sfc-gh-ext-simba-lb authored Mar 10, 2023
1 parent 85381e7 commit f7ae088
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/test/java/net/snowflake/client/jdbc/StreamIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnTestaccount;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.category.TestCategoryOthers;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
Expand Down Expand Up @@ -75,39 +77,42 @@ public void testUploadStream() throws Throwable {
* @throws Throwable if any error occurs.
*/
@Test
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnTestaccount.class)
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
public void testDownloadStream() throws Throwable {
final String DEST_PREFIX = TEST_UUID + "/testUploadStream";
Connection connection = null;
Statement statement = null;
try {
connection = getConnection();
statement = connection.createStatement();
ResultSet rset =
statement.executeQuery(
"PUT file://" + getFullPathFileInResource(TEST_DATA_FILE) + " @~/" + DEST_PREFIX);
assertTrue(rset.next());
assertEquals("UPLOADED", rset.getString(7));

InputStream out =
connection
.unwrap(SnowflakeConnection.class)
.downloadStream("~", DEST_PREFIX + "/" + TEST_DATA_FILE + ".gz", true);
StringWriter writer = new StringWriter();
IOUtils.copy(out, writer, "UTF-8");
String output = writer.toString();
// the first 2 characters
assertEquals("1|", output.substring(0, 2));

// the number of lines
String[] lines = output.split("\n");
assertEquals(28, lines.length);
} finally {
if (statement != null) {
statement.execute("rm @~/" + DEST_PREFIX);
statement.close();
List<String> supportedAccounts = Arrays.asList("s3testaccount", "azureaccount");
for (String accountName : supportedAccounts) {
try {
connection = getConnection(accountName);
statement = connection.createStatement();
ResultSet rset =
statement.executeQuery(
"PUT file://" + getFullPathFileInResource(TEST_DATA_FILE) + " @~/" + DEST_PREFIX);
assertTrue(rset.next());
assertEquals("UPLOADED", rset.getString(7));

InputStream out =
connection
.unwrap(SnowflakeConnection.class)
.downloadStream("~", DEST_PREFIX + "/" + TEST_DATA_FILE + ".gz", true);
StringWriter writer = new StringWriter();
IOUtils.copy(out, writer, "UTF-8");
String output = writer.toString();
// the first 2 characters
assertEquals("1|", output.substring(0, 2));

// the number of lines
String[] lines = output.split("\n");
assertEquals(28, lines.length);
} finally {
if (statement != null) {
statement.execute("rm @~/" + DEST_PREFIX);
statement.close();
}
closeSQLObjects(statement, connection);
}
closeSQLObjects(statement, connection);
}
}

Expand Down

0 comments on commit f7ae088

Please sign in to comment.