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

Commit 6fe52c3

Browse files
authored
fix(java): register test class for reflection to fix native image test (#766)
* fix(java): register test class for reflection to fix native image test
1 parent 63edc69 commit 6fe52c3

File tree

1 file changed

+14
-4
lines changed
  • native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients

1 file changed

+14
-4
lines changed

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final class SpannerFeature implements Feature {
2929

3030
private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc";
3131
private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig";
32+
private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl";
3233
private static final String CLIENT_SIDE_IMPL_CLASS =
3334
"com.google.cloud.spanner.connection.ClientSideStatementImpl";
3435
private static final String CLIENT_SIDE_VALUE_CONVERTER =
@@ -50,10 +51,7 @@ final class SpannerFeature implements Feature {
5051

5152
@Override
5253
public void beforeAnalysis(BeforeAnalysisAccess access) {
53-
Class<?> spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS);
54-
if (spannerTestClass != null) {
55-
NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS);
56-
}
54+
registerSpannerTestClasses(access);
5755
if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) {
5856
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS);
5957
}
@@ -103,4 +101,16 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
103101
"\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E");
104102
}
105103
}
104+
105+
private void registerSpannerTestClasses(BeforeAnalysisAccess access) {
106+
Class<?> spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS);
107+
if (spannerTestClass != null) {
108+
NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS);
109+
}
110+
Class<?> mockClass = access.findClassByName(MOCK_CLASS);
111+
if (mockClass != null) {
112+
NativeImageUtils.registerClassForReflection(
113+
access, "com.google.cloud.spanner.MockDatabaseAdminServiceImpl$MockBackup");
114+
}
115+
}
106116
}

0 commit comments

Comments
 (0)