-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing #7
Comments
@RunWith(SpringRunner::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Sql(
statements = [
"""
CREATE TABLE IF NOT EXISTS lock (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
lock_key VARCHAR(255) UNIQUE ,
token VARCHAR(255),
expireAt TIMESTAMP
);
"""
]) this works, could the SQL be avoided? |
What exactly are you trying to test? Have you considered mocks? The library itself has tests you can take a look at. If you want to write additional Jdbc tests, you will have to create the table (there is another way of creating it, take a look at the Jdbc tests). |
You mean using a script? Yes this is what I ended up doing. |
If you don't add |
Ah, I know what the problem is: @Service
class DistributedLockService(@Qualifier("simpleJdbcLock") private val distributedLock: Lock) {
// This value is the default table name for simpleJdbcLock
private val STORE_ID = "lock"
fun <T> runLocked(key: Any, expiration: Long = Duration.ofSeconds(1).toMillis(), block: () -> T): T {
val token = acquireLock(key, expiration)
val result = block()
releaseLock(key, token)
return result
}
fun acquireLock(key: Any, expiration: Long): String =
distributedLock.acquire(mutableListOf(key.toString()), STORE_ID, expiration)
fun releaseLock(key: Any, token: String) {
distributedLock.release(mutableListOf(key.toString()), token, STORE_ID)
}
} This causes:
I guess I cannot have both the annotation and the manual locks at the same time if I want to disable it. Or I should provide another |
Oh yeah, disabling And only now I have noticed that I should have rearranged the parameters of the |
Exactly, you should write a different |
Yes, I mocked |
Is there an easy way to test annotated methods in
SpringBootTest
?I'd like to disable
distributed-lock
entirely, I tried with:But this fails at runtime
The text was updated successfully, but these errors were encountered: