summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
4813e12)
The test failed because of timing issues with the rate limiter when saving post
replies. The first part of the fix is to inject the rate limiter in the
constructor. The second part would be to create a special rate limiter that
only ever lets the first request pass and not the second one but for now a rate
limit of 1 element per 1000 seconds should be enough, even for the slowest
tests… unless it isn’t.
There are other rate limiters in the memory database which can cause other
tests to fail at random times in the future. Those will be left as an exercise
for another day.
* Memory-based [PostDatabase] implementation.
*/
@Singleton
* Memory-based [PostDatabase] implementation.
*/
@Singleton
-class MemoryDatabase @Inject constructor(private val configuration: Configuration) : AbstractService(), Database {
+class MemoryDatabase constructor(private val configuration: Configuration, private val saveKnownPostRepliesRateLimiter: RateLimiter) : AbstractService(), Database {
+
+ @javax.inject.Inject constructor(configuration: Configuration): this(configuration, RateLimiter.create(1.0))
private val lock = ReentrantReadWriteLock()
private val readLock: ReadLock by lazy { lock.readLock() }
private val lock = ReentrantReadWriteLock()
private val readLock: ReadLock by lazy { lock.readLock() }
private val memoryFriendDatabase = MemoryFriendDatabase(configurationLoader)
private val saveRateLimiter: RateLimiter = RateLimiter.create(1.0)
private val saveKnownPostsRateLimiter: RateLimiter = RateLimiter.create(1.0)
private val memoryFriendDatabase = MemoryFriendDatabase(configurationLoader)
private val saveRateLimiter: RateLimiter = RateLimiter.create(1.0)
private val saveKnownPostsRateLimiter: RateLimiter = RateLimiter.create(1.0)
- private val saveKnownPostRepliesRateLimiter: RateLimiter = RateLimiter.create(1.0)
override val soneLoader get() = this::getSone
override val soneLoader get() = this::getSone
package net.pterodactylus.sone.database.memory
package net.pterodactylus.sone.database.memory
-import com.google.common.base.*
-import com.google.common.base.Optional.*
+import com.google.common.util.concurrent.RateLimiter
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import org.mockito.Mockito.*
import org.mockito.invocation.*
import java.util.Arrays.*
import org.mockito.Mockito.*
import org.mockito.invocation.*
import java.util.Arrays.*
class MemoryDatabaseTest {
private val configuration = deepMock<Configuration>()
class MemoryDatabaseTest {
private val configuration = deepMock<Configuration>()
- private val memoryDatabase = MemoryDatabase(configuration)
+ private val memoryDatabase = MemoryDatabase(configuration, RateLimiter.create(0.001))
private val sone = mock<Sone>()
@BeforeTest
private val sone = mock<Sone>()
@BeforeTest
- @Dirty("the rate limiter should be mocked")
fun `setting post replies as knows twice in a row only saves the database once`() {
prepareConfigurationValues()
val postReply = mock<PostReply>()
fun `setting post replies as knows twice in a row only saves the database once`() {
prepareConfigurationValues()
val postReply = mock<PostReply>()