kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f3391d2c849ab11a4c3bcc1d237fd844a3295a21bf6a375f901345451b2339a1 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-10 20:27 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-07 08:13 -05:00 |
| Parents | 92ae90bf3cd7 |
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 +19 −45
| @@ -31,6 +31,7 @@ | ||
| 31 | 31 | import com.google.common.io.ByteStreams; |
| 32 | 32 | import com.google.common.io.Closer; |
| 33 | 33 | import com.google.common.io.Files; |
| 34 | +import org.apache.commons.exec.*; | |
| 34 | 35 | import org.slf4j.Logger; |
| 35 | 36 | import org.slf4j.LoggerFactory; |
| 36 | 37 | import org.testng.annotations.AfterClass; |
| @@ -226,14 +227,6 @@ | ||
| 226 | 227 | execute("ccm node%d remove", n); |
| 227 | 228 | } |
| 228 | 229 | |
| 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 | 230 | public void bootstrapNode(int n) { |
| 238 | 231 | bootstrapNode(n, null); |
| 239 | 232 | } |
| @@ -280,49 +273,30 @@ | ||
| 280 | 273 | try { |
| 281 | 274 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| 282 | 275 | 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(); | |
| 276 | + CommandLine cli = CommandLine.parse(fullCommand); | |
| 277 | + Executor executor = new DefaultExecutor(); | |
| 278 | + | |
| 279 | + LogOutputStream outStream = new LogOutputStream() { | |
| 280 | + @Override protected void processLine(String line, int logLevel) { | |
| 281 | + logger.debug("ccmout> " + line); | |
| 294 | 282 | } |
| 295 | - line = errReader.readLine(); | |
| 296 | - while (line != null) { | |
| 297 | - logger.error("err> " + line); | |
| 298 | - line = errReader.readLine(); | |
| 283 | + }; | |
| 284 | + LogOutputStream errStream = new LogOutputStream() { | |
| 285 | + @Override protected void processLine(String line, int logLevel) { | |
| 286 | + logger.error("ccmerr> " + line); | |
| 299 | 287 | } |
| 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 | - } | |
| 288 | + }; | |
| 308 | 289 | |
| 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(); | |
| 290 | + ExecuteStreamHandler streamHandler = new PumpStreamHandler(outStream, errStream); | |
| 291 | + executor.setStreamHandler(streamHandler); | |
| 292 | + | |
| 293 | + int retValue = executor.execute(cli); | |
| 294 | + if (retValue != 0) { | |
| 295 | + logger.error("Non-zero exit code ({}) returned from executing ccm command: {}", retValue, fullCommand); | |
| 296 | + throw new RuntimeException(); | |
| 321 | 297 | } |
| 322 | 298 | } catch (IOException e) { |
| 323 | 299 | throw new RuntimeException(e); |
| 324 | - } catch (InterruptedException e) { | |
| 325 | - throw new RuntimeException(e); | |
| 326 | 300 | } |
| 327 | 301 | } |
| 328 | 302 |
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> |