aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java32
2 files changed, 33 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java b/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java
index 288881f9fac..4176925f504 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java
@@ -39,7 +39,7 @@ public class SemaphoreDao {
public boolean acquire(String name, int maxDurationInSeconds) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Semaphore name must not be empty");
- Preconditions.checkArgument(maxDurationInSeconds > 0, "Semaphore max duration must be positive");
+ Preconditions.checkArgument(maxDurationInSeconds > 0, "Semaphore max duration must be positive: " + maxDurationInSeconds);
SqlSession session = mybatis.openSession();
try {
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 6abc912b896..5efd621aa30 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
@@ -20,7 +20,9 @@
package org.sonar.core.persistence;
import org.apache.commons.lang.time.DateUtils;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -35,6 +37,36 @@ import static org.fest.assertions.Assertions.assertThat;
public class SemaphoreDaoTest extends AbstractDaoTestCase {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void should_fail_to_acquire_if_blank_semaphore_name() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Semaphore name must not be empty");
+
+ SemaphoreDao dao = new SemaphoreDao(getMyBatis());
+ dao.acquire(null, 5000);
+ }
+
+ @Test
+ public void should_fail_to_acquire_if_negative_timeout() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Semaphore max duration must be positive: -5000");
+
+ SemaphoreDao dao = new SemaphoreDao(getMyBatis());
+ dao.acquire("foo", -5000);
+ }
+
+ @Test
+ public void should_fail_to_release_if_blank_semaphore_name() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Semaphore name must not be empty");
+
+ SemaphoreDao dao = new SemaphoreDao(getMyBatis());
+ dao.release(null);
+ }
+
@Test
public void create_and_acquire_semaphore() throws Exception {
SemaphoreDao dao = new SemaphoreDao(getMyBatis());