From c94f5f3fa2c90ca3becc6315ebf52bcaaa8c2f1b Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 27 Apr 2022 16:50:19 -0400 Subject: [PATCH 01/18] fix: branch to test all native image configuration changes on CI --- .kokoro/build.sh | 5 + google-cloud-spanner/pom.xml | 37 +++--- .../spanner/nativeimage/SpannerFeature.java | 121 ++++++++++++++++++ ...lientTest.java => SessionClientTests.java} | 2 +- ...DdlClientTest.java => DdlClientTests.java} | 2 +- .../spanner/connection/SqlScriptVerifier.java | 25 ++-- 6 files changed, 161 insertions(+), 31 deletions(-) create mode 100644 google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java rename google-cloud-spanner/src/test/java/com/google/cloud/spanner/{SessionClientTest.java => SessionClientTests.java} (99%) rename google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/{DdlClientTest.java => DdlClientTests.java} (98%) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 56aa8c8f5c2..0bb2b93a739 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -73,6 +73,11 @@ integration) verify RETURN_CODE=$? ;; +graalvm) + # Run Unit and Integration Tests with Native Image + mvn test -Pnative -Penable-integration-tests + RETURN_CODE=$? + ;; slowtests) mvn -B ${INTEGRATION_TEST_ARGS} \ -ntp \ diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 96510c7f504..121e38de78b 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -16,6 +16,7 @@ google-cloud-spanner 0.31.0 + 22.0.0.2 com.google.cloud.spanner.GceTestEnvConfig projects/gcloud-devel/instances/spanner-testing-east1 gcloud-devel @@ -56,6 +57,16 @@ default-test com.google.cloud.spanner.TracerTest,com.google.cloud.spanner.IntegrationTest + + + + ${spanner.testenv.config.class} + ${spanner.testenv.instance} + ${spanner.gce.config.project_id} + ${spanner.testenv.kms_key.name} + + @@ -105,20 +116,6 @@ - - - org.apache.maven.plugins - maven-surefire-plugin - - - ${spanner.testenv.config.class} - ${spanner.testenv.instance} - ${spanner.gce.config.project_id} - ${spanner.testenv.kms_key.name} - - 3000 - - org.graalvm.buildtools native-maven-plugin @@ -142,7 +139,7 @@ org.apache.maven.plugins maven-dependency-plugin - io.grpc:grpc-protobuf-lite,org.hamcrest:hamcrest,org.hamcrest:hamcrest-core,com.google.errorprone:error_prone_annotations,org.openjdk.jmh:jmh-generator-annprocess,com.google.api.grpc:grpc-google-cloud-spanner-v1,com.google.api.grpc:grpc-google-cloud-spanner-admin-instance-v1,com.google.api.grpc:grpc-google-cloud-spanner-admin-database-v1,javax.annotation:javax.annotation-api,io.opencensus:opencensus-impl + io.grpc:grpc-protobuf-lite,org.hamcrest:hamcrest,org.hamcrest:hamcrest-core,com.google.errorprone:error_prone_annotations,org.openjdk.jmh:jmh-generator-annprocess,com.google.api.grpc:grpc-google-cloud-spanner-v1,com.google.api.grpc:grpc-google-cloud-spanner-admin-instance-v1,com.google.api.grpc:grpc-google-cloud-spanner-admin-database-v1,javax.annotation:javax.annotation-api,io.opencensus:opencensus-impl,org.graalvm.sdk:graal-sdk @@ -352,6 +349,16 @@ 1.34 test + + + + org.graalvm.nativeimage + svm + ${graalvm.version} + provided + + + diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java new file mode 100644 index 00000000000..a2dec135bfa --- /dev/null +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -0,0 +1,121 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.spanner.nativeimage; + +import com.google.api.gax.nativeimage.NativeImageUtils; +import com.oracle.svm.core.annotate.AutomaticFeature; +import com.oracle.svm.core.configure.ResourcesRegistry; +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.impl.ConfigurationCondition; + +/** Registers Spanner library classes for reflection. */ +@AutomaticFeature +final class SpannerFeature implements Feature { + + private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; + private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig"; + private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl"; + private static final String CLIENT_SIDE_IMPL_CLASS = + "com.google.cloud.spanner.connection.ClientSideStatementImpl"; + private static final String CLIENT_SIDE_VALUE_CONVERTER = + "com.google.cloud.spanner.connection.ClientSideStatementValueConverters"; + private static final String CONNECTION_IMPL = + "com.google.cloud.spanner.connection.ConnectionImpl"; + private static final String CLIENT_SIDE_STATEMENTS = + "com.google.cloud.spanner.connection.ClientSideStatements"; + private static final String CONNECTION_STATEMENT_EXECUTOR = + "com.google.cloud.spanner.connection.ConnectionStatementExecutor"; + private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; + private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; + private static final String ABSTRACT_STATEMENT_PARSER = + "com.google.cloud.spanner.connection.AbstractStatementParser"; + private static final String STATEMENT_PARSER = + "com.google.cloud.spanner.connection.SpannerStatementParser"; + private static final String DIALECT = "com.google.cloud.spanner.Dialect"; + + @Override + public void beforeAnalysis(BeforeAnalysisAccess access) { + registerSpannerTestClasses(access); + if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS); + } + if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR); + } + if (access.findClassByName(CONNECTION_IMPL) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL); + } + if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER); + NativeImageUtils.registerClassForReflection(access, "com.google.cloud.spanner.Dialect"); + } + if (access.findClassByName(STATEMENT_PARSER) != null) { + NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); + } + + Class spannerClass = access.findClassByName(SPANNER_CLASS); + if (spannerClass != null) { + NativeImageUtils.registerClassHierarchyForReflection( + access, "com.google.spanner.admin.database.v1.Database"); + NativeImageUtils.registerClassHierarchyForReflection( + access, "com.google.spanner.admin.instance.v1.Instance"); + NativeImageUtils.registerClassForReflection( + access, "com.google.spanner.admin.database.v1.RestoreInfo"); + + // Resources + ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"); + resourcesRegistry.addResources( + "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); + } + } + + private void registerSpannerTestClasses(BeforeAnalysisAccess access) { + Class spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS); + if (spannerTestClass != null) { + NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS); + } + Class mockClass = access.findClassByName(MOCK_CLASS); + if (mockClass != null) { + NativeImageUtils.registerClassForReflection( + access, "com.google.cloud.spanner.MockDatabaseAdminServiceImpl$MockBackup"); + } + } +} diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionClientTests.java similarity index 99% rename from google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionClientTest.java rename to google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionClientTests.java index 7c2710156c7..6d1f88b26fb 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionClientTests.java @@ -54,7 +54,7 @@ import org.mockito.MockitoAnnotations; @RunWith(Parameterized.class) -public class SessionClientTest { +public class SessionClientTests { private final class TestExecutorFactory implements ExecutorFactory { @Override public ScheduledExecutorService get() { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DdlClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DdlClientTests.java similarity index 98% rename from google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DdlClientTest.java rename to google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DdlClientTests.java index 24b4ebf0964..9d84c6e0a1f 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DdlClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/DdlClientTests.java @@ -35,7 +35,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class DdlClientTest { +public class DdlClientTests { private final String instanceId = "test-instance"; private final String databaseId = "test-database"; diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java index d9de876ceda..109186438a6 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java @@ -16,10 +16,8 @@ package com.google.cloud.spanner.connection; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import com.google.cloud.spanner.Dialect; import com.google.cloud.spanner.ErrorCode; @@ -175,17 +173,16 @@ public SqlScriptVerifier(GenericConnectionProvider provider) { @Override protected void verifyExpectedException( String statement, Exception e, String code, String messagePrefix) { - assertThat(e instanceof SpannerException, is(true)); + assertTrue(e instanceof SpannerException); SpannerException spannerException = (SpannerException) e; - assertThat( - statement + " resulted in " + spannerException.toString(), - spannerException.getErrorCode(), - is(equalTo(ErrorCode.valueOf(code)))); - if (messagePrefix != null) { - assertThat( - statement, - e.getMessage(), - startsWith(messagePrefix.substring(1, messagePrefix.length() - 1))); + assertEquals( + statement + " resulted in " + spannerException, + ErrorCode.valueOf(code), + spannerException.getErrorCode()); + if (messagePrefix!=null) { + assertTrue( + statement, + e.getMessage().startsWith(messagePrefix.substring(1, messagePrefix.length() - 1))); } } } From 87b0cea72c1eae8803590b2fa2b7e8a3f6e0e3ee Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 27 Apr 2022 20:54:04 +0000 Subject: [PATCH 02/18] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../spanner/nativeimage/SpannerFeature.java | 170 +++++++++--------- .../spanner/connection/SqlScriptVerifier.java | 12 +- 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java index a2dec135bfa..08eb4651a2b 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -27,95 +27,95 @@ @AutomaticFeature final class SpannerFeature implements Feature { - private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; - private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig"; - private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl"; - private static final String CLIENT_SIDE_IMPL_CLASS = - "com.google.cloud.spanner.connection.ClientSideStatementImpl"; - private static final String CLIENT_SIDE_VALUE_CONVERTER = - "com.google.cloud.spanner.connection.ClientSideStatementValueConverters"; - private static final String CONNECTION_IMPL = - "com.google.cloud.spanner.connection.ConnectionImpl"; - private static final String CLIENT_SIDE_STATEMENTS = - "com.google.cloud.spanner.connection.ClientSideStatements"; - private static final String CONNECTION_STATEMENT_EXECUTOR = - "com.google.cloud.spanner.connection.ConnectionStatementExecutor"; - private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR = - "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; - private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = - "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; - private static final String ABSTRACT_STATEMENT_PARSER = - "com.google.cloud.spanner.connection.AbstractStatementParser"; - private static final String STATEMENT_PARSER = - "com.google.cloud.spanner.connection.SpannerStatementParser"; - private static final String DIALECT = "com.google.cloud.spanner.Dialect"; + private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; + private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig"; + private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl"; + private static final String CLIENT_SIDE_IMPL_CLASS = + "com.google.cloud.spanner.connection.ClientSideStatementImpl"; + private static final String CLIENT_SIDE_VALUE_CONVERTER = + "com.google.cloud.spanner.connection.ClientSideStatementValueConverters"; + private static final String CONNECTION_IMPL = + "com.google.cloud.spanner.connection.ConnectionImpl"; + private static final String CLIENT_SIDE_STATEMENTS = + "com.google.cloud.spanner.connection.ClientSideStatements"; + private static final String CONNECTION_STATEMENT_EXECUTOR = + "com.google.cloud.spanner.connection.ConnectionStatementExecutor"; + private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; + private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; + private static final String ABSTRACT_STATEMENT_PARSER = + "com.google.cloud.spanner.connection.AbstractStatementParser"; + private static final String STATEMENT_PARSER = + "com.google.cloud.spanner.connection.SpannerStatementParser"; + private static final String DIALECT = "com.google.cloud.spanner.Dialect"; - @Override - public void beforeAnalysis(BeforeAnalysisAccess access) { - registerSpannerTestClasses(access); - if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) { - NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS); - } - if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { - NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); - } - if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { - NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); - } - if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) { - NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER); - } - if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) { - NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS); - } - if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) { - NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR); - } - if (access.findClassByName(CONNECTION_IMPL) != null) { - NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL); - } - if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) { - NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER); - NativeImageUtils.registerClassForReflection(access, "com.google.cloud.spanner.Dialect"); - } - if (access.findClassByName(STATEMENT_PARSER) != null) { - NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); - } + @Override + public void beforeAnalysis(BeforeAnalysisAccess access) { + registerSpannerTestClasses(access); + if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS); + } + if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR); + } + if (access.findClassByName(CONNECTION_IMPL) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL); + } + if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER); + NativeImageUtils.registerClassForReflection(access, "com.google.cloud.spanner.Dialect"); + } + if (access.findClassByName(STATEMENT_PARSER) != null) { + NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); + } - Class spannerClass = access.findClassByName(SPANNER_CLASS); - if (spannerClass != null) { - NativeImageUtils.registerClassHierarchyForReflection( - access, "com.google.spanner.admin.database.v1.Database"); - NativeImageUtils.registerClassHierarchyForReflection( - access, "com.google.spanner.admin.instance.v1.Instance"); - NativeImageUtils.registerClassForReflection( - access, "com.google.spanner.admin.database.v1.RestoreInfo"); + Class spannerClass = access.findClassByName(SPANNER_CLASS); + if (spannerClass != null) { + NativeImageUtils.registerClassHierarchyForReflection( + access, "com.google.spanner.admin.database.v1.Database"); + NativeImageUtils.registerClassHierarchyForReflection( + access, "com.google.spanner.admin.instance.v1.Instance"); + NativeImageUtils.registerClassForReflection( + access, "com.google.spanner.admin.database.v1.RestoreInfo"); - // Resources - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"); - resourcesRegistry.addResources( - "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); - } + // Resources + ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"); + resourcesRegistry.addResources( + "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); } + } - private void registerSpannerTestClasses(BeforeAnalysisAccess access) { - Class spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS); - if (spannerTestClass != null) { - NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS); - } - Class mockClass = access.findClassByName(MOCK_CLASS); - if (mockClass != null) { - NativeImageUtils.registerClassForReflection( - access, "com.google.cloud.spanner.MockDatabaseAdminServiceImpl$MockBackup"); - } + private void registerSpannerTestClasses(BeforeAnalysisAccess access) { + Class spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS); + if (spannerTestClass != null) { + NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS); + } + Class mockClass = access.findClassByName(MOCK_CLASS); + if (mockClass != null) { + NativeImageUtils.registerClassForReflection( + access, "com.google.cloud.spanner.MockDatabaseAdminServiceImpl$MockBackup"); } + } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java index 109186438a6..15b031705e3 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java @@ -176,13 +176,13 @@ protected void verifyExpectedException( assertTrue(e instanceof SpannerException); SpannerException spannerException = (SpannerException) e; assertEquals( - statement + " resulted in " + spannerException, - ErrorCode.valueOf(code), - spannerException.getErrorCode()); - if (messagePrefix!=null) { + statement + " resulted in " + spannerException, + ErrorCode.valueOf(code), + spannerException.getErrorCode()); + if (messagePrefix != null) { assertTrue( - statement, - e.getMessage().startsWith(messagePrefix.substring(1, messagePrefix.length() - 1))); + statement, + e.getMessage().startsWith(messagePrefix.substring(1, messagePrefix.length() - 1))); } } } From 27924bcb1f47717e6110e56e02327051317427a4 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Thu, 28 Apr 2022 13:43:09 -0400 Subject: [PATCH 03/18] include StatementResult and PostgreSqlStatementParser --- .../cloud/spanner/nativeimage/SpannerFeature.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java index a2dec135bfa..73938e40997 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -48,7 +48,10 @@ final class SpannerFeature implements Feature { "com.google.cloud.spanner.connection.AbstractStatementParser"; private static final String STATEMENT_PARSER = "com.google.cloud.spanner.connection.SpannerStatementParser"; - private static final String DIALECT = "com.google.cloud.spanner.Dialect"; + private static final String POSTGRESQL_STATEMENT_PARSER = + "com.google.cloud.spanner.connection.PostgreSQLStatementParser"; + private static final String STATEMENT_RESULT = + "com.google.cloud.spanner.connection.StatementResult$ResultType"; @Override public void beforeAnalysis(BeforeAnalysisAccess access) { @@ -81,6 +84,12 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { if (access.findClassByName(STATEMENT_PARSER) != null) { NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); } + if (access.findClassByName(POSTGRESQL_STATEMENT_PARSER) != null) { + NativeImageUtils.registerConstructorsForReflection(access, POSTGRESQL_STATEMENT_PARSER); + } + if (access.findClassByName(STATEMENT_RESULT) != null) { + NativeImageUtils.registerClassForReflection(access, STATEMENT_RESULT); + } Class spannerClass = access.findClassByName(SPANNER_CLASS); if (spannerClass != null) { From 0088e43557838fc2308d01042d1825e3f33f0684 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 28 Apr 2022 17:47:56 +0000 Subject: [PATCH 04/18] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../spanner/nativeimage/SpannerFeature.java | 168 +++++++++--------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java index 331369d0c05..f278c31988a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -27,94 +27,94 @@ @AutomaticFeature final class SpannerFeature implements Feature { - private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; - private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig"; - private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl"; - private static final String CLIENT_SIDE_IMPL_CLASS = - "com.google.cloud.spanner.connection.ClientSideStatementImpl"; - private static final String CLIENT_SIDE_VALUE_CONVERTER = - "com.google.cloud.spanner.connection.ClientSideStatementValueConverters"; - private static final String CONNECTION_IMPL = - "com.google.cloud.spanner.connection.ConnectionImpl"; - private static final String CLIENT_SIDE_STATEMENTS = - "com.google.cloud.spanner.connection.ClientSideStatements"; - private static final String CONNECTION_STATEMENT_EXECUTOR = - "com.google.cloud.spanner.connection.ConnectionStatementExecutor"; - private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR = - "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; - private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = - "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; - private static final String ABSTRACT_STATEMENT_PARSER = - "com.google.cloud.spanner.connection.AbstractStatementParser"; - private static final String STATEMENT_PARSER = - "com.google.cloud.spanner.connection.SpannerStatementParser"; - private static final String POSTGRESQL_STATEMENT_PARSER = - "com.google.cloud.spanner.connection.PostgreSQLStatementParser"; - private static final String STATEMENT_RESULT = - "com.google.cloud.spanner.connection.StatementResult$ResultType"; + private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; + private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig"; + private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl"; + private static final String CLIENT_SIDE_IMPL_CLASS = + "com.google.cloud.spanner.connection.ClientSideStatementImpl"; + private static final String CLIENT_SIDE_VALUE_CONVERTER = + "com.google.cloud.spanner.connection.ClientSideStatementValueConverters"; + private static final String CONNECTION_IMPL = + "com.google.cloud.spanner.connection.ConnectionImpl"; + private static final String CLIENT_SIDE_STATEMENTS = + "com.google.cloud.spanner.connection.ClientSideStatements"; + private static final String CONNECTION_STATEMENT_EXECUTOR = + "com.google.cloud.spanner.connection.ConnectionStatementExecutor"; + private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; + private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; + private static final String ABSTRACT_STATEMENT_PARSER = + "com.google.cloud.spanner.connection.AbstractStatementParser"; + private static final String STATEMENT_PARSER = + "com.google.cloud.spanner.connection.SpannerStatementParser"; + private static final String POSTGRESQL_STATEMENT_PARSER = + "com.google.cloud.spanner.connection.PostgreSQLStatementParser"; + private static final String STATEMENT_RESULT = + "com.google.cloud.spanner.connection.StatementResult$ResultType"; - @Override - public void beforeAnalysis(BeforeAnalysisAccess access) { - registerSpannerTestClasses(access); - if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) { - NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS); - } - if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { - NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); - } - if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { - NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); - } - if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) { - NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER); - } - if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) { - NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS); - } - if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) { - NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR); - } - if (access.findClassByName(CONNECTION_IMPL) != null) { - NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL); - } - if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) { - NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER); - NativeImageUtils.registerClassForReflection(access, "com.google.cloud.spanner.Dialect"); - } - if (access.findClassByName(STATEMENT_PARSER) != null) { - NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); - } - if (access.findClassByName(POSTGRESQL_STATEMENT_PARSER) != null) { - NativeImageUtils.registerConstructorsForReflection(access, POSTGRESQL_STATEMENT_PARSER); - } - if (access.findClassByName(STATEMENT_RESULT) != null) { - NativeImageUtils.registerClassForReflection(access, STATEMENT_RESULT); - } + @Override + public void beforeAnalysis(BeforeAnalysisAccess access) { + registerSpannerTestClasses(access); + if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS); + } + if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR); + } + if (access.findClassByName(CONNECTION_IMPL) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL); + } + if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER); + NativeImageUtils.registerClassForReflection(access, "com.google.cloud.spanner.Dialect"); + } + if (access.findClassByName(STATEMENT_PARSER) != null) { + NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); + } + if (access.findClassByName(POSTGRESQL_STATEMENT_PARSER) != null) { + NativeImageUtils.registerConstructorsForReflection(access, POSTGRESQL_STATEMENT_PARSER); + } + if (access.findClassByName(STATEMENT_RESULT) != null) { + NativeImageUtils.registerClassForReflection(access, STATEMENT_RESULT); + } - Class spannerClass = access.findClassByName(SPANNER_CLASS); - if (spannerClass != null) { - NativeImageUtils.registerClassHierarchyForReflection( - access, "com.google.spanner.admin.database.v1.Database"); - NativeImageUtils.registerClassHierarchyForReflection( - access, "com.google.spanner.admin.instance.v1.Instance"); - NativeImageUtils.registerClassForReflection( - access, "com.google.spanner.admin.database.v1.RestoreInfo"); + Class spannerClass = access.findClassByName(SPANNER_CLASS); + if (spannerClass != null) { + NativeImageUtils.registerClassHierarchyForReflection( + access, "com.google.spanner.admin.database.v1.Database"); + NativeImageUtils.registerClassHierarchyForReflection( + access, "com.google.spanner.admin.instance.v1.Instance"); + NativeImageUtils.registerClassForReflection( + access, "com.google.spanner.admin.database.v1.RestoreInfo"); - // Resources - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"); - resourcesRegistry.addResources( - "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); - } + // Resources + ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"); + resourcesRegistry.addResources( + "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); } + } private void registerSpannerTestClasses(BeforeAnalysisAccess access) { Class spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS); From cc7d3c7f31757f997607460a1e1e91feb02b216c Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 11 May 2022 17:09:33 -0400 Subject: [PATCH 05/18] remove dependency on svm --- google-cloud-spanner/pom.xml | 9 --------- .../spanner/nativeimage/SpannerFeature.java | 19 ------------------- .../native-image/native-image.properties | 1 + .../native-image/resource-config.json | 8 ++++++++ 4 files changed, 9 insertions(+), 28 deletions(-) create mode 100644 google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties create mode 100644 google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/resource-config.json diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 121e38de78b..9ac1a5be031 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -350,15 +350,6 @@ test - - - org.graalvm.nativeimage - svm - ${graalvm.version} - provided - - - diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java index f278c31988a..29c6e8b8745 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -17,14 +17,9 @@ package com.google.cloud.spanner.nativeimage; import com.google.api.gax.nativeimage.NativeImageUtils; -import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.configure.ResourcesRegistry; -import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.ConfigurationCondition; /** Registers Spanner library classes for reflection. */ -@AutomaticFeature final class SpannerFeature implements Feature { private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; @@ -99,20 +94,6 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { access, "com.google.spanner.admin.instance.v1.Instance"); NativeImageUtils.registerClassForReflection( access, "com.google.spanner.admin.database.v1.RestoreInfo"); - - // Resources - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"); - resourcesRegistry.addResources( - "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); - resourcesRegistry.addResources( - ConfigurationCondition.alwaysTrue(), - "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); } } diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties new file mode 100644 index 00000000000..31e01f1cbc5 --- /dev/null +++ b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties @@ -0,0 +1 @@ +Args = --features=com.google.cloud.spanner.nativeimage.SpannerFeature \ No newline at end of file diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/resource-config.json b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/resource-config.json new file mode 100644 index 00000000000..91d913b239b --- /dev/null +++ b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/resource-config.json @@ -0,0 +1,8 @@ +{ + "resources": [ + {"pattern": "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"}, + {"pattern": "\\Qcom/google/cloud/spanner/connection/PG_ClientSideStatements.json\\E"}, + {"pattern": "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"}, + {"pattern": "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"} + ] +} \ No newline at end of file From 4e30216191793770ff6260ecd308d6e5a6dc5b53 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 11 May 2022 17:20:23 -0400 Subject: [PATCH 06/18] add graal-sdk dependency --- google-cloud-spanner/pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 389bc3c7ec2..78fbd459004 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -293,6 +293,13 @@ grpc-alts + + org.graalvm.sdk + graal-sdk + ${graalvm.version} + provided + + junit From 498703268419c75f095b1d39e7cb911aeb901bc6 Mon Sep 17 00:00:00 2001 From: Mridula <66699525+mpeddada1@users.noreply.github.com> Date: Wed, 11 May 2022 21:38:16 -0400 Subject: [PATCH 07/18] Update native-image.properties --- .../cloud/spanner/META-INF/native-image/native-image.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties index 31e01f1cbc5..a063d6e0d05 100644 --- a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties +++ b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties @@ -1 +1 @@ -Args = --features=com.google.cloud.spanner.nativeimage.SpannerFeature \ No newline at end of file +Args = --initialize-at-build-time=com.google.cloud.spanner.IntegrationTestEnv --features=com.google.cloud.spanner.nativeimage.SpannerFeature From 839e141b7806d2d039b376ae0b404969daa5a23b Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Thu, 12 May 2022 13:20:08 -0400 Subject: [PATCH 08/18] modify native-image.properties --- .../resources/META-INF/native-image/native-image.properties | 2 ++ .../resources}/META-INF/native-image/resource-config.json | 0 .../cloud/spanner/META-INF/native-image/native-image.properties | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties rename google-cloud-spanner/src/{test/resources/com/google/cloud/spanner => main/resources}/META-INF/native-image/resource-config.json (100%) delete mode 100644 google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties diff --git a/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties b/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties new file mode 100644 index 00000000000..d56f752abef --- /dev/null +++ b/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties @@ -0,0 +1,2 @@ +Args = --initialize-at-build-time=com.google.cloud.spanner.IntegrationTestEnv \ + --features=com.google.cloud.spanner.nativeimage.SpannerFeature diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/resource-config.json b/google-cloud-spanner/src/main/resources/META-INF/native-image/resource-config.json similarity index 100% rename from google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/resource-config.json rename to google-cloud-spanner/src/main/resources/META-INF/native-image/resource-config.json diff --git a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties b/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties deleted file mode 100644 index a063d6e0d05..00000000000 --- a/google-cloud-spanner/src/test/resources/com/google/cloud/spanner/META-INF/native-image/native-image.properties +++ /dev/null @@ -1 +0,0 @@ -Args = --initialize-at-build-time=com.google.cloud.spanner.IntegrationTestEnv --features=com.google.cloud.spanner.nativeimage.SpannerFeature From 6c73a6c784c4f444e443a794ec96490dca08b401 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Fri, 20 May 2022 10:26:27 -0400 Subject: [PATCH 09/18] upgrade to 22.1.0 --- google-cloud-spanner/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index e02500a10fa..53b930590c0 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -16,7 +16,7 @@ google-cloud-spanner 0.31.1 - 22.0.0.2 + 22.1.0 com.google.cloud.spanner.GceTestEnvConfig projects/gcloud-devel/instances/spanner-testing-east1 gcloud-devel From 203f1d03454a488c7a610239c01dabba6a426ac4 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 23 May 2022 13:20:05 +0000 Subject: [PATCH 10/18] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae09624dddd..8b78c739d54 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-spanner' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-spanner:6.24.0' +implementation 'com.google.cloud:google-cloud-spanner:6.25.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.24.0" +libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.25.0" ``` ## Authentication From ee29ce1f538110941c493366186e40cd70bf7778 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Mon, 23 May 2022 09:43:52 -0400 Subject: [PATCH 11/18] initialize junit class at build time --- .../resources/META-INF/native-image/native-image.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties b/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties index d56f752abef..0bcf872e79b 100644 --- a/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties +++ b/google-cloud-spanner/src/main/resources/META-INF/native-image/native-image.properties @@ -1,2 +1,4 @@ -Args = --initialize-at-build-time=com.google.cloud.spanner.IntegrationTestEnv \ +Args = --initialize-at-build-time=com.google.cloud.spanner.IntegrationTestEnv,\ + org.junit.experimental.categories.CategoryValidator,\ + org.junit.validator.AnnotationValidator \ --features=com.google.cloud.spanner.nativeimage.SpannerFeature From c739b77f76741b8321448b2b058d6e73a8582f54 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Tue, 24 May 2022 18:31:23 -0400 Subject: [PATCH 12/18] add GraalVM JDK 17 test --- .kokoro/build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 0bb2b93a739..91699b34016 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -78,6 +78,11 @@ graalvm) mvn test -Pnative -Penable-integration-tests RETURN_CODE=$? ;; +graalvm17) + # Run Unit and Integration Tests with Native Image + mvn test -Pnative -Penable-integration-tests + RETURN_CODE=$? + ;; slowtests) mvn -B ${INTEGRATION_TEST_ARGS} \ -ntp \ From a43464a930820a00239cfc167faea1dadc73e72d Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 25 May 2022 09:52:45 -0400 Subject: [PATCH 13/18] empty commit From 8661e49981e7a0b86c568703b6137e4e7aa6a059 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 25 May 2022 09:53:07 -0400 Subject: [PATCH 14/18] empty commit From 485245d47b127b9cd1fff0f52255f431a28c2796 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 25 May 2022 09:53:32 -0400 Subject: [PATCH 15/18] empty commit From 926f4214fe828935487d7005bebeb69176bc0e78 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 25 May 2022 15:52:39 -0400 Subject: [PATCH 16/18] add pg config --- .../com/google/cloud/spanner/nativeimage/SpannerFeature.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java index 29c6e8b8745..afd30c2e35e 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -39,6 +39,7 @@ final class SpannerFeature implements Feature { "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; + private static final String CLIENT_SIDE_STATEMENT_PG_EXECUTOR = "com.google.cloud.spanner.connection.ClientSideStatementPgBeginExecutor"; private static final String ABSTRACT_STATEMENT_PARSER = "com.google.cloud.spanner.connection.AbstractStatementParser"; private static final String STATEMENT_PARSER = @@ -57,6 +58,9 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_PG_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_PG_EXECUTOR); + } if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); } From a43d130a62d223380aeceaeada12d49f9eee795f Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 25 May 2022 19:55:17 +0000 Subject: [PATCH 17/18] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../com/google/cloud/spanner/nativeimage/SpannerFeature.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java index afd30c2e35e..38007ddc073 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java @@ -39,7 +39,8 @@ final class SpannerFeature implements Feature { "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; - private static final String CLIENT_SIDE_STATEMENT_PG_EXECUTOR = "com.google.cloud.spanner.connection.ClientSideStatementPgBeginExecutor"; + private static final String CLIENT_SIDE_STATEMENT_PG_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementPgBeginExecutor"; private static final String ABSTRACT_STATEMENT_PARSER = "com.google.cloud.spanner.connection.AbstractStatementParser"; private static final String STATEMENT_PARSER = From b6119aae24110b65deb7125fe62bc66ca60458b1 Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Wed, 25 May 2022 19:01:10 -0400 Subject: [PATCH 18/18] ci: ci to build with JDK 11 (cont.) (#1890) * ci: ci to build with JDK 11 (cont.) --- .github/workflows/ci.yaml | 14 +++++++++- .../integration-tests-against-emulator.yaml | 21 ++++++++++++--- .github/workflows/samples.yaml | 27 ++++++++++++++++--- .kokoro/build.sh | 8 ++---- .kokoro/common.sh | 7 ++++- .kokoro/dependencies.sh | 8 ++++++ owlbot.py | 2 ++ 7 files changed, 73 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ef324c71e3..857028b88b8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -83,10 +83,22 @@ jobs: java: [8, 11, 17] steps: - uses: actions/checkout@v3 + # For Java 8 tests, use JDK 11 to compile + - if: ${{matrix.java}} == '8' + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: zulu + - if: ${{matrix.java}} == '8' + run: echo "JAVA11_HOME=${JAVA_HOME}" >> $GITHUB_ENV + shell: bash - uses: actions/setup-java@v3 with: distribution: zulu java-version: ${{matrix.java}} + - if: ${{matrix.java}} == '8' + run: echo "JAVA8_HOME=${JAVA_HOME}" >> $GITHUB_ENV + shell: bash - run: java -version - run: .kokoro/dependencies.sh lint: @@ -108,7 +120,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: zulu - java-version: 8 + java-version: 11 - run: java -version - run: .kokoro/build.sh env: diff --git a/.github/workflows/integration-tests-against-emulator.yaml b/.github/workflows/integration-tests-against-emulator.yaml index 7d82960228a..da05e8d3d75 100644 --- a/.github/workflows/integration-tests-against-emulator.yaml +++ b/.github/workflows/integration-tests-against-emulator.yaml @@ -20,12 +20,27 @@ jobs: - uses: stCarolas/setup-maven@v4 with: maven-version: 3.8.1 - - uses: actions/setup-java@v1 + # Build with JDK 11 and run tests with JDK 8 + - uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: zulu + - run: echo "JAVA11_HOME=${JAVA_HOME}" >> $GITHUB_ENV + shell: bash + - uses: actions/setup-java@v3 with: java-version: 8 + distribution: zulu + - run: echo "JAVA8_HOME=${JAVA_HOME}" >> $GITHUB_ENV + shell: bash - run: java -version - - run: .kokoro/build.sh - - run: mvn -B -Dspanner.testenv.instance="" -Penable-integration-tests -DtrimStackTrace=false -Dclirr.skip=true -Denforcer.skip=true -fae verify + - name: Compiling main library + run: .kokoro/build.sh + - name: Running tests + run: | + mvn -B -Dspanner.testenv.instance="" -Penable-integration-tests \ + -DtrimStackTrace=false -Dclirr.skip=true -Denforcer.skip=true \ + -Dmaven.main.skip=true -fae verify env: JOB_TYPE: test SPANNER_EMULATOR_HOST: localhost:9010 diff --git a/.github/workflows/samples.yaml b/.github/workflows/samples.yaml index ab983e5d492..d0eb0cb5def 100644 --- a/.github/workflows/samples.yaml +++ b/.github/workflows/samples.yaml @@ -12,18 +12,39 @@ jobs: - name: Run checkstyle run: mvn -P lint --quiet --batch-mode checkstyle:check working-directory: samples/snippets + compile-java8: + name: "compile (8)" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v3 + with: + # Java 11 to generate class file targeting Java 8 + java-version: 11 + distribution: zulu + - name: Compile Spanner + run: mvn clean install + - uses: actions/setup-java@v3 + with: + java-version: 8 + distribution: zulu + - name: Compile samples + run: mvn compile + working-directory: samples + compile: runs-on: ubuntu-latest strategy: matrix: - java: [8, 11] + java: [11, 17] steps: - uses: actions/checkout@v2 - - uses: actions/setup-java@v1 + - uses: actions/setup-java@v3 with: java-version: ${{matrix.java}} + distribution: zulu - name: Compile Spanner run: mvn clean install - name: Compile samples run: mvn compile - working-directory: samples + working-directory: samples \ No newline at end of file diff --git a/.kokoro/build.sh b/.kokoro/build.sh index a0824a071c7..750b4915792 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -23,11 +23,6 @@ cd ${scriptDir}/.. # include common functions source ${scriptDir}/common.sh -function setJava() { - export JAVA_HOME=$1 - export PATH=${JAVA_HOME}/bin:$PATH -} - # units-java8 uses both JDK 11 and JDK 8. GraalVM dependencies require JDK 11 to # compile the classes touching GraalVM classes. if [ ! -z "${JAVA11_HOME}" ]; then @@ -57,7 +52,6 @@ fi # are compatible with Java 8 when running tests. if [ ! -z "${JAVA8_HOME}" ]; then setJava "${JAVA8_HOME}" - mvn -version fi RETURN_CODE=0 @@ -87,6 +81,7 @@ integration) -DtrimStackTrace=false \ -Dclirr.skip=true \ -Denforcer.skip=true \ + -Dmaven.main.skip=true \ -fae \ verify RETURN_CODE=$? @@ -110,6 +105,7 @@ slowtests) -DtrimStackTrace=false \ -Dclirr.skip=true \ -Denforcer.skip=true \ + -Dmaven.main.skip=true \ -fae \ verify RETURN_CODE=$? diff --git a/.kokoro/common.sh b/.kokoro/common.sh index ace89f45a9d..6c8089ffddd 100644 --- a/.kokoro/common.sh +++ b/.kokoro/common.sh @@ -55,4 +55,9 @@ function retry_with_backoff { ## Helper functionss function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; } function msg() { println "$*" >&2; } -function println() { printf '%s\n' "$(now) $*"; } \ No newline at end of file +function println() { printf '%s\n' "$(now) $*"; } + +function setJava() { + export JAVA_HOME=$1 + export PATH=${JAVA_HOME}/bin:$PATH +} diff --git a/.kokoro/dependencies.sh b/.kokoro/dependencies.sh index d7476cfe972..6a9f719a5e6 100755 --- a/.kokoro/dependencies.sh +++ b/.kokoro/dependencies.sh @@ -49,6 +49,10 @@ function determineMavenOpts() { export MAVEN_OPTS=$(determineMavenOpts) +if [ ! -z "${JAVA11_HOME}" ]; then + setJava "${JAVA11_HOME}" +fi + # this should run maven enforcer retry_with_backoff 3 10 \ mvn install -B -V -ntp \ @@ -56,6 +60,10 @@ retry_with_backoff 3 10 \ -Dmaven.javadoc.skip=true \ -Dclirr.skip=true +if [ ! -z "${JAVA8_HOME}" ]; then + setJava "${JAVA8_HOME}" +fi + mvn -B dependency:analyze -DfailOnWarning=true echo "****************** DEPENDENCY LIST COMPLETENESS CHECK *******************" diff --git a/owlbot.py b/owlbot.py index cb907a9878c..22fabca5c94 100644 --- a/owlbot.py +++ b/owlbot.py @@ -42,6 +42,8 @@ ".github/blunderbuss.yml", ".github/workflows/samples.yaml", ".github/workflows/ci.yaml", + ".kokoro/common.sh", ".kokoro/build.sh", + ".kokoro/dependencies.sh", ] )