From a37df9f33b3b14a79b281d61951e194b67198e23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 16 Sep 2019 11:23:58 +0200 Subject: [PATCH] SONAR-12398 fix too long lock name for Portfolio Refresh which prevented the whole feature to actually work --- .../java/org/sonar/db/property/InternalPropertiesDao.java | 4 ++-- .../org/sonar/db/property/InternalPropertiesDaoTest.java | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) 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() { -- 2.39.5