KEYCLOAK-10792 MigrationTest fails in pipeline: fix log file checker to start from the right position after server restart
This commit is contained in:
parent
9fb9197b53
commit
71eed3af06
4 changed files with 31 additions and 19 deletions
|
@ -344,6 +344,19 @@ public class AuthServerTestEnricher {
|
|||
} catch (Exception e) {
|
||||
// It is expected that server startup fails with migration-mode-manual
|
||||
if (e instanceof LifecycleException && handleManualMigration()) {
|
||||
log.info("Set log file checker to end of file.");
|
||||
try {
|
||||
// this will mitigate possible issues in manual server update tests
|
||||
// when the auth server started with not updated DB
|
||||
// e.g. Caused by: org.keycloak.ServerStartupError: Database not up-to-date, please migrate database with
|
||||
if (suiteContext.getServerLogChecker() == null) {
|
||||
setServerLogChecker();
|
||||
}
|
||||
suiteContext.getServerLogChecker()
|
||||
.updateLastCheckedPositionsOfAllFilesToEndOfFile();
|
||||
} catch (IOException ioe) {
|
||||
log.warn("Server log checker failed to update position:", ioe);
|
||||
}
|
||||
log.info("Starting server again after manual DB migration was finished");
|
||||
startContainerEvent.fire(new StartContainer(suiteContext.getAuthServerInfo().getArquillianContainer()));
|
||||
return;
|
||||
|
@ -408,18 +421,24 @@ public class AuthServerTestEnricher {
|
|||
}
|
||||
}
|
||||
|
||||
private void setServerLogChecker() throws IOException {
|
||||
String jbossHomePath = suiteContext.getAuthServerInfo().getProperties().get("jbossHome");
|
||||
suiteContext.setServerLogChecker(LogChecker.getJBossServerLogsChecker(jbossHomePath));
|
||||
}
|
||||
|
||||
public void checkServerLogs(@Observes(precedence = -1) BeforeSuite event) throws IOException, InterruptedException {
|
||||
if (! suiteContext.getAuthServerInfo().isJBossBased()) {
|
||||
suiteContext.setServerLogChecker(new TextFileChecker()); // checks nothing
|
||||
return;
|
||||
}
|
||||
|
||||
boolean checkLog = Boolean.parseBoolean(System.getProperty("auth.server.log.check", "true"));
|
||||
String jbossHomePath = suiteContext.getAuthServerInfo().getProperties().get("jbossHome");
|
||||
if (checkLog) {
|
||||
LogChecker.getJBossServerLogsChecker(true, jbossHomePath).checkFiles(AuthServerTestEnricher::failOnRecognizedErrorInLog);
|
||||
if (suiteContext.getServerLogChecker() == null) {
|
||||
setServerLogChecker();
|
||||
}
|
||||
boolean checkLog = Boolean.parseBoolean(System.getProperty("auth.server.log.check", "true"));
|
||||
if (checkLog) {
|
||||
suiteContext.getServerLogChecker()
|
||||
.checkFiles(true, AuthServerTestEnricher::failOnRecognizedErrorInLog);
|
||||
}
|
||||
suiteContext.setServerLogChecker(LogChecker.getJBossServerLogsChecker(false, jbossHomePath));
|
||||
}
|
||||
|
||||
public void initializeTestContext(@Observes(precedence = 2) BeforeClass event) {
|
||||
|
@ -522,7 +541,7 @@ public class AuthServerTestEnricher {
|
|||
|
||||
public void afterTest(@Observes(precedence = -1) After event) throws IOException {
|
||||
if (event.getTestMethod().getAnnotation(UncaughtServerErrorExpected.class) == null) {
|
||||
suiteContext.getServerLogChecker().checkFiles(this::checkForNoUnexpectedUncaughtError);
|
||||
suiteContext.getServerLogChecker().checkFiles(false, this::checkForNoUnexpectedUncaughtError);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@ public class LogChecker {
|
|||
}
|
||||
}
|
||||
|
||||
public static TextFileChecker getJBossServerLogsChecker(boolean verbose, String jbossHome) throws IOException {
|
||||
public static TextFileChecker getJBossServerLogsChecker(String jbossHome) throws IOException {
|
||||
String[] pathsToCheck = getJBossServerLogFiles(jbossHome);
|
||||
Path[] pathsArray = Arrays.stream(pathsToCheck).map(File::new).map(File::toPath).toArray(Path[]::new);
|
||||
|
||||
return new TextFileChecker(verbose, pathsArray);
|
||||
return new TextFileChecker(pathsArray);
|
||||
}
|
||||
|
||||
}
|
|
@ -41,15 +41,8 @@ public class TextFileChecker {
|
|||
|
||||
private final Path[] paths;
|
||||
|
||||
private final boolean verbose;
|
||||
|
||||
public TextFileChecker(boolean verbose, Path... paths) {
|
||||
this.verbose = verbose;
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
public TextFileChecker(Path... paths) {
|
||||
this(false, paths);
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
private void updateLastCheckedPositionsOfAllFilesToEndOfFile(Path path) throws IOException {
|
||||
|
@ -60,7 +53,7 @@ public class TextFileChecker {
|
|||
}
|
||||
}
|
||||
|
||||
public void checkFiles(Consumer<Stream<String>> lineChecker) throws IOException {
|
||||
public void checkFiles(boolean verbose, Consumer<Stream<String>> lineChecker) throws IOException {
|
||||
for (Path path : paths) {
|
||||
log.logf(verbose ? Level.INFO : Level.DEBUG, "Checking server log: '%s'", path.toAbsolutePath());
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public class TextFileCheckerTest {
|
|||
|
||||
public void assertCheckedOutputIs(String... expectedOutput) throws IOException {
|
||||
List<String> target = new LinkedList<>();
|
||||
tfc.checkFiles(collector(target));
|
||||
tfc.checkFiles(false, collector(target));
|
||||
Assert.assertThat(target,
|
||||
expectedOutput == null || expectedOutput.length == 0
|
||||
? Matchers.empty()
|
||||
|
|
Loading…
Reference in a new issue