/**
* 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;
* 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");
}
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 {
@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() {