Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only restrict set of checks when executing them [DHIS2-16256] #15840

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public Collection<DataIntegrityCheck> getDataIntegrityChecks(Set<String> checks)
ensureConfigurationsAreLoaded();
return checks.isEmpty()
? unmodifiableCollection(checksByName.values())
: expandChecks(checks).stream().map(checksByName::get).toList();
: expandChecks(checks, false).stream().map(checksByName::get).toList();
}

@Nonnull
Expand All @@ -853,7 +853,7 @@ public Map<String, DataIntegritySummary> getSummaries(@Nonnull Set<String> check
public void runSummaryChecks(@Nonnull Set<String> checks, JobProgress progress) {
runDataIntegrityChecks(
"Data Integrity summary checks",
expandChecks(checks),
expandChecks(checks, true),
progress,
summaryCache,
runningSummaryChecks,
Expand All @@ -875,7 +875,7 @@ public Map<String, DataIntegrityDetails> getDetails(@Nonnull Set<String> checks,
public void runDetailsChecks(@Nonnull Set<String> checks, JobProgress progress) {
runDataIntegrityChecks(
"Data Integrity details checks",
expandChecks(checks),
expandChecks(checks, true),
progress,
detailsCache,
runningDetailsChecks,
Expand All @@ -892,7 +892,7 @@ private static String errorMessage(DataIntegrityCheck check, RuntimeException ex
}

private <T> Map<String, T> getCached(Set<String> checks, long timeout, Cache<T> cache) {
Set<String> names = expandChecks(checks);
Set<String> names = expandChecks(checks, false);
long giveUpTime = currentTimeMillis() + timeout;
Map<String, T> resByName = new LinkedHashMap<>();
boolean retry = false;
Expand Down Expand Up @@ -960,11 +960,11 @@ private <T> void runDataIntegrityChecks(
}
}

private Set<String> expandChecks(Set<String> names) {
private Set<String> expandChecks(Set<String> names, boolean restricted) {
ensureConfigurationsAreLoaded();

if (CollectionUtils.isEmpty(names)) {
return getDefaultChecks();
return getDefaultChecks(restricted);
}
Set<String> expanded = new LinkedHashSet<>();

Expand Down Expand Up @@ -993,13 +993,15 @@ private Set<String> expandChecks(Set<String> names) {
return expanded;
}

private Set<String> getDefaultChecks() {
private Set<String> getDefaultChecks(boolean restricted) {
ensureConfigurationsAreLoaded();

Predicate<DataIntegrityCheck> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.hisp.dhis.dataintegrity.DataIntegrityCheckType;
import org.hisp.dhis.jsontree.JsonMap;
import org.hisp.dhis.jsontree.JsonObject;
import org.hisp.dhis.web.HttpStatus;
import org.hisp.dhis.webapi.controller.DataIntegrityController;
Expand All @@ -48,6 +49,7 @@
* @author Jan Bernitt
*/
class DataIntegritySummaryControllerTest extends AbstractDataIntegrityIntegrationTest {

@Test
void testLegacyChecksHaveSummary() {
for (DataIntegrityCheckType type : DataIntegrityCheckType.values()) {
Expand All @@ -56,6 +58,9 @@ void testLegacyChecksHaveSummary() {
JsonDataIntegritySummary summary = getSummary(check);
assertTrue(summary.getCount() >= 0, "summary threw an exception");
}
JsonMap<JsonDataIntegritySummary> checksByName =
GET("/dataIntegrity/summary?timeout=1000").content().asMap(JsonDataIntegritySummary.class);
assertEquals(31, checksByName.size());
jbee marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
Expand Down
Loading