@@ -33,7 +33,9 @@ class FieldInjectionSmokeTest extends Specification {
3333 @Shared
3434 protected String shadowJarPath = System . getProperty(" datadog.smoketest.agent.shadowJar.path" )
3535 @Shared
36- protected String logFilePath = " ${ buildDirectory} /reports/testProcess.${ this.getClass().getName()} .log"
36+ protected String outFilePath = " ${ buildDirectory} /reports/testProcess.${ this.getClass().getName()} .out.log"
37+ @Shared
38+ protected String errFilePath = " ${ buildDirectory} /reports/testProcess.${ this.getClass().getName()} .err.log"
3739
3840 def " types are injected with expected fields" () {
3941 setup :
@@ -72,21 +74,36 @@ class FieldInjectionSmokeTest extends Specification {
7274 processBuilder. directory(new File (buildDirectory))
7375 processBuilder. environment(). put(" JAVA_HOME" , System . getProperty(" java.home" ))
7476
75- Path testOutput = Paths . get(logFilePath)
76- processBuilder. redirectErrorStream(true )
77- processBuilder. redirectOutput(testOutput. toFile())
77+ Path testOut = Paths . get(outFilePath)
78+ Path testErr = Paths . get(errFilePath)
79+ processBuilder. redirectOutput(testOut. toFile())
80+ processBuilder. redirectError(testErr. toFile())
7881 Process testedProcess = processBuilder. start()
7982
8083 expect :
8184 testedProcess. waitFor(TIMEOUT_SECS , SECONDS )
8285 testedProcess. exitValue() == 0
83- List<String > lines = Files . readAllLines(testOutput)
86+ List<String > linesOut = Files . readAllLines(testOut)
87+ List<String > linesErr = Files . readAllLines(testErr)
8488 Map<String , Set<String > > foundTypesAndFields = new HashMap<> ()
8589 Map<String , List<String > > foundTypesAndInterfaces = new HashMap<> ()
8690 Map<String , List<String > > foundTypesAndGenericInterfaces = new HashMap<> ()
8791 Map<String , String > storeFieldAliases = new HashMap<> ()
88- for (String line : lines) {
92+ for (String line : linesErr) {
93+ System . err. println (line)
94+ // extract context-store allocations from tracer logging
95+ Matcher storeAllocation = CONTEXT_STORE_ALLOCATION . matcher(line)
96+ if (storeAllocation. matches()) {
97+ // assertions use context key while internally we use storeId,
98+ // so we need to record the storeId alias for each context key
99+ String storeId = storeAllocation. group(1 )
100+ String keyName = storeAllocation. group(2 )
101+ storeFieldAliases. put(fieldName(storeId), fieldName(keyName))
102+ }
103+ }
104+ for (String line : linesOut) {
89105 System . out. println (line)
106+ // extract structural info from test application logging
90107 if (line. startsWith(" ___FIELD___" )) {
91108 String [] parts = line. split(" :" )
92109 parts[2 ] = storeFieldAliases. get(parts[2 ])
@@ -97,23 +114,13 @@ class FieldInjectionSmokeTest extends Specification {
97114 } else if (line. startsWith(" ___GENERIC_INTERFACE___" )) {
98115 String [] parts = line. split(" :" )
99116 foundTypesAndGenericInterfaces. computeIfAbsent(parts[1 ], { new HashSet<> () }). add(parts[2 ])
100- } else {
101- Matcher storeAllocation = CONTEXT_STORE_ALLOCATION . matcher(line)
102- if (storeAllocation. matches()) {
103- // assertions use context key while internally we use storeId,
104- // so we need to record the storeId alias for each context key
105- String storeId = storeAllocation. group(1 )
106- String keyName = storeAllocation. group(2 )
107- storeFieldAliases. put(fieldName(storeId), fieldName(keyName))
108- }
109117 }
110118 }
111119 assert testedTypesAndExpectedFields == foundTypesAndFields
112120 // check same list of names for interfaces and generic interfaces
113121 assert foundTypesAndInterfaces == foundTypesAndGenericInterfaces
114122 }
115123
116-
117124 def fieldName (Class<?> klass ) {
118125 return fieldName(klass. getName())
119126 }
0 commit comments