From: Sébastien Lesaint Date: Mon, 16 Sep 2019 09:23:58 +0000 (+0200) Subject: SONAR-12398 fix too long lock name for Portfolio Refresh X-Git-Tag: 7.9.2~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a37df9f33b3b14a79b281d61951e194b67198e23;p=sonarqube.git SONAR-12398 fix too long lock name for Portfolio Refresh which prevented the whole feature to actually work --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalPropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalPropertiesDao.java index 8d2dfadac25..33ea63fb295 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalPropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalPropertiesDao.java @@ -46,7 +46,7 @@ public class InternalPropertiesDao implements Dao { /** * A common prefix used by locks. {@see InternalPropertiesDao#tryLock} */ - public static final String LOCK_PREFIX = "lock."; + private static final String LOCK_PREFIX = "lock."; static final int KEY_MAX_LENGTH = 20; private static final int TEXT_VALUE_MAX_LENGTH = 4000; @@ -192,7 +192,7 @@ public class InternalPropertiesDao implements Dao { * The lock is considered released when the specified duration has elapsed. */ public boolean tryLock(DbSession dbSession, String name, int maxAgeInSeconds) { - String key = LOCK_PREFIX + '.' + name; + String key = LOCK_PREFIX + name; if (key.length() > KEY_MAX_LENGTH) { throw new IllegalArgumentException("lock name is too long"); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalPropertiesDaoTest.java index c995168d02a..01fc23dc680 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalPropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalPropertiesDaoTest.java @@ -55,7 +55,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import static org.sonar.db.property.InternalPropertiesDao.KEY_MAX_LENGTH; -import static org.sonar.db.property.InternalPropertiesDao.LOCK_PREFIX; public class InternalPropertiesDaoTest { @@ -486,15 +485,15 @@ public class InternalPropertiesDaoTest { @Test public void tryLock_throws_if_lock_name_would_produce_too_long_key() { - String tooLongName = randomAlphabetic(KEY_MAX_LENGTH - LOCK_PREFIX.length()); + String tooLongName = randomAlphabetic(KEY_MAX_LENGTH - "lock.".length() + (1 + new Random().nextInt(50))); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("lock name is too long"); underTest.tryLock(dbSession, tooLongName, 60); } - private String key(String name) { - return LOCK_PREFIX + '.' + name; + private static String key(String name) { + return "lock." + name; } private void expectKeyNullOrEmptyIAE() {