* 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 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
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 org.mockito.Mockito.*
import org.mockito.invocation.*
import java.util.Arrays.*
-import java.util.UUID.*
import kotlin.test.*
/**
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
}
@Test
- @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>()