diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-10-15 14:20:45 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-10-15 17:35:14 +0200 |
commit | 201a6d91b04852dc07900a95d31c3b60c8341734 (patch) | |
tree | 41baed23a30891aa31b6ed46b2209720c2887ac5 /sonar-batch | |
parent | 7a7bc0c694bd40711a83751487e4e8479b49b33b (diff) | |
download | sonarqube-201a6d91b04852dc07900a95d31c3b60c8341734.tar.gz sonarqube-201a6d91b04852dc07900a95d31c3b60c8341734.zip |
Fix test with asynchronous logging
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java index 186c15c8931..97567ccdfab 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java @@ -20,14 +20,17 @@ package org.sonar.batch.mediumtest.log; import com.google.common.collect.ImmutableMap; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.AfterClass; @@ -40,7 +43,6 @@ import org.junit.rules.TemporaryFolder; import org.sonar.batch.bootstrapper.LogOutput; import org.sonar.batch.mediumtest.BatchMediumTester; import org.sonar.xoo.XooPlugin; - import static org.assertj.core.api.Assertions.assertThat; public class LogListenerTest { @@ -87,7 +89,8 @@ public class LogListenerTest { public void prepare() throws IOException { System.setOut(new PrintStream(stdOutTarget)); System.setErr(new PrintStream(stdErrTarget)); - logOutput = new LinkedList<>(); + // logger from the batch might write to it asynchronously + logOutput = Collections.synchronizedList(new LinkedList<LogEvent>()); tester.start(); baseDir = temp.getRoot(); @@ -139,8 +142,11 @@ public class LogListenerTest { assertNoStdOutput(); assertThat(logOutput).isNotEmpty(); - for (LogEvent e : logOutput) { - savedStdOut.println("[captured]" + e.level + " " + e.msg); + + synchronized (logOutput) { + for (LogEvent e : logOutput) { + savedStdOut.println("[captured]" + e.level + " " + e.msg); + } } } @@ -160,9 +166,11 @@ public class LogListenerTest { assertNoStdOutput(); - for (LogEvent e : logOutput) { - assertMsgClean(e.msg); - savedStdOut.println("[captured]" + e.level + " " + e.msg); + synchronized (logOutput) { + for (LogEvent e : logOutput) { + assertMsgClean(e.msg); + savedStdOut.println("[captured]" + e.level + " " + e.msg); + } } } |