From 6126d4f55dde76c8b945999008bbee78203a1b75 Mon Sep 17 00:00:00 2001
From: Mridula <66699525+mpeddada1@users.noreply.github.com>
Date: Tue, 31 May 2022 17:18:22 -0400
Subject: [PATCH] fix(java): adding resource and reflection configurations for
native image testing (#809)
* fix(java): adding resource and reflection configurations for native image testing (#809)
---
.kokoro/build.sh | 4 ++--
owlbot.py | 3 ++-
pom.xml | 14 ++++++++++++++
.../native-image.properties | 3 +++
.../google-cloud-spanner-jdbc/resource-config.json | 9 +++++++++
.../jdbc/it/ITJdbcPreparedStatementTest.java | 11 +++++------
6 files changed, 35 insertions(+), 9 deletions(-)
create mode 100644 src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties
create mode 100644 src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/resource-config.json
diff --git a/.kokoro/build.sh b/.kokoro/build.sh
index 5ca4fd4bc..8318273ed 100755
--- a/.kokoro/build.sh
+++ b/.kokoro/build.sh
@@ -71,12 +71,12 @@ integration)
;;
graalvm)
# Run Unit and Integration Tests with Native Image
- mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test
+ mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test "-Dtest=com.google.cloud.spanner.jdbc.it.**"
RETURN_CODE=$?
;;
graalvm17)
# Run Unit and Integration Tests with Native Image
- mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test
+ mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test "-Dtest=com.google.cloud.spanner.jdbc.it.**"
RETURN_CODE=$?
;;
samples)
diff --git a/owlbot.py b/owlbot.py
index 5beca6a87..05f32bb6d 100644
--- a/owlbot.py
+++ b/owlbot.py
@@ -21,5 +21,6 @@
'.github/release-please.yml',
'.github/sync-repo-settings.yaml',
'.github/blunderbuss.yml',
- '.kokoro/nightly/integration.cfg'
+ '.kokoro/nightly/integration.cfg',
+ '.kokoro/build.sh'
])
diff --git a/pom.xml b/pom.xml
index 5bf345fb7..d2860960b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -230,6 +230,14 @@
com.google.cloud.spanner.jdbc.JdbcStatementTimeoutTest
sponge_log
+
+
+ com.google.cloud.spanner.GceTestEnvConfig
+
+
+ projects/gcloud-devel/instances/spanner-testing-east1
+
+
@@ -319,6 +327,12 @@
org.apache.maven.plugins
maven-dependency-plugin
+
+ org.graalvm.sdk:graal-sdk
+ com.google.api.grpc:grpc-google-cloud-spanner-v1
+ com.google.api.grpc:proto-google-cloud-spanner-admin-instance-v1
+ com.google.api.grpc:proto-google-cloud-spanner-admin-database-v1
+
io.grpc:grpc-alts
diff --git a/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties b/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties
new file mode 100644
index 000000000..f211d3a26
--- /dev/null
+++ b/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties
@@ -0,0 +1,3 @@
+Args = --initialize-at-build-time==com.google.cloud.spanner.IntegrationTestEnv,\
+ com.google.cloud.spanner.jdbc.it.JdbcIntegrationTestEnv,\
+ com.google.common.collect.RegularImmutableMap
\ No newline at end of file
diff --git a/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/resource-config.json b/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/resource-config.json
new file mode 100644
index 000000000..2a215e443
--- /dev/null
+++ b/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/resource-config.json
@@ -0,0 +1,9 @@
+{
+ "resources":{
+ "includes":[
+ {"pattern":".*.sql"},
+ {"pattern":".*.json"},
+ {"pattern":".*.txt"}
+ ]
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java b/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java
index 49491332f..c473b6e96 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java
@@ -35,8 +35,8 @@
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
import com.google.common.base.Strings;
import com.google.common.io.BaseEncoding;
-import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.StringReader;
import java.math.BigDecimal;
import java.sql.BatchUpdateException;
@@ -54,7 +54,6 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
-import java.util.Objects;
import java.util.Scanner;
import java.util.TimeZone;
import java.util.UUID;
@@ -1106,14 +1105,14 @@ private void assertDefaultParameterMetaData(ParameterMetaData pmd, int expectedP
}
private List readValuesFromFile(String filename) {
- File file = new File(Objects.requireNonNull(getClass().getResource(filename)).getFile());
StringBuilder builder = new StringBuilder();
- try (Scanner scanner = new Scanner(file)) {
+ try (InputStream stream = ITJdbcPreparedStatementTest.class.getResourceAsStream(filename)) {
+ Scanner scanner = new Scanner(stream);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
builder.append(line).append("\n");
}
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
throw new RuntimeException(e);
}
String[] array = builder.toString().split(";");