Polishing.
Refactored the unit tests to include a negative case and to separate the different scenarios tested. Removed the default LockMode from the Lock annotation. I have the feeling that most users will assume an exclusive Lock when none is specified, but also don't want to request stronger locks than required. Original pull request #1158 See #1041
This commit is contained in:
@@ -34,6 +34,6 @@ public @interface Lock {
|
||||
/**
|
||||
* Defines which type of {@link LockMode} we want to use.
|
||||
*/
|
||||
LockMode value() default LockMode.PESSIMISTIC_READ;
|
||||
LockMode value();
|
||||
|
||||
}
|
||||
|
||||
@@ -335,6 +335,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
|
||||
@Test
|
||||
void findAllByFirstnameWithLock() {
|
||||
|
||||
DummyEntity dummyEntity = createDummyEntity();
|
||||
repository.save(dummyEntity);
|
||||
assertThat(repository.findAllByName(dummyEntity.getName())).hasSize(1);
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.relational.core.sql.LockMode;
|
||||
@@ -123,28 +122,31 @@ public class JdbcQueryMethodUnitTests {
|
||||
}
|
||||
|
||||
@Test // GH-1041
|
||||
void returnsQueryMethodWithLock() throws NoSuchMethodException {
|
||||
void returnsQueryMethodWithCorrectLockTypeWriteLock() throws NoSuchMethodException {
|
||||
|
||||
JdbcQueryMethod queryMethodWithWriteLock = createJdbcQueryMethod("queryMethodWithWriteLock");
|
||||
JdbcQueryMethod queryMethodWithReadLock = createJdbcQueryMethod("queryMethodWithReadLock");
|
||||
|
||||
assertThat(queryMethodWithWriteLock.hasLockMode()).isTrue();
|
||||
assertThat(queryMethodWithReadLock.hasLockMode()).isTrue();
|
||||
assertThat(queryMethodWithWriteLock.lookupLockAnnotation()).isPresent();
|
||||
assertThat(queryMethodWithWriteLock.lookupLockAnnotation().get().value()).isEqualTo(LockMode.PESSIMISTIC_WRITE);
|
||||
}
|
||||
|
||||
@Test // GH-1041
|
||||
void returnsQueryMethodWithCorrectLockType() throws NoSuchMethodException {
|
||||
void returnsQueryMethodWithCorrectLockTypeReadLock() throws NoSuchMethodException {
|
||||
|
||||
JdbcQueryMethod queryMethodWithWriteLock = createJdbcQueryMethod("queryMethodWithWriteLock");
|
||||
JdbcQueryMethod queryMethodWithReadLock = createJdbcQueryMethod("queryMethodWithReadLock");
|
||||
|
||||
assertThat(queryMethodWithWriteLock.lookupLockAnnotation()).isPresent();
|
||||
assertThat(queryMethodWithReadLock.lookupLockAnnotation()).isPresent();
|
||||
|
||||
assertThat(queryMethodWithWriteLock.lookupLockAnnotation().get().value()).isEqualTo(LockMode.PESSIMISTIC_WRITE);
|
||||
assertThat(queryMethodWithReadLock.lookupLockAnnotation().get().value()).isEqualTo(LockMode.PESSIMISTIC_READ);
|
||||
}
|
||||
|
||||
@Test // GH-1041
|
||||
void returnsQueryMethodWithCorrectLockTypeNoLock() throws NoSuchMethodException {
|
||||
|
||||
JdbcQueryMethod queryMethodWithWriteLock = createJdbcQueryMethod("queryMethodName");
|
||||
|
||||
assertThat(queryMethodWithWriteLock.lookupLockAnnotation()).isEmpty();
|
||||
}
|
||||
|
||||
@Lock(LockMode.PESSIMISTIC_WRITE)
|
||||
@Query
|
||||
private void queryMethodWithWriteLock() {}
|
||||
|
||||
Reference in New Issue
Block a user