aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-09-13 14:57:12 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-09-13 16:02:02 +0200
commita1dda7cfb1cc99bfc64a0433a760d97955c02ae8 (patch)
tree96031b126a6628e29fc32a8b09ef31e3353f0272 /sonar-core
parent17e74080cfbf2a105b2893f31730bbe9fff8af5e (diff)
downloadsonarqube-a1dda7cfb1cc99bfc64a0433a760d97955c02ae8.tar.gz
sonarqube-a1dda7cfb1cc99bfc64a0433a760d97955c02ae8.zip
Improve stability of ProgressLoggerTest
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java b/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java
index d7e93c41c98..57bb0de02d5 100644
--- a/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java
@@ -19,33 +19,37 @@
*/
package org.sonar.core.util;
+import com.google.common.util.concurrent.Uninterruptibles;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
+import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.api.utils.log.Loggers;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.startsWith;
-import static org.mockito.Mockito.verify;
public class ProgressLoggerTest {
- @Test(timeout = 1000L)
+ @Rule
+ public LogTester logTester = new LogTester();
+
+ @Test(timeout = 5_000L)
public void log_at_fixed_intervals() throws Exception {
- Logger logger = mock(Logger.class);
AtomicLong counter = new AtomicLong(42L);
- ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, logger);
+ ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, Loggers.get(getClass()));
progress.setPeriodMs(1L);
progress.start();
- Thread.sleep(80L);
+ while (!hasInfoLog("42 rows processed")) {
+ Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MILLISECONDS);
+ }
progress.stop();
- verify(logger, atLeast(1)).info(startsWith("42 rows processed"));
// ability to manual log, generally final status
counter.incrementAndGet();
progress.log();
- verify(logger).info(startsWith("43 rows processed"));
+ assertThat(hasInfoLog("43 rows processed")).isTrue();
}
@Test
@@ -61,6 +65,9 @@ public class ProgressLoggerTest {
progress.setPluralLabel("issues");
assertThat(progress.getPeriodMs()).isEqualTo(10L);
assertThat(progress.getPluralLabel()).isEqualTo("issues");
+ }
+ private boolean hasInfoLog(String expectedLog) {
+ return logTester.logs(LoggerLevel.INFO).stream().filter(s -> s.startsWith(expectedLog)).findFirst().isPresent();
}
}