From 00f50c8aed0f1110a19b9a46ca5440fd24a860e0 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Wed, 6 Dec 2023 12:34:31 +0100 Subject: [PATCH] fix: only restrict set of checks when executing them [DHIS2-16256] (#15840) * fix: only restrict set of checks when executing them [DHIS2-16256] * test: show that slow tests are included in summary [DHIS2-16256] --- .../DefaultDataIntegrityService.java | 20 ++++++++++--------- .../AbstractDataIntegrityIntegrationTest.java | 12 ++++++----- .../DataIntegrityChecksControllerTest.java | 4 ++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java index d52e878348ef..b4168ce3b3cd 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java @@ -853,7 +853,7 @@ public Collection getDataIntegrityChecks(Set checks) ensureConfigurationsAreLoaded(); return checks.isEmpty() ? unmodifiableCollection(checksByName.values()) - : expandChecks(checks).stream().map(checksByName::get).collect(toList()); + : expandChecks(checks, false).stream().map(checksByName::get).collect(toList()); } @Nonnull @@ -868,7 +868,7 @@ public Map getSummaries(@Nonnull Set check public void runSummaryChecks(@Nonnull Set checks, JobProgress progress) { runDataIntegrityChecks( "Data Integrity summary checks", - expandChecks(checks), + expandChecks(checks, true), progress, summaryCache, runningSummaryChecks, @@ -890,7 +890,7 @@ public Map getDetails(@Nonnull Set checks, public void runDetailsChecks(@Nonnull Set checks, JobProgress progress) { runDataIntegrityChecks( "Data Integrity details checks", - expandChecks(checks), + expandChecks(checks, true), progress, detailsCache, runningDetailsChecks, @@ -907,7 +907,7 @@ private static String errorMessage(DataIntegrityCheck check, RuntimeException ex } private Map getCached(Set checks, long timeout, Cache cache) { - Set names = expandChecks(checks); + Set names = expandChecks(checks, false); long giveUpTime = currentTimeMillis() + timeout; Map resByName = new LinkedHashMap<>(); boolean retry = false; @@ -975,11 +975,11 @@ private void runDataIntegrityChecks( } } - private Set expandChecks(Set names) { + private Set expandChecks(Set names, boolean restricted) { ensureConfigurationsAreLoaded(); if (CollectionUtils.isEmpty(names)) { - return getDefaultChecks(); + return getDefaultChecks(restricted); } Set expanded = new LinkedHashSet<>(); @@ -1008,13 +1008,15 @@ private Set expandChecks(Set names) { return expanded; } - private Set getDefaultChecks() { + private Set getDefaultChecks(boolean restricted) { ensureConfigurationsAreLoaded(); + Predicate filter = + restricted ? not(DataIntegrityCheck::isSlow) : check -> true; return checksByName.values().stream() - .filter(not(DataIntegrityCheck::isSlow)) + .filter(filter) .map(DataIntegrityCheck::getName) - .collect(Collectors.toUnmodifiableSet()); + .collect(toUnmodifiableSet()); } private void ensureConfigurationsAreLoaded() { diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/AbstractDataIntegrityIntegrationTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/AbstractDataIntegrityIntegrationTest.java index 192430d73a3b..e8e08e4a8f75 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/AbstractDataIntegrityIntegrationTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/AbstractDataIntegrityIntegrationTest.java @@ -36,6 +36,7 @@ import org.hisp.dhis.web.HttpStatus; import org.hisp.dhis.webapi.DhisControllerIntegrationTest; import org.hisp.dhis.webapi.json.domain.JsonDataIntegrityDetails; +import org.hisp.dhis.webapi.json.domain.JsonDataIntegrityDetails.JsonDataIntegrityIssue; import org.hisp.dhis.webapi.json.domain.JsonDataIntegritySummary; import org.hisp.dhis.webapi.json.domain.JsonWebMessage; import org.springframework.beans.factory.annotation.Autowired; @@ -89,7 +90,7 @@ void checkDataIntegritySummary( } } - private Boolean hasComments(JsonList issues) { + private Boolean hasComments(JsonList issues) { return issues.stream() .map(issue -> issue.has("comment")) .reduce(Boolean.FALSE, Boolean::logicalOr); @@ -104,7 +105,7 @@ void checkDataIntegrityDetailsIssues( postDetails(check); JsonDataIntegrityDetails details = getDetails(check); - JsonList issues = details.getIssues(); + JsonList issues = details.getIssues(); assertTrue(issues.exists()); assertEquals(1, issues.size()); @@ -137,13 +138,14 @@ void checkDataIntegrityDetailsIssues( postDetails(check); JsonDataIntegrityDetails details = getDetails(check); - JsonList issues = details.getIssues(); + JsonList issues = details.getIssues(); assertTrue(issues.exists()); assertEquals(expectedDetailsUnits.size(), issues.size()); /* Always check the UIDs */ - Set issueUIDs = issues.stream().map(issue -> issue.getId()).collect(Collectors.toSet()); + Set issueUIDs = + issues.stream().map(JsonDataIntegrityIssue::getId).collect(Collectors.toSet()); assertEquals(issueUIDs, expectedDetailsUnits); /* @@ -152,7 +154,7 @@ void checkDataIntegrityDetailsIssues( */ if (!expectedDetailsNames.isEmpty()) { Set detailsNames = - issues.stream().map(issue -> issue.getName()).collect(Collectors.toSet()); + issues.stream().map(JsonDataIntegrityIssue::getName).collect(Collectors.toSet()); assertEquals(expectedDetailsNames, detailsNames); } /* This can be empty if comments do not exist in the JSON response. */ diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityChecksControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityChecksControllerTest.java index 9e0187c82999..e4abaa870066 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityChecksControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityChecksControllerTest.java @@ -59,6 +59,10 @@ void testGetAvailableChecks() { for (DataIntegrityCheckType type : DataIntegrityCheckType.values()) { assertCheckExists(type.getName(), checks); } + checks.stream() + .filter(JsonDataIntegrityCheck::getIsSlow) + .findFirst() + .orElseThrow(() -> new AssertionError("There should be slow tests")); } @Test