Allow ignoring patterns in LogChecker

This commit is contained in:
Stian Thorgersen 2016-03-10 07:17:06 +01:00 committed by Bill Burke
parent dd3e6b29bf
commit 55e9f2e21b

View file

@ -1,9 +1,10 @@
package org.keycloak.testsuite.util; package org.keycloak.testsuite.util;
import org.apache.commons.io.FileUtils;
import org.jboss.logging.Logger;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.jboss.logging.Logger;
/** /**
* *
@ -14,21 +15,31 @@ public class LogChecker {
private static final Logger log = Logger.getLogger(LogChecker.class); private static final Logger log = Logger.getLogger(LogChecker.class);
private static final String[] IGNORED = new String[] { ".*Jetty ALPN support not found.*" };
public static void checkServerLog(File logFile) throws IOException { public static void checkServerLog(File logFile) throws IOException {
log.info(String.format("Checking server log: '%s'", logFile.getAbsolutePath())); log.info(String.format("Checking server log: '%s'", logFile.getAbsolutePath()));
String logContent = FileUtils.readFileToString(logFile); String[] logContent = FileUtils.readFileToString(logFile).split("\n");
boolean containsError
= logContent.contains("ERROR")
|| logContent.contains("SEVERE")
|| logContent.contains("Exception ");
for (String log : logContent) {
boolean containsError = log.contains("ERROR") || log.contains("SEVERE") || log.contains("Exception ");
//There is expected string "Exception" in server log: Adding provider //There is expected string "Exception" in server log: Adding provider
//singleton org.keycloak.services.resources.ModelExceptionMapper //singleton org.keycloak.services.resources.ModelExceptionMapper
if (containsError) { if (containsError) {
throw new RuntimeException(String.format("Server log file contains ERROR: '%s'", logFile.getPath())); boolean ignore = false;
for (String i : IGNORED) {
if (log.matches(i)) {
ignore = true;
break;
} }
} }
if (!ignore) {
throw new RuntimeException(String.format("Server log file contains ERROR: '%s'", log));
}
}
}
}
public static void checkJBossServerLog(String jbossHome) throws IOException { public static void checkJBossServerLog(String jbossHome) throws IOException {
checkServerLog(new File(jbossHome + "/standalone/log/server.log")); checkServerLog(new File(jbossHome + "/standalone/log/server.log"));