@@ -54,6 +54,7 @@ public class ConfigurationApiImpl implements ConfigurationApi {
5454 private static final String CHANGED_FILES_URI = "ci/tests/diffs" ;
5555 private static final String FLAKY_TESTS_URI = "ci/libraries/tests/flaky" ;
5656 private static final String KNOWN_TESTS_URI = "ci/libraries/tests" ;
57+ private static final String TEST_MANAGEMENT_TESTS_URI = "test/libraries/test-management/tests" ;
5758
5859 private final BackendApi backendApi ;
5960 private final CiVisibilityMetricCollector metricCollector ;
@@ -63,6 +64,7 @@ public class ConfigurationApiImpl implements ConfigurationApi {
6364 private final JsonAdapter <EnvelopeDto <CiVisibilitySettings >> settingsResponseAdapter ;
6465 private final JsonAdapter <MultiEnvelopeDto <TestIdentifierJson >> testIdentifiersResponseAdapter ;
6566 private final JsonAdapter <EnvelopeDto <KnownTestsDto >> testFullNamesResponseAdapter ;
67+ private final JsonAdapter <EnvelopeDto <TestManagementTestsDto >> testManagementTestsResponseAdapter ;
6668 private final JsonAdapter <EnvelopeDto <ChangedFiles >> changedFilesResponseAdapter ;
6769
6870 public ConfigurationApiImpl (BackendApi backendApi , CiVisibilityMetricCollector metricCollector ) {
@@ -105,6 +107,11 @@ public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector m
105107 ConfigurationApiImpl .class , EnvelopeDto .class , KnownTestsDto .class );
106108 testFullNamesResponseAdapter = moshi .adapter (testFullNamesResponseType );
107109
110+ ParameterizedType testManagementTestsResponseType =
111+ Types .newParameterizedTypeWithOwner (
112+ ConfigurationApiImpl .class , EnvelopeDto .class , TestManagementTestsDto .class );
113+ testManagementTestsResponseAdapter = moshi .adapter (testManagementTestsResponseType );
114+
108115 ParameterizedType changedFilesResponseAdapterType =
109116 Types .newParameterizedTypeWithOwner (
110117 ConfigurationApiImpl .class , EnvelopeDto .class , ChangedFiles .class );
@@ -309,6 +316,90 @@ private Map<String, Collection<TestIdentifier>> parseTestIdentifiers(KnownTestsD
309316 : null ;
310317 }
311318
319+ @ Override
320+ public Map <String , Map <String , Collection <TestIdentifier >>> getTestManagementTestsByModule (
321+ TracerEnvironment tracerEnvironment ) throws IOException {
322+ OkHttpUtils .CustomListener telemetryListener =
323+ new TelemetryListener .Builder (metricCollector )
324+ .requestCount (CiVisibilityCountMetric .TEST_MANAGEMENT_TESTS_DETECTION_REQUEST )
325+ .requestErrors (CiVisibilityCountMetric .TEST_MANAGEMENT_TESTS_DETECTION_REQUEST_ERRORS )
326+ .requestDuration (CiVisibilityDistributionMetric .TEST_MANAGEMENT_TESTS_REQUEST_MS )
327+ .responseBytes (CiVisibilityDistributionMetric .TEST_MANAGEMENT_TESTS_RESPONSE_BYTES )
328+ .build ();
329+
330+ String uuid = uuidGenerator .get ();
331+ EnvelopeDto <TracerEnvironment > request =
332+ new EnvelopeDto <>(new DataDto <>(uuid , "ci_app_libraries_tests_request" , tracerEnvironment ));
333+ String json = requestAdapter .toJson (request );
334+ RequestBody requestBody = RequestBody .create (JSON , json );
335+ TestManagementTestsDto testManagementTestsDto =
336+ backendApi .post (
337+ TEST_MANAGEMENT_TESTS_URI ,
338+ requestBody ,
339+ is ->
340+ testManagementTestsResponseAdapter .fromJson (Okio .buffer (Okio .source (is )))
341+ .data
342+ .attributes ,
343+ telemetryListener ,
344+ false );
345+
346+ return parseTestManagementTests (testManagementTestsDto );
347+ }
348+
349+ private Map <String , Map <String , Collection <TestIdentifier >>> parseTestManagementTests (
350+ TestManagementTestsDto testsManagementTestsDto ) {
351+ int testManagementTestsCount = 0 ;
352+
353+ Map <String , Collection <TestIdentifier >> quarantinedTestsByModule = new HashMap <>();
354+ Map <String , Collection <TestIdentifier >> disabledTestsByModule = new HashMap <>();
355+ Map <String , Collection <TestIdentifier >> attemptToFixTestsByModule = new HashMap <>();
356+
357+ for (Map .Entry <String , TestManagementTestsDto .Suites > e :
358+ testsManagementTestsDto .getModules ().entrySet ()) {
359+ String moduleName = e .getKey ();
360+ Map <String , TestManagementTestsDto .Tests > testsBySuiteName = e .getValue ().getSuites ();
361+
362+ for (Map .Entry <String , TestManagementTestsDto .Tests > se : testsBySuiteName .entrySet ()) {
363+ String suiteName = se .getKey ();
364+ Map <String , TestManagementTestsDto .Properties > tests = se .getValue ().getTests ();
365+
366+ testManagementTestsCount += tests .size ();
367+
368+ for (Map .Entry <String , TestManagementTestsDto .Properties > te : tests .entrySet ()) {
369+ String testName = te .getKey ();
370+ TestManagementTestsDto .Properties properties = te .getValue ();
371+ if (properties .isQuarantined ()) {
372+ quarantinedTestsByModule
373+ .computeIfAbsent (moduleName , k -> new HashSet <>())
374+ .add (new TestIdentifier (suiteName , testName , null ));
375+ }
376+ if (properties .isDisabled ()) {
377+ disabledTestsByModule
378+ .computeIfAbsent (moduleName , k -> new HashSet <>())
379+ .add (new TestIdentifier (suiteName , testName , null ));
380+ }
381+ if (properties .isAttemptToFix ()) {
382+ attemptToFixTestsByModule
383+ .computeIfAbsent (moduleName , k -> new HashSet <>())
384+ .add (new TestIdentifier (suiteName , testName , null ));
385+ }
386+ }
387+ }
388+ }
389+
390+ Map <String , Map <String , Collection <TestIdentifier >>> testsByTypeByModule = new HashMap <>();
391+ testsByTypeByModule .put ("quarantined" , quarantinedTestsByModule );
392+ testsByTypeByModule .put ("disabled" , disabledTestsByModule );
393+ testsByTypeByModule .put ("attempt_to_fix" , attemptToFixTestsByModule );
394+
395+ LOGGER .debug ("Received {} test management tests in total" , testManagementTestsCount );
396+ metricCollector .add (
397+ CiVisibilityDistributionMetric .TEST_MANAGEMENT_TESTS_RESPONSE_TESTS ,
398+ testManagementTestsCount );
399+
400+ return testsByTypeByModule ;
401+ }
402+
312403 @ Override
313404 public ChangedFiles getChangedFiles (TracerEnvironment tracerEnvironment ) throws IOException {
314405 OkHttpUtils .CustomListener telemetryListener =
@@ -427,4 +518,60 @@ private KnownTestsDto(Map<String, Map<String, List<String>>> tests) {
427518 this .tests = tests ;
428519 }
429520 }
521+
522+ private static final class TestManagementTestsDto {
523+ private static final class Properties {
524+ private final Map <String , Boolean > properties ;
525+
526+ private Properties (Map <String , Boolean > properties ) {
527+ this .properties = properties ;
528+ }
529+
530+ public Boolean isQuarantined () {
531+ return properties != null ? properties .getOrDefault ("quarantined" , false ) : false ;
532+ }
533+
534+ public Boolean isDisabled () {
535+ return properties != null ? properties .getOrDefault ("disabled" , false ) : false ;
536+ }
537+
538+ public Boolean isAttemptToFix () {
539+ return properties != null ? properties .getOrDefault ("attempt_to_fix" , false ) : false ;
540+ }
541+ }
542+
543+ private static final class Tests {
544+ private final Map <String , Properties > tests ;
545+
546+ private Tests (Map <String , Properties > tests ) {
547+ this .tests = tests ;
548+ }
549+
550+ public Map <String , Properties > getTests () {
551+ return tests != null ? tests : Collections .emptyMap ();
552+ }
553+ }
554+
555+ private static final class Suites {
556+ private final Map <String , Tests > suites ;
557+
558+ private Suites (Map <String , Tests > suites ) {
559+ this .suites = suites ;
560+ }
561+
562+ public Map <String , Tests > getSuites () {
563+ return suites != null ? suites : Collections .emptyMap ();
564+ }
565+ }
566+
567+ private final Map <String , Suites > modules ;
568+
569+ private TestManagementTestsDto (Map <String , Suites > modules ) {
570+ this .modules = modules ;
571+ }
572+
573+ public Map <String , Suites > getModules () {
574+ return modules != null ? modules : Collections .emptyMap ();
575+ }
576+ }
430577}
0 commit comments