Skip to content

Commit 73c4aa2

Browse files
authored
chore(bigquery-jdbc): fix standalone it build (#13848)
1 parent 66ba925 commit 73c4aa2

3 files changed

Lines changed: 50 additions & 22 deletions

File tree

java-bigquery-jdbc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ package:
7070
cp target/google-cloud-bigquery-jdbc-*-all.jar $(PACKAGE_DESTINATION)/
7171

7272
build-it-standalone:
73-
mvn -Dmaven.test.skip=true package -f pom-it.xml
73+
mvn -Dmaven.test.skip=true package -f pom-it.xml -Dbigquery-jdbc.version=$(JDBC_DRIVER_VERSION)
7474

7575
run-it-standalone:
7676
java -cp $(JDBC_JAR):target-it/* org.junit.platform.console.ConsoleLauncher --select-class com.google.cloud.bigquery.jdbc.it.suites.ITDriverAgnosticTests

java-bigquery-jdbc/pom-it.xml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<maven.compiler.source>8</maven.compiler.source>
1616
<maven.compiler.target>8</maven.compiler.target>
17+
<bigquery-jdbc.version>1.2.0-SNAPSHOT</bigquery-jdbc.version><!-- {x-version-update:google-cloud-bigquery-jdbc:current} -->
1718
</properties>
1819

1920
<dependencies>
2021
<!-- Include the test classes from the main project -->
2122
<dependency>
2223
<groupId>com.google.cloud</groupId>
2324
<artifactId>google-cloud-bigquery-jdbc</artifactId>
24-
<version>1.0.0</version><!-- {x-version-update:google-cloud-bigquery-jdbc:current} -->
25+
<version>${bigquery-jdbc.version}</version>
2526
<type>test-jar</type>
2627
<scope>compile</scope>
2728
</dependency>
@@ -88,6 +89,20 @@
8889
<build>
8990
<directory>target-it</directory>
9091
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<executions>
96+
<execution>
97+
<id>default-compile</id>
98+
<phase>none</phase>
99+
</execution>
100+
<execution>
101+
<id>default-testCompile</id>
102+
<phase>none</phase>
103+
</execution>
104+
</executions>
105+
</plugin>
91106
<plugin>
92107
<groupId>org.apache.maven.plugins</groupId>
93108
<artifactId>maven-shade-plugin</artifactId>
@@ -99,21 +114,26 @@
99114
<goal>shade</goal>
100115
</goals>
101116
<configuration>
102-
<!--
103-
We exclude the main bigquery-jdbc framework classes.
104-
This jar should ONLY contain tests and their dependencies (Junit, Mockito, Truth),
105-
plus the test classes themselves. When running, the ACTUAL JDBC driver jar
106-
will be placed on the classpath.
107-
-->
108117
<createDependencyReducedPom>false</createDependencyReducedPom>
109-
<artifactSet>
110-
<excludes>
111-
<exclude>com.google.cloud:google-cloud-bigquery</exclude>
112-
<exclude>com.google.cloud:google-cloud-bigquerystorage</exclude>
113-
<exclude>io.grpc:*</exclude>
114-
<exclude>com.google.protobuf:*</exclude>
115-
</excludes>
116-
</artifactSet>
118+
<!-- Shading everything except junit & integration tests to avoid version conflicts -->
119+
<relocations>
120+
<relocation>
121+
<pattern>com.</pattern>
122+
<shadedPattern>com.google.bqjdbc.shaded.com.</shadedPattern>
123+
<excludes>com.google.cloud.bigquery.jdbc.it.**</excludes>
124+
</relocation>
125+
<relocation>
126+
<pattern>org.</pattern>
127+
<shadedPattern>com.google.bqjdbc.shaded.org.</shadedPattern>
128+
<excludes>
129+
<exclude>org.junit.**</exclude>
130+
</excludes>
131+
</relocation>
132+
<relocation>
133+
<pattern>io.</pattern>
134+
<shadedPattern>com.google.bqjdbc.shaded.io.</shadedPattern>
135+
</relocation>
136+
</relocations>
117137
<filters>
118138
<filter>
119139
<artifact>*:*</artifact>

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcBaseTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package com.google.cloud.bigquery.jdbc;
1818

1919
import com.google.cloud.bigquery.BigQuery;
20+
import com.google.cloud.bigquery.BigQueryOptions;
2021
import com.google.cloud.bigquery.jdbc.utils.TestUtilities;
2122
import com.google.cloud.bigquery.jdbc.utils.URIBuilder;
23+
import java.lang.reflect.Method;
24+
import java.sql.Connection;
2225
import java.sql.DriverManager;
23-
import java.sql.SQLException;
2426

2527
public class BigQueryJdbcBaseTest {
2628

@@ -48,12 +50,18 @@ public class BigQueryJdbcBaseTest {
4850

4951
protected static BigQuery getBigQuery(String connectionUrl) {
5052
try {
51-
return DriverManager.getConnection(connectionUrl)
52-
.unwrap(BigQueryConnection.class)
53-
.getBigQuery();
54-
} catch (SQLException e) {
55-
throw new RuntimeException("Failed to initialize BigQuery client", e);
53+
Class<?> bqConnClass = Class.forName("com.google.cloud.bigquery.jdbc.BigQueryConnection");
54+
Connection conn = DriverManager.getConnection(connectionUrl);
55+
Object unwrapped = conn.unwrap(bqConnClass);
56+
if (unwrapped != null) {
57+
Method method = bqConnClass.getDeclaredMethod("getBigQuery");
58+
method.setAccessible(true);
59+
return (BigQuery) method.invoke(unwrapped);
60+
}
61+
} catch (Throwable e) {
62+
// ignore for some set of tests; Proxy/TPC tests will fail if it doesn't work.
5663
}
64+
return BigQueryOptions.getDefaultInstance().getService();
5765
}
5866

5967
protected static URIBuilder getBaseUri() {

0 commit comments

Comments
 (0)