aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-12-15 14:22:44 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-12-16 14:35:28 +0100
commite1e54db29f0cc1f9d54adec00e7a2ab092102a12 (patch)
treebc2e5f51006e0770fe4276cf6ed3bc7d54dfbb5f
parentc3e4372a9d58f0a339cf33e7ec81447b0b9cdd25 (diff)
downloadsonarqube-e1e54db29f0cc1f9d54adec00e7a2ab092102a12.tar.gz
sonarqube-e1e54db29f0cc1f9d54adec00e7a2ab092102a12.zip
improving stability of DatabaseMigrationImplConcurrentAccessTest
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java34
1 files changed, 17 insertions, 17 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java
index c9d151576cf..2f7965a7334 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.platform.db.migration;
+import com.google.common.base.Throwables;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -53,10 +54,24 @@ public class DatabaseMigrationImplConcurrentAccessTest {
command.run();
}
};
+ private AtomicInteger triggerCount = new AtomicInteger();
+ private MigrationEngine incrementingMigrationEngine = new MigrationEngine() {
+ @Override
+ public void execute() {
+ // need execute to consume some time to avoid UT to fail because it ran too fast and threads never executed concurrently
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ Throwables.propagate(e);
+ }
+ triggerCount.incrementAndGet();
+ }
+ };
private MutableDatabaseMigrationState migrationState = mock(MutableDatabaseMigrationState.class);
private RubyBridge rubyBridge = mock(RubyBridge.class);
private Platform platform = mock(Platform.class);
private RubyRailsRoutes railsRoutes = mock(RubyRailsRoutes.class);
+ private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, rubyBridge, incrementingMigrationEngine, platform);
@After
public void tearDown() {
@@ -65,19 +80,10 @@ public class DatabaseMigrationImplConcurrentAccessTest {
@Test
public void two_concurrent_calls_to_startit_call_migration_engine_only_once() throws Exception {
- AtomicInteger triggerCount = new AtomicInteger();
- MigrationEngine incrementingMigrationEngine = new MigrationEngine() {
- @Override
- public void execute() {
- triggerCount.incrementAndGet();
- }
- };
when(rubyBridge.railsRoutes()).thenReturn(railsRoutes);
- DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, rubyBridge, incrementingMigrationEngine, platform);
-
- pool.submit(new CallStartit(underTest));
- pool.submit(new CallStartit(underTest));
+ pool.submit(new CallStartit());
+ pool.submit(new CallStartit());
pool.awaitTermination(2, TimeUnit.SECONDS);
@@ -85,12 +91,6 @@ public class DatabaseMigrationImplConcurrentAccessTest {
}
private class CallStartit implements Runnable {
- private final DatabaseMigrationImpl underTest;
-
- private CallStartit(DatabaseMigrationImpl underTest) {
- this.underTest = underTest;
- }
-
@Override
public void run() {
latch.countDown();