33import static datadog .trace .util .Strings .toJson ;
44
55import datadog .trace .api .DisableTestTrace ;
6+ import datadog .trace .api .civisibility .DDTest ;
7+ import datadog .trace .api .civisibility .DDTestSuite ;
68import datadog .trace .api .civisibility .InstrumentationBridge ;
79import datadog .trace .api .civisibility .config .TestIdentifier ;
8- import datadog .trace .api .civisibility .events .TestDescriptor ;
910import datadog .trace .api .civisibility .events .TestEventsHandler ;
10- import datadog .trace .api .civisibility .events .TestSuiteDescriptor ;
1111import datadog .trace .api .civisibility .retry .TestRetryPolicy ;
1212import datadog .trace .api .civisibility .telemetry .CiVisibilityCountMetric ;
1313import datadog .trace .api .civisibility .telemetry .CiVisibilityMetricCollector ;
1919import datadog .trace .civisibility .domain .TestFrameworkSession ;
2020import datadog .trace .civisibility .domain .TestImpl ;
2121import datadog .trace .civisibility .domain .TestSuiteImpl ;
22- import datadog .trace .civisibility .utils .ConcurrentHashMapContextStore ;
2322import java .lang .reflect .Method ;
2423import java .util .Collection ;
2524import java .util .Collections ;
2928import org .slf4j .Logger ;
3029import org .slf4j .LoggerFactory ;
3130
32- public class TestEventsHandlerImpl implements TestEventsHandler {
31+ public class TestEventsHandlerImpl <SuiteKey , TestKey >
32+ implements TestEventsHandler <SuiteKey , TestKey > {
3333
3434 private static final Logger log = LoggerFactory .getLogger (TestEventsHandlerImpl .class );
3535
3636 private final CiVisibilityMetricCollector metricCollector ;
3737 private final TestFrameworkSession testSession ;
3838 private final TestFrameworkModule testModule ;
39-
40- private final ContextStore <TestSuiteDescriptor , TestSuiteImpl > inProgressTestSuites =
41- new ConcurrentHashMapContextStore <>();
42-
43- private final ContextStore <TestDescriptor , TestImpl > inProgressTests =
44- new ConcurrentHashMapContextStore <>();
39+ private final ContextStore <SuiteKey , TestSuiteImpl > inProgressTestSuites ;
40+ private final ContextStore <TestKey , TestImpl > inProgressTests ;
4541
4642 public TestEventsHandlerImpl (
4743 CiVisibilityMetricCollector metricCollector ,
4844 TestFrameworkSession testSession ,
49- TestFrameworkModule testModule ) {
45+ TestFrameworkModule testModule ,
46+ ContextStore <SuiteKey , DDTestSuite > suiteStore ,
47+ ContextStore <TestKey , DDTest > testStore ) {
5048 this .metricCollector = metricCollector ;
5149 this .testSession = testSession ;
5250 this .testModule = testModule ;
51+ this .inProgressTestSuites = (ContextStore ) suiteStore ;
52+ this .inProgressTests = (ContextStore ) testStore ;
5353 }
5454
5555 @ Override
5656 public void onTestSuiteStart (
57+ final SuiteKey descriptor ,
5758 final String testSuiteName ,
5859 final @ Nullable String testFramework ,
5960 final @ Nullable String testFrameworkVersion ,
@@ -79,55 +80,45 @@ public void onTestSuiteStart(
7980 Tags .TEST_TRAITS , toJson (Collections .singletonMap ("category" , toJson (categories )), true ));
8081 }
8182
82- TestSuiteDescriptor descriptor = new TestSuiteDescriptor (testSuiteName , testClass );
8383 inProgressTestSuites .put (descriptor , testSuite );
8484 }
8585
8686 @ Override
87- public void onTestSuiteFinish (final String testSuiteName , final @ Nullable Class <?> testClass ) {
88- if (skipTrace (testClass )) {
87+ public void onTestSuiteFinish (SuiteKey descriptor ) {
88+ if (skipTrace (descriptor . getClass () )) {
8989 return ;
9090 }
9191
92- TestSuiteDescriptor descriptor = new TestSuiteDescriptor (testSuiteName , testClass );
9392 TestSuiteImpl testSuite = inProgressTestSuites .remove (descriptor );
9493 testSuite .end (null );
9594 }
9695
9796 @ Override
98- public void onTestSuiteSkip (String testSuiteName , Class <?> testClass , @ Nullable String reason ) {
99- TestSuiteDescriptor descriptor = new TestSuiteDescriptor (testSuiteName , testClass );
97+ public void onTestSuiteSkip (SuiteKey descriptor , @ Nullable String reason ) {
10098 TestSuiteImpl testSuite = inProgressTestSuites .get (descriptor );
10199 if (testSuite == null ) {
102- log .debug (
103- "Ignoring skip event, could not find test suite with name {} and class {}" ,
104- testSuiteName ,
105- testClass );
100+ log .debug ("Ignoring skip event, could not find test suite {}" , descriptor );
106101 return ;
107102 }
108103 testSuite .setSkipReason (reason );
109104 }
110105
111106 @ Override
112- public void onTestSuiteFailure (
113- String testSuiteName , Class <?> testClass , @ Nullable Throwable throwable ) {
114- TestSuiteDescriptor descriptor = new TestSuiteDescriptor (testSuiteName , testClass );
107+ public void onTestSuiteFailure (SuiteKey descriptor , @ Nullable Throwable throwable ) {
115108 TestSuiteImpl testSuite = inProgressTestSuites .get (descriptor );
116109 if (testSuite == null ) {
117- log .debug (
118- "Ignoring fail event, could not find test suite with name {} and class {}" ,
119- testSuiteName ,
120- testClass );
110+ log .debug ("Ignoring fail event, could not find test suite {}" , descriptor );
121111 return ;
122112 }
123113 testSuite .setErrorInfo (throwable );
124114 }
125115
126116 @ Override
127117 public void onTestStart (
118+ final SuiteKey suiteDescriptor ,
119+ final TestKey descriptor ,
128120 final String testSuiteName ,
129121 final String testName ,
130- final @ Nullable Object testQualifier ,
131122 final @ Nullable String testFramework ,
132123 final @ Nullable String testFrameworkVersion ,
133124 final @ Nullable String testParameters ,
@@ -140,7 +131,6 @@ public void onTestStart(
140131 return ;
141132 }
142133
143- TestSuiteDescriptor suiteDescriptor = new TestSuiteDescriptor (testSuiteName , testClass );
144134 TestSuiteImpl testSuite = inProgressTestSuites .get (suiteDescriptor );
145135 TestImpl test = testSuite .testStart (testName , testMethod , null );
146136
@@ -183,81 +173,45 @@ public void onTestStart(
183173 test .setTag (Tags .TEST_IS_RETRY , true );
184174 }
185175
186- TestDescriptor descriptor =
187- new TestDescriptor (testSuiteName , testClass , testName , testParameters , testQualifier );
188176 inProgressTests .put (descriptor , test );
189177 }
190178
191179 @ Override
192- public void onTestSkip (
193- String testSuiteName ,
194- Class <?> testClass ,
195- String testName ,
196- @ Nullable Object testQualifier ,
197- @ Nullable String testParameters ,
198- @ Nullable String reason ) {
199- TestDescriptor descriptor =
200- new TestDescriptor (testSuiteName , testClass , testName , testParameters , testQualifier );
180+ public void onTestSkip (TestKey descriptor , @ Nullable String reason ) {
201181 TestImpl test = inProgressTests .get (descriptor );
202182 if (test == null ) {
203- log .debug (
204- "Ignoring skip event, could not find test with name {}, suite name{} and class {}" ,
205- testName ,
206- testSuiteName ,
207- testClass );
183+ log .debug ("Ignoring skip event, could not find test {}}" , descriptor );
208184 return ;
209185 }
210186 test .setSkipReason (reason );
211187 }
212188
213189 @ Override
214- public void onTestFailure (
215- String testSuiteName ,
216- Class <?> testClass ,
217- String testName ,
218- @ Nullable Object testQualifier ,
219- @ Nullable String testParameters ,
220- @ Nullable Throwable throwable ) {
221- TestDescriptor descriptor =
222- new TestDescriptor (testSuiteName , testClass , testName , testParameters , testQualifier );
190+ public void onTestFailure (TestKey descriptor , @ Nullable Throwable throwable ) {
223191 TestImpl test = inProgressTests .get (descriptor );
224192 if (test == null ) {
225- log .debug (
226- "Ignoring fail event, could not find test with name {}, suite name{} and class {}" ,
227- testName ,
228- testSuiteName ,
229- testClass );
193+ log .debug ("Ignoring fail event, could not find test {}" , descriptor );
230194 return ;
231195 }
232196 test .setErrorInfo (throwable );
233197 }
234198
235199 @ Override
236- public void onTestFinish (
237- final String testSuiteName ,
238- final Class <?> testClass ,
239- final String testName ,
240- final @ Nullable Object testQualifier ,
241- final @ Nullable String testParameters ) {
242- TestDescriptor descriptor =
243- new TestDescriptor (testSuiteName , testClass , testName , testParameters , testQualifier );
200+ public void onTestFinish (TestKey descriptor ) {
244201 TestImpl test = inProgressTests .remove (descriptor );
245202 if (test == null ) {
246- log .debug (
247- "Ignoring finish event, could not find test with name {}, suite name{} and class {}" ,
248- testName ,
249- testSuiteName ,
250- testClass );
203+ log .debug ("Ignoring finish event, could not find test {}" , descriptor );
251204 return ;
252205 }
253206 test .end (null );
254207 }
255208
256209 @ Override
257210 public void onTestIgnore (
211+ final SuiteKey suiteDescriptor ,
212+ final TestKey testDescriptor ,
258213 final String testSuiteName ,
259214 final String testName ,
260- final @ Nullable Object testQualifier ,
261215 final @ Nullable String testFramework ,
262216 final @ Nullable String testFrameworkVersion ,
263217 final @ Nullable String testParameters ,
@@ -267,9 +221,10 @@ public void onTestIgnore(
267221 final @ Nullable Method testMethod ,
268222 final @ Nullable String reason ) {
269223 onTestStart (
224+ suiteDescriptor ,
225+ testDescriptor ,
270226 testSuiteName ,
271227 testName ,
272- testQualifier ,
273228 testFramework ,
274229 testFrameworkVersion ,
275230 testParameters ,
@@ -278,8 +233,8 @@ public void onTestIgnore(
278233 testMethodName ,
279234 testMethod ,
280235 false );
281- onTestSkip (testSuiteName , testClass , testName , testQualifier , testParameters , reason );
282- onTestFinish (testSuiteName , testClass , testName , testQualifier , testParameters );
236+ onTestSkip (testDescriptor , reason );
237+ onTestFinish (testDescriptor );
283238 }
284239
285240 private static boolean skipTrace (final Class <?> testClass ) {
0 commit comments