kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5cad9430ebec50efbfa636f6fd2c379124c4032a747a12aa4f5ed741b8743da8 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-07 08:18 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-07 08:18 -05:00 |
| Parents | 92ae90bf3cd7, 224ae57a24ac |
3 files changed
modified driver-core/pom.xml +7 −0
| @@ -111,6 +111,13 @@ | ||
| 111 | 111 | </exclusions> |
| 112 | 112 | </dependency> |
| 113 | 113 | |
| 114 | + <dependency> | |
| 115 | + <groupId>org.apache.commons</groupId> | |
| 116 | + <artifactId>commons-exec</artifactId> | |
| 117 | + <version>1.3</version> | |
| 118 | + <scope>test</scope> | |
| 119 | + </dependency> | |
| 120 | + | |
| 114 | 121 | </dependencies> |
| 115 | 122 | |
| 116 | 123 | <build> |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +50 −45
| @@ -28,9 +28,11 @@ | ||
| 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; |
| 35 | +import org.apache.commons.exec.*; | |
| 34 | 36 | import org.slf4j.Logger; |
| 35 | 37 | import org.slf4j.LoggerFactory; |
| 36 | 38 | import org.testng.annotations.AfterClass; |
| @@ -71,6 +73,36 @@ | ||
| 71 | 73 | |
| 72 | 74 | private static final File DEFAULT_SERVER_KEYSTORE_FILE = createTempStore(DEFAULT_SERVER_KEYSTORE_PATH); |
| 73 | 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 | + | |
| 74 | 106 | static final File CASSANDRA_DIR; |
| 75 | 107 | static final String CASSANDRA_VERSION; |
| 76 | 108 | |
| @@ -226,14 +258,6 @@ | ||
| 226 | 258 | execute("ccm node%d remove", n); |
| 227 | 259 | } |
| 228 | 260 | |
| 229 | - public void ring() { | |
| 230 | - ring(1); | |
| 231 | - } | |
| 232 | - | |
| 233 | - public void ring(int n) { | |
| 234 | - executeAndPrint("ccm node%d ring", n); | |
| 235 | - } | |
| 236 | - | |
| 237 | 261 | public void bootstrapNode(int n) { |
| 238 | 262 | bootstrapNode(n, null); |
| 239 | 263 | } |
| @@ -280,49 +304,30 @@ | ||
| 280 | 304 | try { |
| 281 | 305 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| 282 | 306 | logger.debug("Executing: " + fullCommand); |
| 283 | - Process p = runtime.exec(fullCommand, null, CASSANDRA_DIR); | |
| 284 | - int retValue = p.waitFor(); | |
| 285 | - | |
| 286 | - if (retValue != 0) { | |
| 287 | - BufferedReader outReader = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
| 288 | - BufferedReader errReader = new BufferedReader(new InputStreamReader(p.getErrorStream())); | |
| 289 | - | |
| 290 | - String line = outReader.readLine(); | |
| 291 | - while (line != null) { | |
| 292 | - logger.info("out> " + line); | |
| 293 | - line = outReader.readLine(); | |
| 307 | + CommandLine cli = CommandLine.parse(fullCommand); | |
| 308 | + Executor executor = new DefaultExecutor(); | |
| 309 | + | |
| 310 | + LogOutputStream outStream = new LogOutputStream() { | |
| 311 | + @Override protected void processLine(String line, int logLevel) { | |
| 312 | + logger.debug("ccmout> " + line); | |
| 294 | 313 | } |
| 295 | - line = errReader.readLine(); | |
| 296 | - while (line != null) { | |
| 297 | - logger.error("err> " + line); | |
| 298 | - line = errReader.readLine(); | |
| 314 | + }; | |
| 315 | + LogOutputStream errStream = new LogOutputStream() { | |
| 316 | + @Override protected void processLine(String line, int logLevel) { | |
| 317 | + logger.error("ccmerr> " + line); | |
| 299 | 318 | } |
| 300 | - throw new RuntimeException(); | |
| 301 | - } | |
| 302 | - } catch (IOException e) { | |
| 303 | - throw new RuntimeException(e); | |
| 304 | - } catch (InterruptedException e) { | |
| 305 | - throw new RuntimeException(e); | |
| 306 | - } | |
| 307 | - } | |
| 319 | + }; | |
| 308 | 320 | |
| 309 | - private void executeAndPrint(String command, Object... args) { | |
| 310 | - try { | |
| 311 | - String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; | |
| 312 | - logger.debug("Executing: " + fullCommand); | |
| 313 | - Process p = runtime.exec(fullCommand, null, CASSANDRA_DIR); | |
| 314 | - int retValue = p.waitFor(); | |
| 315 | - | |
| 316 | - BufferedReader outReaderOutput = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
| 317 | - String line = outReaderOutput.readLine(); | |
| 318 | - while (line != null) { | |
| 319 | - System.out.println(line); | |
| 320 | - line = outReaderOutput.readLine(); | |
| 321 | + ExecuteStreamHandler streamHandler = new PumpStreamHandler(outStream, errStream); | |
| 322 | + executor.setStreamHandler(streamHandler); | |
| 323 | + | |
| 324 | + int retValue = executor.execute(cli, ENVIRONMENT_MAP); | |
| 325 | + if (retValue != 0) { | |
| 326 | + logger.error("Non-zero exit code ({}) returned from executing ccm command: {}", retValue, fullCommand); | |
| 327 | + throw new RuntimeException(); | |
| 321 | 328 | } |
| 322 | 329 | } catch (IOException e) { |
| 323 | 330 | throw new RuntimeException(e); |
| 324 | - } catch (InterruptedException e) { | |
| 325 | - throw new RuntimeException(e); | |
| 326 | 331 | } |
| 327 | 332 | } |
| 328 | 333 |
modified driver-examples/osgi/pom.xml +8 −0
| @@ -117,12 +117,20 @@ | ||
| 117 | 117 | <version>3.1.0</version> |
| 118 | 118 | <scope>test</scope> |
| 119 | 119 | </dependency> |
| 120 | + | |
| 120 | 121 | <dependency> |
| 121 | 122 | <groupId>javax.inject</groupId> |
| 122 | 123 | <artifactId>javax.inject</artifactId> |
| 123 | 124 | <version>1</version> |
| 124 | 125 | <scope>test</scope> |
| 125 | 126 | </dependency> |
| 127 | + | |
| 128 | + <dependency> | |
| 129 | + <groupId>org.apache.commons</groupId> | |
| 130 | + <artifactId>commons-exec</artifactId> | |
| 131 | + <version>1.3</version> | |
| 132 | + <scope>test</scope> | |
| 133 | + </dependency> | |
| 126 | 134 | </dependencies> |
| 127 | 135 | |
| 128 | 136 | <build> |