diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt index fc3bb7c2..ec3decc4 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Source.kt @@ -22,7 +22,7 @@ import org.kodein.di.instance import suwayomi.tachidesk.manga.impl.extension.Extension.getExtensionIconUrl import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSource import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub -import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.invalidateSourceCache +import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.unregisterCatalogueSource import suwayomi.tachidesk.manga.model.dataclass.SourceDataClass import suwayomi.tachidesk.manga.model.table.ExtensionTable import suwayomi.tachidesk.manga.model.table.SourceTable @@ -136,7 +136,7 @@ object Source { pref.saveNewValue(newValue) pref.callChangeListener(newValue) - // must reload the source cache because a preference was changed - invalidateSourceCache(sourceId) + // must reload the source because a preference was changed + unregisterCatalogueSource(sourceId) } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt index 62a82d08..234f5bd7 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/Extension.kt @@ -240,7 +240,7 @@ object Extension { PackageTools.jarLoaderMap.remove(jarPath)?.close() // clear all loaded sources - sources.forEach { GetCatalogueSource.invalidateSourceCache(it) } + sources.forEach { GetCatalogueSource.unregisterCatalogueSource(it) } File(jarPath).delete() } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt index c303b64d..1d3496e3 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/source/GetCatalogueSource.kt @@ -64,7 +64,7 @@ object GetCatalogueSource { sourceCache += sourcePair } - fun invalidateSourceCache(sourceId: Long) { + fun unregisterCatalogueSource(sourceId: Long) { sourceCache.remove(sourceId) } } diff --git a/server/src/test/kotlin/masstest/TestExtensions.kt b/server/src/test/kotlin/masstest/TestExtensionCompatibility.kt similarity index 98% rename from server/src/test/kotlin/masstest/TestExtensions.kt rename to server/src/test/kotlin/masstest/TestExtensionCompatibility.kt index b77601d7..39052b46 100644 --- a/server/src/test/kotlin/masstest/TestExtensions.kt +++ b/server/src/test/kotlin/masstest/TestExtensionCompatibility.kt @@ -30,12 +30,14 @@ import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSource import suwayomi.tachidesk.manga.model.dataclass.ExtensionDataClass import suwayomi.tachidesk.server.applicationSetup +import suwayomi.tachidesk.test.BASE_PATH +import suwayomi.tachidesk.test.setLoggingEnabled import xyz.nulldev.ts.config.CONFIG_PREFIX import java.io.File import java.util.concurrent.atomic.AtomicInteger @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class TestExtensions { +class TestExtensionCompatibility { private val logger = KotlinLogging.logger {} private lateinit var extensions: List private lateinit var sources: List diff --git a/server/src/test/kotlin/suwayomi/tachidesk/TestUtils.kt b/server/src/test/kotlin/suwayomi/tachidesk/TestUtils.kt deleted file mode 100644 index 00646a63..00000000 --- a/server/src/test/kotlin/suwayomi/tachidesk/TestUtils.kt +++ /dev/null @@ -1,21 +0,0 @@ -package masstest - -/* - * Copyright (C) Contributors to the Suwayomi project - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -import ch.qos.logback.classic.Level -import mu.KotlinLogging -import org.slf4j.Logger - -fun setLoggingEnabled(enabled: Boolean = true) { - val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger) - logger.level = if (enabled) { - Level.DEBUG - } else Level.ERROR -} - -const val BASE_PATH = "build/tmp/TestDesk" diff --git a/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt b/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt index f5378f47..232c08b7 100644 --- a/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt +++ b/server/src/test/kotlin/suwayomi/tachidesk/manga/controller/CategoryControllerTest.kt @@ -7,14 +7,13 @@ package suwayomi.tachidesk.manga.controller * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import org.jetbrains.exposed.sql.deleteAll -import org.jetbrains.exposed.sql.transactions.transaction import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import suwayomi.tachidesk.ApplicationTest import suwayomi.tachidesk.manga.impl.Category import suwayomi.tachidesk.manga.model.table.CategoryTable +import suwayomi.tachidesk.test.ApplicationTest +import suwayomi.tachidesk.test.clearTables internal class CategoryControllerTest : ApplicationTest() { @Test @@ -36,8 +35,8 @@ internal class CategoryControllerTest : ApplicationTest() { @AfterEach internal fun tearDown() { - transaction { - CategoryTable.deleteAll() - } + clearTables( + CategoryTable + ) } } diff --git a/server/src/test/kotlin/suwayomi/tachidesk/manga/impl/CategoryMangaTest.kt b/server/src/test/kotlin/suwayomi/tachidesk/manga/impl/CategoryMangaTest.kt index 93647271..ecdce72d 100644 --- a/server/src/test/kotlin/suwayomi/tachidesk/manga/impl/CategoryMangaTest.kt +++ b/server/src/test/kotlin/suwayomi/tachidesk/manga/impl/CategoryMangaTest.kt @@ -7,25 +7,19 @@ package suwayomi.tachidesk.manga.impl * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import org.jetbrains.exposed.sql.batchInsert -import org.jetbrains.exposed.sql.deleteAll -import org.jetbrains.exposed.sql.insertAndGetId -import org.jetbrains.exposed.sql.transactions.transaction import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance -import suwayomi.tachidesk.ApplicationTest import suwayomi.tachidesk.manga.impl.Category.DEFAULT_CATEGORY_ID import suwayomi.tachidesk.manga.model.table.CategoryMangaTable import suwayomi.tachidesk.manga.model.table.CategoryTable import suwayomi.tachidesk.manga.model.table.ChapterTable -import suwayomi.tachidesk.manga.model.table.ChapterTable.isRead -import suwayomi.tachidesk.manga.model.table.ChapterTable.manga -import suwayomi.tachidesk.manga.model.table.ChapterTable.name -import suwayomi.tachidesk.manga.model.table.ChapterTable.sourceOrder -import suwayomi.tachidesk.manga.model.table.ChapterTable.url import suwayomi.tachidesk.manga.model.table.MangaTable +import suwayomi.tachidesk.test.ApplicationTest +import suwayomi.tachidesk.test.clearTables +import suwayomi.tachidesk.test.createChapters +import suwayomi.tachidesk.test.createLibraryManga @TestInstance(TestInstance.Lifecycle.PER_CLASS) class CategoryMangaTest : ApplicationTest() { @@ -67,45 +61,13 @@ class CategoryMangaTest : ApplicationTest() { ) } - private fun createLibraryManga( - _title: String - ): Int { - return transaction { - MangaTable.insertAndGetId { - it[title] = _title - it[url] = _title - it[sourceReference] = 1 - it[defaultCategory] = true - it[inLibrary] = true - }.value - } - } - - private fun createChapters( - mangaId: Int, - amount: Int, - read: Boolean - ) { - val list = listOf((0 until amount)).flatten().map { 1 } - transaction { - ChapterTable - .batchInsert(list) { - this[url] = "$it" - this[name] = "$it" - this[sourceOrder] = it - this[isRead] = read - this[manga] = mangaId - } - } - } - @AfterEach internal fun tearDown() { - transaction { - ChapterTable.deleteAll() - CategoryMangaTable.deleteAll() - MangaTable.deleteAll() - CategoryTable.deleteAll() - } + clearTables( + ChapterTable, + CategoryMangaTable, + MangaTable, + CategoryTable + ) } } diff --git a/server/src/test/kotlin/suwayomi/tachidesk/test/TestUtils.kt b/server/src/test/kotlin/suwayomi/tachidesk/test/TestUtils.kt new file mode 100644 index 00000000..06232c19 --- /dev/null +++ b/server/src/test/kotlin/suwayomi/tachidesk/test/TestUtils.kt @@ -0,0 +1,68 @@ +package suwayomi.tachidesk.test + +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +import ch.qos.logback.classic.Level +import mu.KotlinLogging +import org.jetbrains.exposed.dao.id.IdTable +import org.jetbrains.exposed.sql.batchInsert +import org.jetbrains.exposed.sql.deleteAll +import org.jetbrains.exposed.sql.insertAndGetId +import org.jetbrains.exposed.sql.transactions.transaction +import org.slf4j.Logger +import suwayomi.tachidesk.manga.model.table.ChapterTable +import suwayomi.tachidesk.manga.model.table.MangaTable + +fun setLoggingEnabled(enabled: Boolean = true) { + val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger) + logger.level = if (enabled) { + Level.DEBUG + } else Level.ERROR +} + +const val BASE_PATH = "build/tmp/TestDesk" + +fun createLibraryManga( + _title: String +): Int { + return transaction { + MangaTable.insertAndGetId { + it[title] = _title + it[url] = _title + it[sourceReference] = 1 + it[defaultCategory] = true + it[inLibrary] = true + }.value + } +} + +fun createChapters( + mangaId: Int, + amount: Int, + read: Boolean +) { + val list = listOf((0 until amount)).flatten().map { 1 } + transaction { + ChapterTable + .batchInsert(list) { + this[ChapterTable.url] = "$it" + this[ChapterTable.name] = "$it" + this[ChapterTable.sourceOrder] = it + this[ChapterTable.isRead] = read + this[ChapterTable.manga] = mangaId + } + } +} + +fun clearTables(vararg tables: IdTable<*>) { + transaction { + for (table in tables) { + table.deleteAll() + } + } +}