Skip to content

Commit

Permalink
fix(java): make system property accessible for native image compilati…
Browse files Browse the repository at this point in the history
…on (#1694)

* fix(java): make system properties accessible for native image compilation

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
mpeddada1 and gcf-owl-bot[bot] authored Feb 22, 2022
1 parent 98cac5d commit e3fb2b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
38 changes: 34 additions & 4 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<properties>
<site.installationModule>google-cloud-spanner</site.installationModule>
<opencensus.version>0.31.0</opencensus.version>
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing-east1</spanner.testenv.instance>
<spanner.gce.config.project_id>gcloud-devel</spanner.gce.config.project_id>
<spanner.testenv.kms_key.name>projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key</spanner.testenv.kms_key.name>
</properties>


Expand Down Expand Up @@ -70,10 +74,10 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing-east1</spanner.testenv.instance>
<spanner.gce.config.project_id>gcloud-devel</spanner.gce.config.project_id>
<spanner.testenv.kms_key.name>projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key</spanner.testenv.kms_key.name>
<spanner.testenv.config.class>${spanner.testenv.config.class}</spanner.testenv.config.class>
<spanner.testenv.instance>${spanner.testenv.instance}</spanner.testenv.instance>
<spanner.gce.config.project_id>${spanner.gce.config.project_id}</spanner.gce.config.project_id>
<spanner.testenv.kms_key.name>${spanner.testenv.kms_key.name}</spanner.testenv.kms_key.name>
</systemPropertyVariables>
<forkedProcessTimeoutInSeconds>3000</forkedProcessTimeoutInSeconds>
</configuration>
Expand All @@ -100,6 +104,32 @@
</execution>
</executions>
</plugin>

<!--Configurations for native image tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<spanner.testenv.config.class>${spanner.testenv.config.class}</spanner.testenv.config.class>
<spanner.testenv.instance>${spanner.testenv.instance}</spanner.testenv.instance>
<spanner.gce.config.project_id>${spanner.gce.config.project_id}</spanner.gce.config.project_id>
<spanner.testenv.kms_key.name>${spanner.testenv.kms_key.name}</spanner.testenv.kms_key.name>
</systemPropertyVariables>
<forkedProcessTimeoutInSeconds>3000</forkedProcessTimeoutInSeconds>
</configuration>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs combine.children="append">
<buildArg>-Dspanner.testenv.config.class=${spanner.testenv.config.class}</buildArg>
</buildArgs>
</configuration>
</plugin>
<!--Configurations for native image tests-->

<plugin>
<?m2e ignore?>
<groupId>org.codehaus.mojo</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class IntegrationTestEnv extends ExternalResource {
/** Names a property that provides the class name of the {@link TestEnvConfig} to use. */
public static final String TEST_ENV_CONFIG_CLASS_NAME = "spanner.testenv.config.class";

public static final String CONFIG_CLASS = System.getProperty(TEST_ENV_CONFIG_CLASS_NAME, null);

/**
* Names a property that, if set, identifies an existing Cloud Spanner instance to use for tests.
*/
Expand All @@ -62,12 +64,11 @@ public RemoteSpannerHelper getTestHelper() {
@SuppressWarnings("unchecked")
protected void initializeConfig()
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
String configClassName = System.getProperty(TEST_ENV_CONFIG_CLASS_NAME, null);
if (configClassName == null) {
if (CONFIG_CLASS == null) {
throw new NullPointerException("Property " + TEST_ENV_CONFIG_CLASS_NAME + " needs to be set");
}
Class<? extends TestEnvConfig> configClass;
configClass = (Class<? extends TestEnvConfig>) Class.forName(configClassName);
configClass = (Class<? extends TestEnvConfig>) Class.forName(CONFIG_CLASS);
config = configClass.newInstance();
}

Expand Down

0 comments on commit e3fb2b2

Please sign in to comment.