Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mpeddada1 opened this issue Feb 16, 2022 · 0 comments · Fixed by #1694
Closed

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

mpeddada1 opened this issue Feb 16, 2022 · 0 comments · Fixed by #1694
Assignees
Labels
api: spanner Issues related to the googleapis/java-spanner API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@mpeddada1
Copy link
Contributor

mpeddada1 commented Feb 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants