11package datadog.smoketest
22
33import datadog.trace.agent.test.utils.PortUtils
4- import de.thetaphi.forbiddenapis.SuppressForbidden
5- import groovy.transform.CompileStatic
6- import spock.lang.AutoCleanup
7- import spock.lang.Shared
8- import spock.lang.Specification
9-
10- import java.nio.CharBuffer
114import java.nio.file.Files
125import java.nio.file.Paths
136import java.util.concurrent.TimeoutException
7+ import spock.lang.AutoCleanup
8+ import spock.lang.Shared
9+ import spock.lang.Specification
1410
1511abstract class ProcessManager extends Specification {
1612
@@ -20,8 +16,6 @@ abstract class ProcessManager extends Specification {
2016 public static final String ENV = " smoketest"
2117 public static final String VERSION = " 99"
2218
23- @Shared
24- protected String workingDirectory = System . getProperty(" user.dir" )
2519 @Shared
2620 protected String buildDirectory = System . getProperty(" datadog.smoketest.builddir" )
2721 @Shared
@@ -73,9 +67,7 @@ abstract class ProcessManager extends Specification {
7367 OutputThreads outputThreads = new OutputThreads ()
7468
7569 def setupSpec () {
76- if (buildDirectory == null || shadowJarPath == null ) {
77- throw new AssertionError (" Expected system properties not found. Smoke tests have to be run from Gradle. Please make sure that is the case." )
78- }
70+ assert buildDirectory && shadowJarPath: ' Expected system properties not found. Smoke tests have to be run from Gradle. Please make sure that is the case.'
7971 assert Files . isDirectory(Paths . get(buildDirectory))
8072 assert Files . isRegularFile(Paths . get(shadowJarPath))
8173
@@ -84,7 +76,6 @@ abstract class ProcessManager extends Specification {
8476 (0 .. < numberOfProcesses). each { idx ->
8577 ProcessBuilder processBuilder = createProcessBuilder(idx)
8678
87-
8879 processBuilder. environment(). put(" JAVA_HOME" , System . getProperty(" java.home" ))
8980 processBuilder. environment(). put(" DD_API_KEY" , apiKey())
9081
@@ -101,7 +92,7 @@ abstract class ProcessManager extends Specification {
10192 (0 .. < numberOfProcesses). each { idx ->
10293 def curProc = testedProcesses[idx]
10394
104- if ( ! curProc. isAlive() && curProc. exitValue() != 0 ) {
95+ if (! curProc. isAlive() && curProc. exitValue() != 0 ) {
10596 def exitCode = curProc. exitValue()
10697 def logFile = logFilePaths[idx]
10798
@@ -124,7 +115,7 @@ abstract class ProcessManager extends Specification {
124115 exitValue = tp?. exitValue()
125116 break
126117 }
127- catch (Throwable e ) {
118+ catch (Throwable ignored ) {
128119 if (attempt == 1 ) {
129120 System . out. println (" Destroying instrumented process" )
130121 tp. destroy()
@@ -212,8 +203,11 @@ abstract class ProcessManager extends Specification {
212203
213204 void forEachLogLine (Closure checker ) {
214205 for (String lfp : logFilePaths) {
215- ProcessManager . eachLine(new File (lfp)) {
216- checker(it)
206+ def file = new File (lfp)
207+ file. withReader { reader ->
208+ reader. eachLine {
209+ checker(it)
210+ }
217211 }
218212 }
219213 }
@@ -240,7 +234,7 @@ abstract class ProcessManager extends Specification {
240234 * @param checker should return true if a match is found
241235 */
242236 void processTestLogLines (Closure<Boolean > checker ) {
243- outputThreads. processTestLogLines {return checker(it) }
237+ outputThreads. processTestLogLines { return checker(it) }
244238 }
245239
246240 protected void beforeProcessBuilders () {}
@@ -259,33 +253,4 @@ abstract class ProcessManager extends Specification {
259253 String apiKey () {
260254 return " 01234567890abcdef123456789ABCDEF"
261255 }
262-
263- @CompileStatic
264- @SuppressForbidden
265- private static void eachLine (File file , Closure closure ) {
266- def reader = new InputStreamReader (new FileInputStream (file))
267- CharBuffer buffer = CharBuffer . allocate(OutputThreads . MAX_LINE_SIZE )
268- while (reader. read(buffer) != -1 ) {
269- buffer. flip()
270- while (buffer. hasRemaining()) {
271- char c = buffer. get()
272- if (c == ' \n ' || c == ' \r ' ) {
273- break
274- }
275- }
276- // we found the separator or we're out of data (max line size hit)
277- // either way, report a line
278- def str = buffer. duplicate(). flip(). toString(). trim()
279- if (str) {
280- closure(str)
281- }
282-
283- buffer. compact()
284- }
285- if (buffer. position() > 0 ) {
286- buffer. flip(). toString(). split(' \r\n |\n ' ). each {
287- closure. call(it. trim())
288- }
289- }
290- }
291256}
0 commit comments