Skip to content

Commit

Permalink
fix(java): register test class for reflection to fix native image test (
Browse files Browse the repository at this point in the history
#766)

* fix(java): register test class for reflection to fix native image test
  • Loading branch information
mpeddada1 authored Apr 1, 2022
1 parent deb19a9 commit fa07125
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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 =
Expand All @@ -50,10 +51,7 @@ final class SpannerFeature implements Feature {

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
Class<?> spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS);
if (spannerTestClass != null) {
NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS);
}
registerSpannerTestClasses(access);
if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) {
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS);
}
Expand Down Expand Up @@ -103,4 +101,16 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
"\\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");
}
}
}

0 comments on commit fa07125

Please sign in to comment.