Skip to content

Commit

Permalink
Merge pull request #1379 from GIScience/fix-apitests-logging
Browse files Browse the repository at this point in the history
fixes #1379
  • Loading branch information
jlink committed Mar 31, 2023
2 parents a4ed9e5 + 6a2994f commit 0613ab3
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ openrouteservice/Program FilesApache Software FoundationTomcat 7.0webappsopenrou
.recommenders/index/http___download_eclipse_org_recommenders_models_neon_/segments.gen
.idea/
*.iml
*.ipr
*.iws
.DS_Store
nohup.out
.python-version
Expand All @@ -27,11 +29,9 @@ openrouteservice/src/main/resources/ors-config*
docker/elevation_cache
docker/conf

# Ignore ors.run file
*ors.run

cgiar_provider/
graphs/
graphs-*/
target/
.python-version
nohup.out
Expand Down
12 changes: 6 additions & 6 deletions openrouteservice/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ TODO.txt
.classpath
.project
#/WebContent/WEB-INF/ors-config.json
*.iws
*.ipr
cgiar-cache
srtm_38_03.zip
logs/
.attach_*
# jqwik
.jqwik-database

# integration tests
!src/test/resources/logs/TEST_LOGGING.json
graphs-apitests/
ors.log
ors.log

# jqwik
.jqwik-database

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import org.heigit.ors.routing.RoutingProfileManager;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.util.FileSystemUtils;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

@Order(Integer.MIN_VALUE) // Before even the context is created
public class InitializeGraphsOnce implements BeforeAllCallback {
@Order(Integer.MIN_VALUE) // Run before even spring context has been built
public class InitializeGraphsOnce implements BeforeAllCallback, BeforeEachCallback {

private static final Logger LOGGER = Logger.getLogger(InitializeGraphsOnce.class.getName());

Expand All @@ -24,10 +25,24 @@ public class InitializeGraphsOnce implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext extensionContext) {
ExtensionContext.Store store = rootStore(extensionContext);
boolean graphsFolderAlreadyDeleted = store.getOrDefault(GRAPHS_FOLDER_DELETED, Boolean.class, Boolean.FALSE);
deleteGraphsFolderOncePerTestRun(store);
}

@Override
public void beforeEach(ExtensionContext context) {
// Waiting for all graphs being built.
// Do it here - instead of beforeAll - because now the Logging configuration has been correctly set up.
RoutingProfileManager.getInstance();
}

private synchronized static void deleteGraphsFolderOncePerTestRun(ExtensionContext.Store store) {
boolean graphsFolderAlreadyDeleted = store.getOrDefault(GRAPHS_FOLDER_DELETED, Boolean.class, Boolean.FALSE);
boolean ciPropertySet = System.getProperty("CI") != null && System.getProperty("CI").equalsIgnoreCase("true");
boolean deleteGraphsFolder = !graphsFolderAlreadyDeleted && ciPropertySet;

// Necessary to allow api tests, if already other spring boot tests have created profiles
// RoutingProfileManager.destroyInstance();

if (deleteGraphsFolder) {
try {
Path graphsFolder = Paths.get(GRAPHS_FOLDER);
Expand All @@ -39,7 +54,6 @@ public void beforeAll(ExtensionContext extensionContext) {
}
store.put(GRAPHS_FOLDER_DELETED, true);
}
RoutingProfileManager.getInstance(); // Waiting for all graphs being built
}

private static ExtensionContext.Store rootStore(ExtensionContext extensionContext) {
Expand Down
63 changes: 63 additions & 0 deletions openrouteservice/src/test/resources/logs/TEST_LOGGING.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"configuration": {
"status": "error",
"name": "ORSLogger",
"packages": "org.apache.logging.log4j",
"appenders": {
"Console": {
"name": "stdout",
"PatternLayout": {
"pattern": "%d{dd MMM HH:mm:ss} %p [%c{2}] - %m%n"
}
},
"RollingFile": {
"name": "orslogfile",
"fileName": "${sys:ors-log-filepath}/ors.log",
"filePattern": "${sys:ors-log-filepath}/ors.%d{yyyy-MM-dd}.log.gz",
"PatternLayout": {
"pattern": "%d %p [%c{2}] - %m%n"
},
"TimeBasedTriggeringPolicy": { "interval": "1", "modulate": "true" }
}
},
"loggers": {
"logger": [
{
"name": "org.heigit.ors",
"level": "info",
"additivity": "false",
"AppenderRef": [
{
"ref": "orslogfile"
},
{
"ref": "stdout"
}
]
},
{
"name": "org.springframework",
"level": "warn",
"additivity": "false",
"AppenderRef": {
"ref": "stdout"
}
},
{
"name": "org.hibernate",
"level": "warn",
"additivity": "false",
"AppenderRef": {
"ref": "stdout"
}
}
],
"root": {
"level": "info",
"AppenderRef": {
"ref": "stdout"
}
}
}
}
}
2 changes: 1 addition & 1 deletion openrouteservice/src/test/resources/ors-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
},
"logging": {
"enabled": true,
"level_file": "PRODUCTION_LOGGING.json",
"level_file": "TEST_LOGGING.json",
"location": "./logs",
"stdout": true
},
Expand Down

0 comments on commit 0613ab3

Please sign in to comment.