kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 224ae57a24ac8b5ac26d3732f6d4938ad9b41bfa384e4928aff346506d3e8d30 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-03 14:47 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-07 08:13 -05:00 |
| Parents | f3391d2c849a |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +32 −1
| @@ -28,6 +28,7 @@ | ||
| 28 | 28 | |
| 29 | 29 | import com.google.common.base.Joiner; |
| 30 | 30 | import com.google.common.collect.ImmutableMap; |
| 31 | +import com.google.common.collect.Maps; | |
| 31 | 32 | import com.google.common.io.ByteStreams; |
| 32 | 33 | import com.google.common.io.Closer; |
| 33 | 34 | import com.google.common.io.Files; |
| @@ -72,6 +73,36 @@ | ||
| 72 | 73 | |
| 73 | 74 | private static final File DEFAULT_SERVER_KEYSTORE_FILE = createTempStore(DEFAULT_SERVER_KEYSTORE_PATH); |
| 74 | 75 | |
| 76 | + /** | |
| 77 | + * The environment variables to use when invoking CCM. Inherits the current processes environment, but will also | |
| 78 | + * prepend to the PATH variable the value of the 'ccm.path' property and set JAVA_HOME variable to the | |
| 79 | + * 'ccm.java.home' variable. | |
| 80 | + * | |
| 81 | + * At times it is necessary to use a separate java install for CCM then what is being used for running tests. | |
| 82 | + * For example, if you want to run tests with JDK 6 but against Cassandra 2.0, which requires JDK 7. | |
| 83 | + */ | |
| 84 | + private static final Map<String,String> ENVIRONMENT_MAP; | |
| 85 | + | |
| 86 | + static { | |
| 87 | + // Inherit the current environment. | |
| 88 | + Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); | |
| 89 | + // If ccm.path is set, override the PATH variable with it. | |
| 90 | + String ccmPath = System.getProperty("ccm.path"); | |
| 91 | + if(ccmPath != null) { | |
| 92 | + String existingPath = envMap.get("PATH"); | |
| 93 | + if(existingPath == null) { | |
| 94 | + existingPath = ""; | |
| 95 | + } | |
| 96 | + envMap.put("PATH", ccmPath + ":" + existingPath); | |
| 97 | + } | |
| 98 | + // If ccm.java.home is set, override the JAVA_HOME variable with it. | |
| 99 | + String ccmJavaHome = System.getProperty("ccm.java.home"); | |
| 100 | + if(ccmJavaHome != null) { | |
| 101 | + envMap.put("JAVA_HOME", ccmJavaHome); | |
| 102 | + } | |
| 103 | + ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); | |
| 104 | + } | |
| 105 | + | |
| 75 | 106 | static final File CASSANDRA_DIR; |
| 76 | 107 | static final String CASSANDRA_VERSION; |
| 77 | 108 | |
| @@ -290,7 +321,7 @@ | ||
| 290 | 321 | ExecuteStreamHandler streamHandler = new PumpStreamHandler(outStream, errStream); |
| 291 | 322 | executor.setStreamHandler(streamHandler); |
| 292 | 323 | |
| 293 | - int retValue = executor.execute(cli); | |
| 324 | + int retValue = executor.execute(cli, ENVIRONMENT_MAP); | |
| 294 | 325 | if (retValue != 0) { |
| 295 | 326 | logger.error("Non-zero exit code ({}) returned from executing ccm command: {}", retValue, fullCommand); |
| 296 | 327 | throw new RuntimeException(); |