Skip to content

Commit

Permalink
GH-5053: avoid log spam for configurations class with legacy settings (
Browse files Browse the repository at this point in the history
  • Loading branch information
aschwarte10 authored Aug 12, 2024
2 parents 59eba18 + bfa6b86 commit 1044c5c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ public static Set<Value> getPropertyValues(Model model, Resource subject, IRI pr
var fallbackObjects = model.filter(subject, fallbackProperty, null).objects();

if (!fallbackObjects.isEmpty() && !preferredObjects.equals(fallbackObjects)) {
logger.warn("Discrepancy between use of the old and new config vocabulary.");
var msg = "Discrepancy between use of the old and new config vocabulary.";
// depending on whether preferred is set, we log on warn or debug
if (preferredObjects.isEmpty()) {
logger.debug(msg);
} else {
logger.warn(msg);
}

if (preferredObjects.containsAll(fallbackObjects)) {
return preferredObjects;
Expand Down Expand Up @@ -235,7 +241,13 @@ public static Optional<Resource> getSubjectByType(Model model, IRI type, IRI leg
private static void logDiscrepancyWarning(Optional<? extends Value> preferred,
Optional<? extends Value> fallback) {
if (!fallback.isEmpty() && !preferred.equals(fallback)) {
logger.warn("Discrepancy between use of the old and new config vocabulary.");
var msg = "Discrepancy between use of the old and new config vocabulary.";
// depending on whether preferred is set, we log on warn or debug
if (preferred.isEmpty()) {
logger.debug(msg);
} else {
logger.warn(msg);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void testGetLiteralValue_no_discrepancy() {
var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(literal("label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -116,7 +117,21 @@ public void testGetLiteralValue_useLegacy_onlyNew() {
System.setProperty("org.eclipse.rdf4j.model.vocabulary.useLegacyConfig", "");

assertThat(result).contains(literal("label"));
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
public void testGetLiteralValue_onlyLegacy() {

var subject = bnode();
var m = new ModelBuilder().subject(subject)
.add(RDFS.COMMENT, "comment")
.build();

var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);

assertThat(result).contains(literal("comment"));
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand Down Expand Up @@ -158,6 +173,7 @@ public void testGetResourceValue_no_discrepancy() {
var result = Configurations.getResourceValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(iri("urn:label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -183,6 +199,7 @@ public void testGetIRIValue_no_discrepancy() {
var result = Configurations.getIRIValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(iri("urn:label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -197,6 +214,7 @@ public void testGetPropertyValues_no_legacy() {
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).hasSize(2);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -213,6 +231,7 @@ public void testGetPropertyValues_no_discrepancy() {
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).hasSize(2);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -229,6 +248,7 @@ public void testGetPropertyValues_useLegacy_no_discrepancy() {
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).hasSize(2);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand Down

0 comments on commit 1044c5c

Please sign in to comment.