Skip to content

Native Image tests are failing when System Properties are used.  #1693

@mpeddada1

Description

@mpeddada1

Currently some integrations tests that are run with the native profile are resulting in the following errors:

JUnit Vintage:ITSessionPoolIntegrationTest
    ClassSource [className = 'com.google.cloud.spanner.ITSessionPoolIntegrationTest', filePosition = null]
    => java.lang.NullPointerException: Property spanner.testenv.config.class needs to be set
       com.google.cloud.spanner.IntegrationTestEnv.initializeConfig(IntegrationTestEnv.java:68)
       com.google.cloud.spanner.IntegrationTestEnv.before(IntegrationTestEnv.java:77)
       org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
       org.junit.rules.RunRules.evaluate(RunRules.java:20)
       org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
       org.junit.runners.ParentRunner.run(ParentRunner.java:413)
       org.junit.runner.JUnitCore.run(JUnitCore.java:137)
       org.junit.runner.JUnitCore.run(JUnitCore.java:115)
       org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
       org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
       [...]
JUnit Vintage:ITInstanceAdminTest
    ClassSource [className = 'com.google.cloud.spanner.it.ITInstanceAdminTest', filePosition = null]
    => java.lang.NullPointerException: Property spanner.testenv.config.class needs to be set
       com.google.cloud.spanner.IntegrationTestEnv.initializeConfig(IntegrationTestEnv.java:68)
       com.google.cloud.spanner.IntegrationTestEnv.before(IntegrationTestEnv.java:77)
       org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
       org.junit.rules.RunRules.evaluate(RunRules.java:20)
       org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
       org.junit.runners.ParentRunner.run(ParentRunner.java:413)
       org.junit.runner.JUnitCore.run(JUnitCore.java:137)
       org.junit.runner.JUnitCore.run(JUnitCore.java:115)
       org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
       org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
       [...]

This means that system properties are not accessible to the tests after native image compilation. According to the official documentation, System properties are only available at build-time (when the native image builder is building the image) and not at run-time and can't be determined from the maven-surefire/maven-failsafe plugin. This requires us to do a couple of things:

  1. Pass the System Property in question directly to the native-image command using -Dspanner.testenv.config.class=.
  2. Store the system property's value as the static variable.
  3. Initialize the class that is referencing the System Property at build-time. (fix(java): initialize spanner test environment class at build-time and add reflection configurations java-core#734)

Additionally, we also need to specify the system properties to the maven surefire plugin because the native profile uses this plugin to run tests before building the native image.

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: spannerIssues related to the googleapis/java-spanner API.triage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions