aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2012-12-03 15:32:49 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2012-12-03 16:08:20 +0100
commit9e6d221047e1a2d4076e285da63993ead0920884 (patch)
tree3374114562043bbf86169709548a51d85c05e2d3 /sonar-core
parent085f48615e1424da08239bb76c331a0b7a0bf90f (diff)
downloadsonarqube-9e6d221047e1a2d4076e285da63993ead0920884.tar.gz
sonarqube-9e6d221047e1a2d4076e285da63993ead0920884.zip
SONAR-3306 Improve unit test to fix issue on it-sonar-persistence tests
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java31
1 files changed, 28 insertions, 3 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java
index 781d5c95997..6458060cb3a 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java
@@ -27,6 +27,9 @@ import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
@@ -234,12 +237,34 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase {
}
private boolean isRecent(Date date) {
- Date now = new Date();
- Date futur = DateUtils.addDays(now, 1);
- Date past = DateUtils.addDays(now, -1);
+ Date futur = DateUtils.addMinutes(now(), 1);
+ Date past = DateUtils.addDays(now(), -1);
return date.after(past) && date.before(futur);
}
+ private Date now() {
+ Connection connection = null;
+ PreparedStatement statement = null;
+ ResultSet rs = null;
+ try {
+ connection = getConnection();
+ rs = null;
+ statement = connection.prepareStatement("select current_timestamp");
+ rs = statement.executeQuery();
+ if (rs.next()) {
+ return new Date();
+ }
+ return null;
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ DatabaseUtils.closeQuietly(rs);
+ DatabaseUtils.closeQuietly(statement);
+ DatabaseUtils.closeQuietly(connection);
+ }
+ }
+
private static class Runner extends Thread {
SemaphoreDao dao;
AtomicInteger locks;