Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.cloud.bigquery.jdbc.it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -29,7 +28,6 @@
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
Expand All @@ -47,14 +45,8 @@ private void validateConnection(String connection_uri) throws SQLException {
Connection connection = DriverManager.getConnection(connection_uri);
assertNotNull(connection);
assertFalse(connection.isClosed());
String query = "SELECT DISTINCT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 850";
Statement statement = connection.createStatement();
ResultSet jsonResultSet = statement.executeQuery(query);
int totalRows = 0;
while (jsonResultSet.next()) {
totalRows += 1;
}
assertEquals(totalRows, 850);
validateStatement(statement, 850);
connection.close();
}

Expand Down Expand Up @@ -177,11 +169,7 @@ public void testValidGoogleUserAccountAuthentication() throws SQLException {
assertFalse(connection.isClosed());

Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50");

assertEquals(50, resultSetRowCount(resultSet));
validateStatement(statement, 50);
connection.close();
}

Expand All @@ -204,11 +192,7 @@ public void testValidExternalAccountAuthentication() throws SQLException {
assertFalse(connection.isClosed());

Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50");

assertEquals(50, resultSetRowCount(resultSet));
validateStatement(statement, 50);
connection.close();
}

Expand All @@ -227,11 +211,7 @@ public void testValidExternalAccountAuthenticationFromFile() throws SQLException
assertFalse(connection.isClosed());

Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50");

assertEquals(50, resultSetRowCount(resultSet));
validateStatement(statement, 50);
connection.close();
}

Expand Down Expand Up @@ -261,11 +241,7 @@ public void testValidExternalAccountAuthenticationRawJson() throws SQLException
assertFalse(connection.isClosed());

Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50");

assertEquals(50, resultSetRowCount(resultSet));
validateStatement(statement, 50);
connection.close();
}

Expand All @@ -275,6 +251,7 @@ public void testValidExternalAccountAuthenticationRawJson() throws SQLException
"https://www.googleapis.com/auth/bigquery, false"
})
@Tag("advanced")
@Tag("disable_tpc")
public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean isReadOnly)
throws Exception {
final JsonObject authJson = getAuthJson();
Expand Down Expand Up @@ -316,11 +293,7 @@ public void testValidRefreshTokenAuthentication() throws SQLException {
assertFalse(connection.isClosed());

Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(
"SELECT word FROM `bigquery-public-data.samples.shakespeare` LIMIT 50");

assertEquals(50, resultSetRowCount(resultSet));
validateStatement(statement, 50);
connection.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.bigquery.jdbc.it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -429,4 +430,16 @@ public static List<String> getInfoBySQL(Connection connection, String sqlCmd)
}
return result;
}

public static void validateStatement(Statement stmt, int expectedRows) throws SQLException {
String query = "SELECT * FROM UNNEST(GENERATE_ARRAY(1, " + expectedRows + "))";
assertTrue(stmt.execute(query));
int count = 0;
try (ResultSet rs = stmt.getResultSet()) {
while (rs.next()) {
count++;
}
}
assertEquals(expectedRows, count);
}
}
Loading
Loading