diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java index 0877553e42c0..1d6bac0cd257 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java @@ -90,7 +90,7 @@ public void testValidServiceAccountAuthentication() throws SQLException, IOExcep Files.write(tempFile.toPath(), authJson.toString().getBytes()); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + getBaseConnectionUrl() + "ProjectId=" + authJson.get("project_id").getAsString() + ";OAuthType=0;" @@ -104,11 +104,7 @@ public void testValidServiceAccountAuthentication() throws SQLException, IOExcep @Test public void testServiceAccountAuthenticationMissingOAuthPvtKeyPath() throws SQLException { - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "ProjectId=" - + PROJECT_ID - + ";OAuthType=0;"; + String connection_uri = getBaseConnectionUrl() + "ProjectId=" + PROJECT_ID + ";OAuthType=0;"; try { DriverManager.getConnection(connection_uri); @@ -127,7 +123,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsPath() Files.write(tempFile.toPath(), authJson.toString().getBytes()); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + getBaseConnectionUrl() + "ProjectId=" + authJson.get("project_id").getAsString() + ";OAuthType=0;" @@ -144,7 +140,7 @@ public void testValidServiceAccountAuthenticationViaEmailAndPkcs8Key() final JsonObject authJson = getAuthJson(); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + getBaseConnectionUrl() + "ProjectId=" + authJson.get("project_id").getAsString() + ";OAuthType=0;" @@ -162,7 +158,7 @@ public void testValidServiceAccountAuthenticationOAuthPvtKeyAsJson() final JsonObject authJson = getAuthJson(); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + getBaseConnectionUrl() + "ProjectId=" + authJson.get("project_id").getAsString() + ";OAuthType=0;" @@ -192,9 +188,12 @@ public void testValidServiceAccountAuthenticationP12() throws SQLException, IOEx @Disabled public void testValidGoogleUserAccountAuthentication() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" + getBaseConnectionUrl() + + "PROJECTID=" + PROJECT_ID - + ";OAuthType=1;OAuthClientId=client_id;OAuthClientSecret=client_secret;"; + + ";OAuthType=1;" + + "OAuthClientId=client_id;" + + "OAuthClientSecret=client_secret;"; Connection connection = DriverManager.getConnection(connection_uri); assertNotNull(connection); @@ -213,12 +212,15 @@ public void testValidGoogleUserAccountAuthentication() throws SQLException { @Disabled public void testValidExternalAccountAuthentication() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" + getBaseConnectionUrl() + + "PROJECTID=" + PROJECT_ID + ";OAUTHTYPE=4;" + "BYOID_AudienceUri=//iam.googleapis.com/projects//locations//workloadIdentityPools//providers/;" - + "BYOID_SubjectTokenType=;BYOID_CredentialSource={\"file\":\"/path/to/file\"};" - + "BYOID_SA_Impersonation_Uri=;BYOID_TokenUri=;"; + + "BYOID_SubjectTokenType=;" + + "BYOID_CredentialSource={\"file\":\"/path/to/file\"};" + + "BYOID_SA_Impersonation_Uri=;" + + "BYOID_TokenUri=;"; Connection connection = DriverManager.getConnection(connection_uri); assertNotNull(connection); @@ -237,7 +239,8 @@ public void testValidExternalAccountAuthentication() throws SQLException { @Disabled public void testValidExternalAccountAuthenticationFromFile() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" + getBaseConnectionUrl() + + "PROJECTID=" + PROJECT_ID + ";OAUTHTYPE=4;" + "OAuthPvtKeyPath=/path/to/file;"; @@ -259,9 +262,11 @@ public void testValidExternalAccountAuthenticationFromFile() throws SQLException @Disabled public void testValidExternalAccountAuthenticationRawJson() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" + getBaseConnectionUrl() + + "PROJECTID=" + PROJECT_ID - + ";OAUTHTYPE=4;OAuthPvtKey={\n" + + ";OAUTHTYPE=4;" + + "OAuthPvtKey={\n" + " \"universe_domain\": \"googleapis.com\",\n" + " \"type\": \"external_account\",\n" + " \"audience\":" @@ -303,7 +308,8 @@ public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean String accessToken = credentials.getAccessToken().getTokenValue(); String connectionUri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=" + getBaseConnectionUrl() + + "ProjectId=" + authJson.get("project_id").getAsString() + ";OAuthType=2" + ";OAuthAccessToken=" @@ -319,10 +325,13 @@ public void testValidPreGeneratedAccessTokenAuthentication(String scope, boolean @Disabled public void testValidRefreshTokenAuthentication() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" + getBaseConnectionUrl() + + "PROJECTID=" + PROJECT_ID - + ";OAUTHTYPE=2;OAuthRefreshToken=refresh_token;" - + ";OAuthClientId=client;OAuthClientSecret=secret;"; + + ";OAUTHTYPE=2;" + + "OAuthRefreshToken=refresh_token;" + + ";OAuthClientId=client;" + + "OAuthClientSecret=secret;"; Connection connection = DriverManager.getConnection(connection_uri); assertNotNull(connection); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java index 5b4d36fac4fe..5b6377f6f885 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java @@ -23,6 +23,7 @@ import com.google.cloud.bigquery.BigQueryOptions; import com.google.cloud.bigquery.QueryJobConfiguration; import com.google.cloud.bigquery.jdbc.BigQueryJdbcBaseTest; +import com.google.cloud.bigquery.jdbc.utils.TestUtilities; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -177,10 +178,13 @@ private static void registerShutdownHook(final String dataset) { } public static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId(); + + public static String getBaseConnectionUrl() { + return TestUtilities.getBaseConnectionUrl(); + } + public static String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=" - + DEFAULT_CATALOG - + ";OAuthType=3;Timeout=3600;"; + getBaseConnectionUrl() + "ProjectId=" + DEFAULT_CATALOG + ";OAuthType=3;Timeout=3600;"; public static final String createDatasetQuery = "CREATE SCHEMA IF NOT EXISTS `%s.%s` OPTIONS(default_table_expiration_days = 5)"; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java index 9fe1c4f0f2fc..44a8160f726d 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java @@ -64,11 +64,8 @@ public class ITBigQueryJDBCTest extends ITBase { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); - static final String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; - static final String session_enabled_connection_uri = connection_uri + ";EnableSession=1"; + static final String connection_uri = ITBase.connectionUrl; + static final String session_enabled_connection_uri = connection_uri + "EnableSession=1;"; private static final String BASE_QUERY = "SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 order by" + " trip_distance asc LIMIT %s"; @@ -109,10 +106,8 @@ public void testValidAllDataTypesSerializationFromSelectQueryArrowDataset() thro String TABLE_NAME = "JDBC_INTEGRATION_ARROW_TEST_TABLE"; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME + " LIMIT 5000;"; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + DEFAULT_CATALOG - + ";EnableHighThroughputAPI=1;" + ITBigQueryJDBCTest.connection_uri + + "EnableHighThroughputAPI=1;" + "HighThroughputActivationRatio=2;" + "HighThroughputMinTableSize=1000;"; @@ -240,10 +235,11 @@ public void testReadAPIPathLarge() throws SQLException { @Test public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { String connectionUri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + DEFAULT_CATALOG - + ";OAUTHTYPE=3;MaxResults=300;HighThroughputActivationRatio=2;" - + "HighThroughputMinTableSize=100;EnableHighThroughputAPI=1"; + ITBigQueryJDBCTest.connection_uri + + "MaxResults=300;" + + "HighThroughputActivationRatio=2;" + + "HighThroughputMinTableSize=100;" + + "EnableHighThroughputAPI=1"; Connection connection = DriverManager.getConnection(connectionUri); Statement statement = connection.createStatement(); int expectedCnt = 1000; @@ -257,10 +253,10 @@ public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { @Test public void testReadAPIPathLargeWithThresholdNotMet() throws SQLException { String connectionUri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + DEFAULT_CATALOG - + ";OAUTHTYPE=3;HighThroughputActivationRatio=4;" - + "HighThroughputMinTableSize=100;EnableHighThroughputAPI=1"; + ITBigQueryJDBCTest.connection_uri + + "HighThroughputActivationRatio=4;" + + "HighThroughputMinTableSize=100;" + + "EnableHighThroughputAPI=1"; Connection connection = DriverManager.getConnection(connectionUri); Statement statement = connection.createStatement(); int expectedCnt = 5000; @@ -305,10 +301,7 @@ public void testInvalidQuery() throws SQLException { @Test public void testDriver() throws SQLException { - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; + String connection_uri = ITBigQueryJDBCTest.connection_uri; Driver driver = BigQueryDriver.getRegisteredDriver(); assertTrue(driver.acceptsURL(connection_uri)); @@ -323,10 +316,7 @@ public void testDriver() throws SQLException { @Test public void testDefaultDataset() throws SQLException { - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;DEFAULTDATASET=testDataset"; + String connection_uri = ITBigQueryJDBCTest.connection_uri + "DEFAULTDATASET=testDataset"; Driver driver = BigQueryDriver.getRegisteredDriver(); assertTrue(driver.acceptsURL(connection_uri)); @@ -337,10 +327,7 @@ public void testDefaultDataset() throws SQLException { DatasetId.of("testDataset"), connection.unwrap(BigQueryConnection.class).getDefaultDataset()); - String connection_uri_null_default_dataset = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; + String connection_uri_null_default_dataset = ITBigQueryJDBCTest.connection_uri; assertTrue(driver.acceptsURL(connection_uri_null_default_dataset)); @@ -354,11 +341,7 @@ public void testDefaultDataset() throws SQLException { @Test public void testDefaultDatasetWithProject() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;DEFAULTDATASET=" - + PROJECT_ID - + ".testDataset"; + ITBigQueryJDBCTest.connection_uri + "DEFAULTDATASET=" + PROJECT_ID + ".testDataset"; Driver driver = BigQueryDriver.getRegisteredDriver(); assertTrue(driver.acceptsURL(connection_uri)); @@ -373,10 +356,7 @@ public void testDefaultDatasetWithProject() throws SQLException { @Test public void testLocation() throws SQLException { - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;LOCATION=EU"; + String connection_uri = ITBigQueryJDBCTest.connection_uri + "LOCATION=EU"; Driver driver = BigQueryDriver.getRegisteredDriver(); assertTrue(driver.acceptsURL(connection_uri)); @@ -392,10 +372,7 @@ public void testLocation() throws SQLException { ResultSet resultSet = statement.executeQuery(query); assertEquals(100, resultSetRowCount(resultSet)); - String connection_uri_null_location = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; + String connection_uri_null_location = ITBigQueryJDBCTest.connection_uri; assertTrue(driver.acceptsURL(connection_uri_null_location)); @@ -408,10 +385,7 @@ public void testLocation() throws SQLException { @Test public void testIncorrectLocation() throws SQLException { - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;LOCATION=europe-west3"; + String connection_uri = ITBigQueryJDBCTest.connection_uri + "LOCATION=europe-west3"; Driver driver = BigQueryDriver.getRegisteredDriver(); @@ -1291,12 +1265,13 @@ public void testAllValidStatementTypesForAddBatch() throws SQLException { public void testUnsupportedHTAPIFallbacksToStandardQueriesWithRange() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` LIMIT 5000;"; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";MaxResults=500;HighThroughputActivationRatio=1;" + ITBigQueryJDBCTest.connection_uri + + "MaxResults=500;" + + "HighThroughputActivationRatio=1;" + "HighThroughputMinTableSize=100;" - + "EnableHighThroughputAPI=1;UnsupportedHTAPIFallback=1;JobCreationMode=1;"; + + "EnableHighThroughputAPI=1;" + + "UnsupportedHTAPIFallback=1;" + + "JobCreationMode=1;"; // Read data via JDBC Connection connection = DriverManager.getConnection(connection_uri); @@ -1315,12 +1290,12 @@ public void testIntervalDataTypeWithArrowResultSet() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` order by intColumn limit 5000;"; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";MaxResults=500;HighThroughputActivationRatio=0;" + ITBigQueryJDBCTest.connection_uri + + "MaxResults=500;" + + "HighThroughputActivationRatio=0;" + "HighThroughputMinTableSize=100;" - + "EnableHighThroughputAPI=1;JobCreationMode=1;"; + + "EnableHighThroughputAPI=1;" + + "JobCreationMode=1;"; // Read data via JDBC Connection connection = DriverManager.getConnection(connection_uri); @@ -1340,12 +1315,12 @@ public void testIntervalDataTypeWithJsonResultSet() throws SQLException { String selectQuery = "select * from `DATATYPERANGETEST.RangeIntervalTestTable` order by intColumn limit 10 ;"; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";MaxResults=500;HighThroughputActivationRatio=1;" + ITBigQueryJDBCTest.connection_uri + + "MaxResults=500;" + + "HighThroughputActivationRatio=1;" + "HighThroughputMinTableSize=100;" - + "EnableHighThroughputAPI=0;JobCreationMode=1;"; + + "EnableHighThroughputAPI=0;" + + "JobCreationMode=1;"; // Read data via JDBC Connection connection = DriverManager.getConnection(connection_uri); @@ -1366,11 +1341,7 @@ public void testValidLEPEndpointQuery() throws SQLException { String TABLE_NAME = "REGIONAL_TABLE"; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME; String connection_uri = - "jdbc:bigquery://https://googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";" + ITBigQueryJDBCTest.connection_uri + "EndpointOverrides=BIGQUERY=https://us-east4-bigquery.googleapis.com;"; // Read data via JDBC @@ -1386,11 +1357,7 @@ public void testValidEndpointWithInvalidBQPortThrows() throws SQLException { String TABLE_NAME = "JDBC_REGIONAL_TABLE_" + randomNumber; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME; String connection_uri = - "jdbc:bigquery://https://googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";" + ITBigQueryJDBCTest.connection_uri + "EndpointOverrides=BIGQUERY=https://us-east4-bigquery.googleapis.com:12312312;"; // Read data via JDBC @@ -1406,11 +1373,7 @@ public void testLEPEndpointDataNotFoundThrows() throws SQLException { String TABLE_NAME = "REGIONAL_TABLE"; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";" + ITBigQueryJDBCTest.connection_uri + "EndpointOverrides=BIGQUERY=https://us-east5-bigquery.googleapis.com;"; // Attempting read data via JDBC @@ -1426,11 +1389,7 @@ public void testValidREPEndpointQuery() throws SQLException { String TABLE_NAME = "REGIONAL_TABLE"; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";" + ITBigQueryJDBCTest.connection_uri + "EndpointOverrides=BIGQUERY=https://bigquery.us-east4.rep.googleapis.com;"; // Read data via JDBC @@ -1447,11 +1406,7 @@ public void testREPEndpointDataNotFoundThrows() throws SQLException { String TABLE_NAME = "REGIONAL_TABLE"; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";" + ITBigQueryJDBCTest.connection_uri + "EndpointOverrides=BIGQUERY=https://bigquery.us-east7.rep.googleapis.com;"; // Attempting read data via JDBC @@ -1527,7 +1482,7 @@ public void testConnectionIsValid() throws SQLException { @Test public void testDataSource() throws SQLException { DataSource ds = new DataSource(); - ds.setURL("jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"); + ds.setURL(getBaseConnectionUrl()); ds.setOAuthType(3); try (Connection connection = ds.getConnection()) { @@ -1540,7 +1495,7 @@ public void testDataSourceOAuthPvtKeyPath() throws SQLException, IOException { File tempFile = File.createTempFile("auth", ".json"); tempFile.deleteOnExit(); DataSource ds = new DataSource(); - ds.setURL("jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"); + ds.setURL(getBaseConnectionUrl()); ds.setOAuthType(0); ds.setOAuthPvtKeyPath(tempFile.toPath().toString()); assertEquals(0, ds.getOAuthType().intValue()); @@ -1697,11 +1652,8 @@ public void testPreparedStatementDateTimeValues() throws SQLException { public void testValidDestinationTableSavesQueriesWithLegacySQL() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=BIG_QUERY;" + ITBigQueryJDBCTest.connection_uri + + "QueryDialect=BIG_QUERY;" + "AllowLargeResults=1;" + "LargeResultTable=destination_table_test_legacy;" + "LargeResultDataset=INTEGRATION_TESTS;"; @@ -1729,12 +1681,7 @@ public void testValidDestinationTableSavesQueriesWithLegacySQL() throws SQLExcep @Test public void testNonEnabledUseLegacySQLThrowsSyntaxError() throws SQLException { // setup - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + DEFAULT_CATALOG - + ";"; + String connection_uri = ITBigQueryJDBCTest.connection_uri; String selectLegacyQuery = "SELECT * FROM [bigquery-public-data.deepmind_alphafold.metadata] LIMIT 20000000;"; Connection connection = DriverManager.getConnection(connection_uri, new Properties()); @@ -1749,11 +1696,7 @@ public void testNonEnabledUseLegacySQLThrowsSyntaxError() throws SQLException { public void testUseLegacySQLWithLargeResultsNotAllowedQueries() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + DEFAULT_CATALOG - + ";QueryDialect=BIG_QUERY;AllowLargeResults=0;"; + ITBigQueryJDBCTest.connection_uri + "QueryDialect=BIG_QUERY;" + "AllowLargeResults=0;"; String selectLegacyQuery = "SELECT * FROM [bigquery-public-data.deepmind_alphafold.metadata] LIMIT 250000;"; Connection connection = DriverManager.getConnection(connection_uri, new Properties()); @@ -1771,11 +1714,8 @@ public void testUseLegacySQLWithLargeResultsNotAllowedQueries() throws SQLExcept public void testValidDestinationTableSavesQueriesWithStandardSQL() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=SQL;" + ITBigQueryJDBCTest.connection_uri + + "QueryDialect=SQL;" + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;"; String selectLegacyQuery = @@ -1804,11 +1744,8 @@ public void testDestinationTableAndDestinationDatasetThatDoesNotExistsCreates() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=BIG_QUERY;" + ITBigQueryJDBCTest.connection_uri + + "QueryDialect=BIG_QUERY;" + "AllowLargeResults=1;" + "LargeResultTable=FakeTable;" + "LargeResultDataset=FakeDataset;"; @@ -1837,11 +1774,7 @@ public void testUseLegacySQLWithLargeResultsAllowedWithNoDestinationTableDefault throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + DEFAULT_CATALOG - + ";QueryDialect=BIG_QUERY;AllowLargeResults=1;"; + ITBigQueryJDBCTest.connection_uri + "QueryDialect=BIG_QUERY;" + "AllowLargeResults=1;"; String selectLegacyQuery = "SELECT * FROM [bigquery-public-data.deepmind_alphafold.metadata] LIMIT 250000;"; Connection connection = DriverManager.getConnection(connection_uri, new Properties()); @@ -1859,11 +1792,8 @@ public void testUseLegacySQLWithLargeResultsAllowedWithNoDestinationTableDefault public void testDestinationTableWithMissingDestinationDatasetDefaults() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=BIG_QUERY;" + ITBigQueryJDBCTest.connection_uri + + "QueryDialect=BIG_QUERY;" + "AllowLargeResults=1;" + "LargeResultTable=FakeTable;"; String selectLegacyQuery = @@ -1892,11 +1822,8 @@ public void testNonSelectForLegacyDestinationTableThrows() throws SQLException { "CREATE OR REPLACE TABLE %s.%s (`id` INTEGER, `name` STRING, `age` INTEGER);", DATASET, TRANSACTION_TABLE); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=BIG_QUERY;" + ITBigQueryJDBCTest.connection_uri + + "QueryDialect=BIG_QUERY;" + "AllowLargeResults=1;" + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;"; @@ -1918,11 +1845,8 @@ public void testNonSelectForStandardDestinationTableDoesNotThrow() throws SQLExc "CREATE OR REPLACE TABLE %s.%s (`id` INTEGER, `name` STRING, `age` INTEGER);", DATASET, TRANSACTION_TABLE); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=SQL;" + ITBigQueryJDBCTest.connection_uri + + "QueryDialect=SQL;" + "AllowLargeResults=1;" + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;"; @@ -2001,12 +1925,12 @@ public void testRangeDataTypeWithArrowResultSet() throws SQLException { "select * from `DATATYPERANGETEST.RangeIntervalTestTable` order by intColumn limit 5000;"; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";MaxResults=500;HighThroughputActivationRatio=0;" + ITBigQueryJDBCTest.connection_uri + + "MaxResults=500;" + + "HighThroughputActivationRatio=0;" + "HighThroughputMinTableSize=100;" - + "EnableHighThroughputAPI=1;JobCreationMode=1;"; + + "EnableHighThroughputAPI=1;" + + "JobCreationMode=1;"; // Read data via JDBC Connection connection = DriverManager.getConnection(connection_uri); @@ -2052,11 +1976,8 @@ public void testAlterTable() throws SQLException { public void testQueryPropertyDataSetProjectIdQueriesToCorrectDataset() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryProperties=dataset_project_id=" + ITBigQueryJDBCTest.connection_uri + + "QueryProperties=dataset_project_id=" + PROJECT_ID + ";"; String insertQuery = @@ -2087,11 +2008,8 @@ public void testQueryPropertyDataSetProjectIdQueriesToCorrectDataset() throws SQ public void testQueryPropertyDataSetProjectIdQueriesToIncorrectDatasetThrows() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryProperties=dataset_project_id=bigquerytestdefault" + ITBigQueryJDBCTest.connection_uri + + "QueryProperties=dataset_project_id=bigquerytestdefault" + ";"; String insertQuery = String.format( @@ -2109,11 +2027,7 @@ public void testQueryPropertyDataSetProjectIdQueriesToIncorrectDatasetThrows() @Test public void testQueryPropertyTimeZoneQueries() throws SQLException { String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryProperties=time_zone=America/New_York;"; + ITBigQueryJDBCTest.connection_uri + "QueryProperties=time_zone=America/New_York;"; String query = "SELECT * FROM `bigquery-public-data.samples.shakespeare` LIMIT 180"; Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); @@ -2133,13 +2047,7 @@ public void testQueryPropertySessionIdSetsStatementSession() throws SQLException, InterruptedException { String sessionId = getSessionId(); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryProperties=session_id=" - + sessionId - + ";"; + ITBigQueryJDBCTest.connection_uri + "QueryProperties=session_id=" + sessionId + ";"; String selectQuery = "INSERT INTO `bigquery-devtools-drivers.JDBC_INTEGRATION_DATASET.No_KMS_Test_table` (id," + " name, age) VALUES (132, 'Batman', 531);"; @@ -2164,14 +2072,7 @@ public void testQueryPropertySessionIdSetsStatementSession() public void testEncryptedTableWithKmsQueries() throws SQLException { // setup String KMSKeyName = requireEnvVar("KMS_RESOURCE_PATH"); - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";KMSKeyName=" - + KMSKeyName - + ";"; + String connection_uri = ITBigQueryJDBCTest.connection_uri + "KMSKeyName=" + KMSKeyName + ";"; String selectQuery = "SELECT * FROM `JDBC_INTEGRATION_DATASET.KMS_Test_table`;"; Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); @@ -2190,14 +2091,7 @@ public void testEncryptedTableWithKmsQueries() throws SQLException { @Test public void testIncorrectKmsThrows() throws SQLException { String KMSKeyName = requireEnvVar("KMS_RESOURCE_PATH"); - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";KMSKeyName=" - + KMSKeyName - + ";"; + String connection_uri = ITBigQueryJDBCTest.connection_uri + "KMSKeyName=" + KMSKeyName + ";"; String selectQuery = "INSERT INTO `bigquery-devtools-drivers.JDBC_INTEGRATION_DATASET.No_KMS_Test_table` (id," + " name, age) VALUES (132, 'Batman', 531);"; @@ -2214,11 +2108,8 @@ public void testIncorrectKmsThrows() throws SQLException { public void testQueryPropertyServiceAccountFollowsIamPermission() throws SQLException { final String SERVICE_ACCOUNT_EMAIL = requireEnvVar("SA_EMAIL"); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryProperties=service_account=" + ITBigQueryJDBCTest.connection_uri + + "QueryProperties=service_account=" + SERVICE_ACCOUNT_EMAIL + ";"; Driver driver = BigQueryDriver.getRegisteredDriver(); @@ -2242,11 +2133,7 @@ public void testValidLegacySQLStatement() throws SQLException { + "FROM\n" + " [bigquery-public-data.github_repos.commits],\n" + " [bigquery-public-data.github_repos.sample_commits] LIMIT 10"; - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";QueryDialect=BIG_QUERY;"; + String connection_uri = ITBigQueryJDBCTest.connection_uri + "QueryDialect=BIG_QUERY;"; Connection connection = DriverManager.getConnection(connection_uri); Statement statement = connection.createStatement(); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java index cbd128a818f1..d70f0cb77a9b 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITCallableStatementTest.java @@ -48,10 +48,7 @@ public class ITCallableStatementTest extends ITBase { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); - static final String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; + static final String connection_uri = ITBase.connectionUrl; private static final Random random = new Random(); private static String DATASET; private static final String CALLABLE_STMT_PROC_NAME = "IT_CALLABLE_STMT_PROC_TEST"; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java index 6f3b5ca43926..0da773d7c965 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionPoolingTest.java @@ -43,8 +43,7 @@ public class ITConnectionPoolingTest extends ITBase { @Test public void testPooledConnectionDataSourceSuccess() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -62,9 +61,7 @@ public void testPooledConnectionDataSourceFailNoConnectionURl() { @Test public void testPooledConnectionDataSourceFailInvalidConnectionURl() { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;" - + "ListenerPoolSize=invalid"; + String connectionUrl = ITBase.connectionUrl + "ListenerPoolSize=invalid;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -73,8 +70,7 @@ public void testPooledConnectionDataSourceFailInvalidConnectionURl() { @Test public void testPooledConnectionAddConnectionListener() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -89,8 +85,7 @@ public void testPooledConnectionAddConnectionListener() throws SQLException { @Test public void testPooledConnectionRemoveConnectionListener() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -105,8 +100,7 @@ public void testPooledConnectionRemoveConnectionListener() throws SQLException { @Test public void testPooledConnectionConnectionClosed() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -129,8 +123,7 @@ public void testPooledConnectionConnectionClosed() throws SQLException { @Test public void testPooledConnectionClose() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -149,8 +142,7 @@ public void testPooledConnectionClose() throws SQLException { @Test public void testPooledConnectionConnectionError() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -178,8 +170,7 @@ public void testPooledConnectionConnectionError() throws SQLException { @Test public void testPooledConnectionListenerAddListener() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -194,8 +185,7 @@ public void testPooledConnectionListenerAddListener() throws SQLException { @Test public void testPooledConnectionListenerRemoveListener() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -213,8 +203,7 @@ public void testPooledConnectionListenerRemoveListener() throws SQLException { @Test public void testPooledConnectionListenerCloseConnection() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -236,8 +225,7 @@ public void testPooledConnectionListenerCloseConnection() throws SQLException { @Test public void testPooledConnectionListenerClosePooledConnection() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -254,8 +242,7 @@ public void testPooledConnectionListenerClosePooledConnection() throws SQLExcept @Test public void testPooledConnectionListenerConnectionError() throws SQLException { - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;OAuthType=3;ProjectId=testProject;ConnectionPoolSize=20;ListenerPoolSize=20;"; + String connectionUrl = ITBase.connectionUrl + "ConnectionPoolSize=20;" + "ListenerPoolSize=20;"; PooledConnectionDataSource pooledDataSource = new PooledConnectionDataSource(); pooledDataSource.setURL(connectionUrl); @@ -281,24 +268,15 @@ public void testPooledConnectionListenerConnectionError() throws SQLException { @Test public void testExecuteQueryWithConnectionPoolingEnabledDefaultPoolSize() throws SQLException { - String connectionURL = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";"; + String connectionURL = ITBase.connectionUrl; + assertConnectionPoolingResults(connectionURL, DEFAULT_CONN_POOL_SIZE); } @Test public void testExecuteQueryWithConnectionPoolingEnabledCustomPoolSize() throws SQLException { String connectionURL = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";" - + "ConnectionPoolSize=" - + CUSTOM_CONN_POOL_SIZE - + ";"; + ITBase.connectionUrl + "ConnectionPoolSize=" + CUSTOM_CONN_POOL_SIZE + ";"; assertConnectionPoolingResults(connectionURL, CUSTOM_CONN_POOL_SIZE); } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java index d1a5b06ed6fb..40fd50e27488 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java @@ -49,8 +49,7 @@ public class ITConnectionTest { static int randomNumber = random.nextInt(999); private static final String TABLE_NAME = "JDBC_CONNECTION_TEST_TABLE" + randomNumber; - private static String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=%s;OAuthType=3;Timeout=3600;"; + private static String connectionUrl = ITBase.connectionUrl; @BeforeAll public static void beforeClass() throws InterruptedException { diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java index 8df46d7d5802..ab05738a41a6 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITDatabaseMetadataTest.java @@ -49,10 +49,7 @@ public class ITDatabaseMetadataTest extends ITBase { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); - static final String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; + static final String connection_uri = ITBase.connectionUrl; private static final Random random = new Random(); private static final int randomNumber = random.nextInt(9999); private static String DATASET; @@ -65,8 +62,7 @@ public class ITDatabaseMetadataTest extends ITBase { Pattern.compile("^(\\d+)\\.(\\d+)(?:\\.\\d+)+\\s*.*"); private static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId(); private static final String TABLE_NAME = "JDBC_DBMETADATA_TEST_TABLE" + randomNumber; - private static String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=%s;OAuthType=3;Timeout=3600;"; + private static String connectionUrl = ITBase.connectionUrl; @BeforeAll public static void beforeClass() throws InterruptedException, SQLException { @@ -1107,11 +1103,7 @@ public void testAdditionalProjectsInMetadata() throws SQLException { String datasetInAdditionalProject = "baseball"; String urlWithAdditionalProjects = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=" - + PROJECT_ID - + ";OAuthType=3" - + ";AdditionalProjects=" - + additionalProjectsValue; + ITBase.connectionUrl + "AdditionalProjects=" + additionalProjectsValue; try (Connection conn = DriverManager.getConnection(urlWithAdditionalProjects)) { DatabaseMetaData dbMetaData = conn.getMetaData(); @@ -1172,10 +1164,8 @@ public void testFilterTablesOnDefaultDataset_getTables() throws SQLException { String table2InSpecificDataset = "external_table"; String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=" - + PROJECT_ID - + ";OAuthType=3" - + ";DefaultDataset=" + ITDatabaseMetadataTest.connectionUrl + + "DefaultDataset=" + defaultDatasetValue + ";FilterTablesOnDefaultDataset=1"; try (Connection conn = DriverManager.getConnection(connectionUrl)) { @@ -1243,10 +1233,8 @@ public void testFilterTablesOnDefaultDataset_getColumns() throws SQLException { String[] columnsInSpecificTable = {"id", "name", "created_at"}; String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=" - + PROJECT_ID - + ";OAuthType=3" - + ";DefaultDataset=" + ITDatabaseMetadataTest.connectionUrl + + "DefaultDataset=" + defaultDatasetValue + ";FilterTablesOnDefaultDataset=1"; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java index 161f5163b691..ff9dbf0e7060 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java @@ -81,15 +81,9 @@ public class ITNightlyBigQueryTest { private static final String CALLABLE_STMT_DML_TABLE_NAME = "IT_CALLABLE_STMT_PROC_DML_TABLE"; private static String DATASET; private static String DATASET2; - static final String session_enabled_connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;EnableSession=1"; + static final String session_enabled_connection_uri = ITBase.connectionUrl + "EnableSession=1;"; - static final String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3"; + static final String connection_uri = ITBase.connectionUrl; @BeforeAll public static void beforeClass() throws SQLException { @@ -343,11 +337,8 @@ public void testExecuteLargeUpdate() throws SQLException { public void testHTAPIWithValidDestinationTableSavesQueriesWithStandardSQL() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=SQL;" + ITNightlyBigQueryTest.connection_uri + + "QueryDialect=SQL;" + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;" + "EnableHighThroughputAPI=1;"; @@ -733,11 +724,8 @@ public void testFailedStatementInTheMiddleOfExecuteBatchStopsExecuting() throws public void testHTAPIWithValidDestinationTableSavesQueriesWithLegacy() throws SQLException { // setup String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryDialect=BIG_QUERY;" + ITNightlyBigQueryTest.connection_uri + + "QueryDialect=BIG_QUERY;" + "LargeResultTable=destination_table_test;" + "LargeResultDataset=INTEGRATION_TESTS;" + "EnableHighThroughputAPI=1;"; @@ -1121,10 +1109,8 @@ public void testValidAllDataTypesSerializationFromSelectQueryArrowDataset() thro String TABLE_NAME = "JDBC_INTEGRATION_ARROW_TEST_TABLE"; String selectQuery = "select * from " + DATASET + "." + TABLE_NAME + " LIMIT 5000;"; String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;ProjectId=" - + PROJECT_ID - + ";EnableHighThroughputAPI=1;" + ITNightlyBigQueryTest.connection_uri + + "EnableHighThroughputAPI=1;" + "HighThroughputActivationRatio=2;" + "HighThroughputMinTableSize=1000;"; @@ -1183,10 +1169,10 @@ public void testBulkInsertOperation() throws SQLException { String selectQuery = String.format("SELECT * FROM %s.%s", DATASET, TABLE_NAME); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;" - + "EnableWriteAPI=1;SWA_ActivationRowCount=5;SWA_AppendRowCount=500"; + ITNightlyBigQueryTest.connection_uri + + "EnableWriteAPI=1;" + + "SWA_ActivationRowCount=5;" + + "SWA_AppendRowCount=500"; try (Connection connection = DriverManager.getConnection(connection_uri)) { bigQueryStatement.execute(createQuery); @@ -1232,10 +1218,10 @@ public void testBulkInsertOperationStandard() throws SQLException { String selectQuery = String.format("SELECT * FROM %s.%s", DATASET, TABLE_NAME); String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;" - + "EnableWriteAPI=0;SWA_ActivationRowCount=50;SWA_AppendRowCount=500"; + ITNightlyBigQueryTest.connection_uri + + "EnableWriteAPI=0;" + + "SWA_ActivationRowCount=50;" + + "SWA_AppendRowCount=500"; try (Connection connection = DriverManager.getConnection(connection_uri)) { bigQueryStatement.execute(createQuery); @@ -1365,13 +1351,7 @@ public void testQueryPropertySessionIdIsUsedWithTransaction() // Run the transaction String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";QueryProperties=session_id=" - + sessionId - + ";"; + ITNightlyBigQueryTest.connection_uri + "QueryProperties=session_id=" + sessionId + ";"; Driver driver = BigQueryDriver.getRegisteredDriver(); Connection connection = driver.connect(connection_uri, new Properties()); Statement statement = connection.createStatement(); @@ -1613,12 +1593,7 @@ public void testIterateOrderArrowMultiThread() throws SQLException { @Test public void testNonEnabledUseLegacySQLThrowsSyntaxError() throws SQLException { // setup - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" - + "OAuthType=3;" - + "ProjectId=" - + PROJECT_ID - + ";"; + String connection_uri = ITNightlyBigQueryTest.connection_uri; String selectLegacyQuery = "SELECT * FROM [bigquery-public-data.deepmind_alphafold.metadata] LIMIT 20000000;"; Driver driver = BigQueryDriver.getRegisteredDriver(); @@ -1661,10 +1636,12 @@ public void testReadAPIPathLarge() throws SQLException { @Test public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { String connectionUri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;MaxResults=300;HighThroughputActivationRatio=2;" - + "HighThroughputMinTableSize=100;EnableHighThroughputAPI=1"; + ITNightlyBigQueryTest.connection_uri + + "MaxResults=300;" + + "HighThroughputActivationRatio=2;" + + "HighThroughputMinTableSize=100;" + + "EnableHighThroughputAPI=1"; + Connection connection = DriverManager.getConnection(connectionUri); Statement statement = connection.createStatement(); int expectedCnt = 1000; @@ -1679,10 +1656,11 @@ public void testReadAPIPathLargeWithThresholdParameters() throws SQLException { @Test public void testReadAPIPathLargeWithThresholdNotMet() throws SQLException { String connectionUri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + PROJECT_ID - + ";OAUTHTYPE=3;HighThroughputActivationRatio=4;" - + "HighThroughputMinTableSize=100;EnableHighThroughputAPI=1"; + ITNightlyBigQueryTest.connection_uri + + "HighThroughputActivationRatio=4;" + + "HighThroughputMinTableSize=100;" + + "EnableHighThroughputAPI=1"; + Connection connection = DriverManager.getConnection(connectionUri); Statement statement = connection.createStatement(); int expectedCnt = 5000; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITResultSetMetadataTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITResultSetMetadataTest.java index 917db7124243..65a3b888d4fd 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITResultSetMetadataTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITResultSetMetadataTest.java @@ -55,8 +55,7 @@ public static void afterClass() throws InterruptedException { @Test public void testResultSetMetadata() throws SQLException { String selectData = "SELECT * FROM " + DATASET + "." + TABLE_NAME + ";"; - Connection connection = - DriverManager.getConnection(String.format(ITBase.connectionUrl, DEFAULT_CATALOG)); + Connection connection = DriverManager.getConnection(ITBase.connectionUrl); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(selectData); metaData = resultSet.getMetaData(); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index bc3a995d837a..0e097a6095fa 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -43,8 +43,7 @@ public class ITStatementTest { private static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId(); private static String DATASET; - private static String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=%s;OAuthType=3;Timeout=3600;"; + private static String connectionUrl = ITBase.connectionUrl; private static Random random = new Random(); private static int randomNumber = random.nextInt(999); private static final String TABLE_NAME = "JDBC_STATEMENT_TEST_TABLE" + randomNumber; @@ -222,10 +221,7 @@ public void testExecuteUpdate() throws SQLException { @Test public void testScript() throws SQLException { - String connection_uri = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;PROJECTID=" - + DEFAULT_CATALOG - + ";OAUTHTYPE=3"; + String connection_uri = ITStatementTest.connectionUrl; Properties withReadApi = new Properties(); withReadApi.setProperty("EnableHighThroughputAPI", "1"); Connection connection = DriverManager.getConnection(connection_uri, withReadApi); @@ -254,19 +250,9 @@ private int resultSetRowCount(ResultSet resultSet) throws SQLException { @Test public void testStringColumnLength() throws SQLException { - String projectId = DEFAULT_CATALOG; String TABLE_NAME = "StringColumnLengthTable"; - String oauthType = "3"; // Google Application Credentials int length = 10; - String connectionUrl = - "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=" - + projectId - + ";OAuthType=" - + oauthType - + ";Timeout=3600;" - + "StringColumnLength=" - + length - + ";"; + String connectionUrl = ITStatementTest.connectionUrl + "StringColumnLength=" + length + ";"; // + "EnableSession=1"; Connection connection1 = DriverManager.getConnection(connectionUrl); Statement statement = connection1.createStatement(); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/utils/TestUtilities.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/utils/TestUtilities.java index 419cb9b0bcb1..e395c124a8f7 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/utils/TestUtilities.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/utils/TestUtilities.java @@ -140,4 +140,30 @@ public int getConnectionErrorCount() { return connectionErrorCount; } } + + private static String getEnvOrProperty(String envVar, String sysProp, String defaultValue) { + String value = System.getenv(envVar); + if (value == null || value.isEmpty()) { + value = System.getProperty(sysProp, defaultValue); + } + return value; + } + + public static String getBaseUrl() { + return getEnvOrProperty( + "BIGQUERY_BASE_URL", "bigquery.baseUrl", "https://www.googleapis.com/bigquery/v2:443"); + } + + public static String getUrlFlags() { + return getEnvOrProperty("BIGQUERY_URL_FLAGS", "bigquery.urlFlags", ""); + } + + public static String getBaseConnectionUrl() { + String baseUrl = getBaseUrl(); + String flags = getUrlFlags(); + if (!flags.isEmpty() && !flags.endsWith(";")) { + flags += ";"; + } + return "jdbc:bigquery://" + baseUrl + ";" + flags; + } }