File tree Expand file tree Collapse file tree 6 files changed +17
-9
lines changed
main/kotlin/io/github/manamiproject/manami/app
test/kotlin/io/github/manamiproject/manami/app/cache/populator Expand file tree Collapse file tree 6 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import io.github.manamiproject.modb.anilist.AnilistConfig
2424import io.github.manamiproject.modb.core.logging.LoggerDelegate
2525import io.github.manamiproject.modb.kitsu.KitsuConfig
2626import io.github.manamiproject.modb.myanimelist.MyanimelistConfig
27+ import kotlinx.coroutines.runBlocking
2728import java.net.URI
2829import java.util.concurrent.Executors
2930import java.util.concurrent.atomic.AtomicReference
@@ -85,8 +86,10 @@ class Manami(
8586
8687private val backgroundTasks = Executors .newCachedThreadPool()
8788
88- internal fun runInBackground (action : () -> Unit ) {
89+ internal fun runInBackground (action : suspend () -> Unit ) {
8990 backgroundTasks.submit {
90- action.invoke()
91+ runBlocking {
92+ action.invoke()
93+ }
9194 }
9295}
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import io.github.manamiproject.modb.serde.json.AnimeListJsonStringDeserializer
1111import io.github.manamiproject.modb.serde.json.DefaultExternalResourceJsonDeserializer
1212import io.github.manamiproject.modb.serde.json.ExternalResourceJsonDeserializer
1313import io.github.manamiproject.modb.serde.json.models.Dataset
14- import kotlinx.coroutines.runBlocking
1514import java.net.URI
1615
1716internal class AnimeCachePopulator (
@@ -20,10 +19,10 @@ internal class AnimeCachePopulator(
2019 private val eventBus : EventBus = SimpleEventBus ,
2120) : CachePopulator<URI, CacheEntry<Anime>> {
2221
23- override fun populate (cache : Cache <URI , CacheEntry <Anime >>) {
22+ override suspend fun populate (cache : Cache <URI , CacheEntry <Anime >>) {
2423 log.info {" Populating cache with anime from [$uri ]." }
2524
26- val parsedAnime = runBlocking { parser.deserialize(uri.toURL()).data }
25+ val parsedAnime = parser.deserialize(uri.toURL()).data
2726
2827 parsedAnime.forEach { anime ->
2928 anime.sources.forEach { source ->
Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ import io.github.manamiproject.manami.app.cache.Cache
44import io.github.manamiproject.manami.app.cache.CacheEntry
55
66internal interface CachePopulator <KEY , VALUE : CacheEntry <* >> {
7- fun populate (cache : Cache <KEY , VALUE >)
7+ suspend fun populate (cache : Cache <KEY , VALUE >)
88}
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ internal class DeadEntriesCachePopulator(
2020 private val parser : ExternalResourceJsonDeserializer <DeadEntries > = DefaultExternalResourceJsonDeserializer (deserializer = DeadEntriesJsonStringDeserializer .instance),
2121) : CachePopulator<URI, CacheEntry<Anime>> {
2222
23- override fun populate (cache : Cache <URI , CacheEntry <Anime >>) {
23+ override suspend fun populate (cache : Cache <URI , CacheEntry <Anime >>) {
2424 log.info { " Populating cache with dead entries from [${config.hostname()} ]" }
2525
2626 runBlocking {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import io.github.manamiproject.modb.core.models.AnimeSeason.Season.FALL
1616import io.github.manamiproject.modb.test.MockServerTestCase
1717import io.github.manamiproject.modb.test.WireMockServerCreator
1818import io.github.manamiproject.modb.test.loadTestResource
19+ import kotlinx.coroutines.runBlocking
1920import org.assertj.core.api.Assertions.assertThat
2021import org.junit.jupiter.api.Test
2122import java.net.URI
@@ -128,7 +129,9 @@ internal class AnimeCachePopulatorTest: MockServerTestCase<WireMockServer> by Wi
128129 )
129130
130131 // when
131- animeCachePopulator.populate(testCache)
132+ runBlocking {
133+ animeCachePopulator.populate(testCache)
134+ }
132135
133136 // then
134137 val expectedAnidbEntry = expectedAnime.copy(
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import io.github.manamiproject.modb.core.config.Hostname
1111import io.github.manamiproject.modb.core.config.MetaDataProviderConfig
1212import io.github.manamiproject.modb.test.MockServerTestCase
1313import io.github.manamiproject.modb.test.WireMockServerCreator
14+ import kotlinx.coroutines.runBlocking
1415import org.assertj.core.api.Assertions.assertThat
1516import org.junit.jupiter.api.Test
1617import java.net.URI
@@ -55,7 +56,9 @@ internal class DeadEntriesCachePopulatorTest: MockServerTestCase<WireMockServer>
5556 )
5657
5758 // when
58- animeCachePopulator.populate(testCache)
59+ runBlocking {
60+ animeCachePopulator.populate(testCache)
61+ }
5962
6063 // then
6164 assertThat(testCache.fetch(URI (" https://example.org/anime/12449" ))).isInstanceOf(DeadEntry ::class .java)
You can’t perform that action at this time.
0 commit comments