@@ -33,7 +33,9 @@ class FieldInjectionSmokeTest extends Specification {
33
33
@Shared
34
34
protected String shadowJarPath = System . getProperty(" datadog.smoketest.agent.shadowJar.path" )
35
35
@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"
37
39
38
40
def " types are injected with expected fields" () {
39
41
setup :
@@ -72,21 +74,36 @@ class FieldInjectionSmokeTest extends Specification {
72
74
processBuilder. directory(new File (buildDirectory))
73
75
processBuilder. environment(). put(" JAVA_HOME" , System . getProperty(" java.home" ))
74
76
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())
78
81
Process testedProcess = processBuilder. start()
79
82
80
83
expect :
81
84
testedProcess. waitFor(TIMEOUT_SECS , SECONDS )
82
85
testedProcess. exitValue() == 0
83
- List<String > lines = Files . readAllLines(testOutput)
86
+ List<String > linesOut = Files . readAllLines(testOut)
87
+ List<String > linesErr = Files . readAllLines(testErr)
84
88
Map<String , Set<String > > foundTypesAndFields = new HashMap<> ()
85
89
Map<String , List<String > > foundTypesAndInterfaces = new HashMap<> ()
86
90
Map<String , List<String > > foundTypesAndGenericInterfaces = new HashMap<> ()
87
91
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) {
89
105
System . out. println (line)
106
+ // extract structural info from test application logging
90
107
if (line. startsWith(" ___FIELD___" )) {
91
108
String [] parts = line. split(" :" )
92
109
parts[2 ] = storeFieldAliases. get(parts[2 ])
@@ -97,23 +114,13 @@ class FieldInjectionSmokeTest extends Specification {
97
114
} else if (line. startsWith(" ___GENERIC_INTERFACE___" )) {
98
115
String [] parts = line. split(" :" )
99
116
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
- }
109
117
}
110
118
}
111
119
assert testedTypesAndExpectedFields == foundTypesAndFields
112
120
// check same list of names for interfaces and generic interfaces
113
121
assert foundTypesAndInterfaces == foundTypesAndGenericInterfaces
114
122
}
115
123
116
-
117
124
def fieldName (Class<?> klass ) {
118
125
return fieldName(klass. getName())
119
126
}
0 commit comments