Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Commit 684934e

Browse files
authored
fix(java): initialize spanner test environment class at build-time (#734)
1 parent 3b83bd7 commit 684934e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/OpenCensusFeature.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
@AutomaticFeature
2626
final class OpenCensusFeature implements Feature {
2727

28-
private static final String OPEN_CENSUS_CLASS = "io.opencensus.impl.tags.TagsComponentImpl";
28+
private static final String TAGS_COMPONENT_CLASS = "io.opencensus.impl.tags.TagsComponentImpl";
29+
private static final String STATS_COMPONENT_CLASS = "io.opencensus.impl.stats.StatsComponentImpl";
2930

3031
@Override
3132
public void beforeAnalysis(BeforeAnalysisAccess access) {
32-
if (access.findClassByName(OPEN_CENSUS_CLASS) != null) {
33+
if (access.findClassByName(STATS_COMPONENT_CLASS) != null) {
34+
registerForReflectiveInstantiation(access, STATS_COMPONENT_CLASS);
35+
}
36+
if (access.findClassByName(TAGS_COMPONENT_CLASS) != null) {
3337
registerForReflectiveInstantiation(access, "io.opencensus.impl.metrics.MetricsComponentImpl");
3438
registerForReflectiveInstantiation(access, "io.opencensus.impl.tags.TagsComponentImpl");
3539
registerForReflectiveInstantiation(access, "io.opencensus.impl.trace.TraceComponentImpl");

native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/SpannerFeature.java

+5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
final class SpannerFeature implements Feature {
2828

2929
private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc";
30+
private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig";
3031

3132
@Override
3233
public void beforeAnalysis(BeforeAnalysisAccess access) {
34+
Class<?> spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS);
35+
if (spannerTestClass != null) {
36+
NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS);
37+
}
3338
Class<?> spannerClass = access.findClassByName(SPANNER_CLASS);
3439
if (spannerClass != null) {
3540
NativeImageUtils.registerClassHierarchyForReflection(

native-image-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-core/native-image.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ Args = --allow-incomplete-classpath \
22
--enable-url-protocols=https,http \
33
--initialize-at-build-time=org.conscrypt,\
44
org.slf4j.LoggerFactory,\
5-
org.junit.platform.engine.TestTag \
5+
org.junit.platform.engine.TestTag,\
6+
com.google.cloud.spanner.IntegrationTestEnv \
67
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl,\
78
io.grpc.netty.shaded.io.netty.internal.tcnative.SSL,\
89
io.grpc.netty.shaded.io.netty.internal.tcnative.CertificateVerifier,\

0 commit comments

Comments
 (0)