diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 4eec02809..66a3b155b 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -1,6 +1,5 @@ import com.gitlab.davinkevin.podcastserver.database.DatabaseConfiguration import com.gitlab.davinkevin.podcastserver.dockerimages.DockerImagesConfiguration -import com.gradle.enterprise.gradleplugin.testretry.retry import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.internal.deprecation.DeprecatableConfiguration import org.jetbrains.kotlin.gradle.dsl.JvmTarget @@ -58,9 +57,7 @@ dependencies { implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") - implementation("org.springframework:spring-r2dbc") implementation("org.postgresql:postgresql") - runtimeOnly("org.postgresql:r2dbc-postgresql") implementation(project(":backend-lib-database")) implementation("org.jdom:jdom2:2.0.6.1") @@ -69,7 +66,6 @@ dependencies { implementation(project(":backend-lib-youtubedl")) implementation("net.bramp.ffmpeg:ffmpeg:0.8.0") - implementation("io.r2dbc:r2dbc-pool") implementation("io.projectreactor.kotlin:reactor-kotlin-extensions") implementation("org.jetbrains.kotlin:kotlin-reflect") @@ -119,9 +115,9 @@ tasks.test { systemProperty("user.timezone", "UTC") project.extensions.getByType().apply { - systemProperty("spring.r2dbc.url", r2dbc()) - systemProperty("spring.r2dbc.username", user) - systemProperty("spring.r2dbc.password", password) + systemProperty("spring.datasource.url", jdbc()) + systemProperty("spring.datasource.username", user) + systemProperty("spring.datasource.password", password) dependsOn(migrateDbTask) } jvmArgs = listOf("--add-opens", "java.base/java.time=ALL-UNNAMED") diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/config/JooqConfig.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/config/JooqConfig.kt deleted file mode 100644 index 31b577ed6..000000000 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/config/JooqConfig.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.davinkevin.podcastserver.config - -import io.r2dbc.spi.ConnectionFactory -import org.jooq.DSLContext -import org.jooq.conf.Settings -import org.jooq.impl.DSL -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -/** - * Created by kevin on 29/12/2021 - */ -@Configuration -class JooqConfig { - - @Bean - fun dslContext(cf: ConnectionFactory): DSLContext { - val settings = Settings().withBindOffsetDateTimeType(true) - - return DSL.using(cf) - .configuration() - .derive(settings) - .dsl() - } -} diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepository.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepository.kt index b154aaf1f..d19ca8a7a 100644 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepository.kt +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepository.kt @@ -6,8 +6,6 @@ import com.github.davinkevin.podcastserver.database.Tables.ITEM import com.github.davinkevin.podcastserver.database.Tables.PODCAST import com.github.davinkevin.podcastserver.database.tables.Cover.COVER import org.jooq.DSLContext -import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toMono import java.net.URI import java.time.OffsetDateTime import java.util.* @@ -16,45 +14,43 @@ import kotlin.io.path.extension class CoverRepository(private val query: DSLContext) { - fun save(cover: CoverForCreation): Cover? { + fun save(cover: CoverForCreation): Cover { val id = UUID.randomUUID() - return query.insertInto(COVER) + + query.insertInto(COVER) .set(COVER.ID, id) .set(COVER.WIDTH, cover.width) .set(COVER.HEIGHT, cover.height) .set(COVER.URL, cover.url.toASCIIString()) - .toMono() - .map { Cover(id, cover.url, cover.height, cover.width) } - .block() + .execute() + + return Cover(id, cover.url, cover.height, cover.width) } - fun findCoverOlderThan(date: OffsetDateTime): List = Flux.defer { - Flux.from( - query - .select( - PODCAST.ID, PODCAST.TITLE, - ITEM.ID, ITEM.TITLE, - COVER.ID, COVER.URL - ) - .from( - COVER - .innerJoin(ITEM).on(COVER.ID.eq(ITEM.COVER_ID)) - .innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID)) - ) - .where(ITEM.CREATION_DATE.lessOrEqual(date)) - .orderBy(COVER.ID.asc()) + fun findCoverOlderThan(date: OffsetDateTime): List { + return query + .select( + PODCAST.ID, PODCAST.TITLE, + ITEM.ID, ITEM.TITLE, + COVER.ID, COVER.URL ) - .map { (podcastId, podcastTitle, itemId, itemTitle, coverId, coverUrl) -> - DeleteCoverRequest( - id = coverId, - extension = Path(coverUrl).extension, - item = Item(itemId, itemTitle), - podcast = Podcast(podcastId, podcastTitle) - ) - } - } - .collectList() - .block()!! + .from( + COVER + .innerJoin(ITEM).on(COVER.ID.eq(ITEM.COVER_ID)) + .innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID)) + ) + .where(ITEM.CREATION_DATE.lessOrEqual(date)) + .orderBy(COVER.ID.asc()) + .fetch() + .map { (podcastId, podcastTitle, itemId, itemTitle, coverId, coverUrl) -> + DeleteCoverRequest( + id = coverId, + extension = Path(coverUrl).extension, + item = Item(itemId, itemTitle), + podcast = Podcast(podcastId, podcastTitle) + ) + } + } } data class CoverForCreation(val width: Int, val height: Int, val url: URI) diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepository.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepository.kt index c1df079e1..5fa687b50 100644 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepository.kt +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepository.kt @@ -14,8 +14,6 @@ import com.github.davinkevin.podcastserver.manager.downloader.DownloadingItem.Po import org.jooq.DSLContext import org.jooq.Record9 import org.jooq.impl.DSL.* -import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toMono import java.net.URI import java.nio.file.Path import java.time.OffsetDateTime @@ -42,8 +40,7 @@ class DownloadRepository(private val query: DSLContext) { .and(ITEM.ID.notIn(select(DOWNLOADING_ITEM.ITEM_ID).from(DOWNLOADING_ITEM))) .orderBy(ITEM.PUB_DATE.asc()) ) - .toMono() - .block() + .execute() } fun addItemToQueue(id: UUID) { @@ -56,8 +53,7 @@ class DownloadRepository(private val query: DSLContext) { .where(ITEM.ID.eq(id)) .and(ITEM.ID.notIn(select(DOWNLOADING_ITEM.ITEM_ID).from(DOWNLOADING_ITEM))) ) - .toMono() - .block() + .execute() } fun findAllToDownload(limit: Int): List { @@ -71,59 +67,52 @@ class DownloadRepository(private val query: DSLContext) { val item = DOWNLOADING_ITEM.item() - val items = Flux.from( - query.with(snapshot) - .select( - item.ID, item.TITLE, item.STATUS, item.URL, item.NUMBER_OF_FAIL, - item.podcast().ID, item.podcast().TITLE, - item.cover().ID, item.cover().URL - ) - .from( - snapshot - .innerJoin(DOWNLOADING_ITEM) - .on(snapshot.field(DOWNLOADING_ITEM.ITEM_ID)!!.eq(DOWNLOADING_ITEM.ITEM_ID)) - ) - .where(snapshot.field(DOWNLOADING_ITEM.STATE)!!.eq(DownloadingState.WAITING)) - .orderBy(snapshot.field(position)) - ) - .collectList() - .block()!! + val items = query.with(snapshot) + .select( + item.ID, item.TITLE, item.STATUS, item.URL, item.NUMBER_OF_FAIL, + item.podcast().ID, item.podcast().TITLE, + item.cover().ID, item.cover().URL + ) + .from( + snapshot + .innerJoin(DOWNLOADING_ITEM) + .on(snapshot.field(DOWNLOADING_ITEM.ITEM_ID)!!.eq(DOWNLOADING_ITEM.ITEM_ID)) + ) + .where(snapshot.field(DOWNLOADING_ITEM.STATE)!!.eq(DownloadingState.WAITING)) + .orderBy(snapshot.field(position)) + .fetch() return items.map(::toDownloadingItem) } fun findAllDownloading(): List { val item = DOWNLOADING_ITEM.item() - val items = Flux.from( - query - .select( - item.ID, item.TITLE, item.STATUS, item.URL, item.NUMBER_OF_FAIL, - item.podcast().ID, item.podcast().TITLE, - item.cover().ID, item.cover().URL - ) - .from(DOWNLOADING_ITEM) - .where(DOWNLOADING_ITEM.STATE.eq(DownloadingState.DOWNLOADING)) - .orderBy(DOWNLOADING_ITEM.POSITION.asc()) - ) - .collectList().block()!! + val items = query + .select( + item.ID, item.TITLE, item.STATUS, item.URL, item.NUMBER_OF_FAIL, + item.podcast().ID, item.podcast().TITLE, + item.cover().ID, item.cover().URL + ) + .from(DOWNLOADING_ITEM) + .where(DOWNLOADING_ITEM.STATE.eq(DownloadingState.DOWNLOADING)) + .orderBy(DOWNLOADING_ITEM.POSITION.asc()) + .fetch() return items.map(::toDownloadingItem) } fun findAllWaiting(): List { val item = DOWNLOADING_ITEM.item() - val items = Flux.from( - query - .select( - item.ID, item.TITLE, item.STATUS, item.URL, item.NUMBER_OF_FAIL, - item.podcast().ID, item.podcast().TITLE, - item.cover().ID, item.cover().URL - ) - .from(DOWNLOADING_ITEM) - .where(DOWNLOADING_ITEM.STATE.eq(DownloadingState.WAITING)) - .orderBy(DOWNLOADING_ITEM.POSITION.asc()) - ) - .collectList().block()!! + val items = query + .select( + item.ID, item.TITLE, item.STATUS, item.URL, item.NUMBER_OF_FAIL, + item.podcast().ID, item.podcast().TITLE, + item.cover().ID, item.cover().URL + ) + .from(DOWNLOADING_ITEM) + .where(DOWNLOADING_ITEM.STATE.eq(DownloadingState.WAITING)) + .orderBy(DOWNLOADING_ITEM.POSITION.asc()) + .fetch() return items.map(::toDownloadingItem) } @@ -133,16 +122,14 @@ class DownloadRepository(private val query: DSLContext) { .update(DOWNLOADING_ITEM) .set(DOWNLOADING_ITEM.STATE, DownloadingState.DOWNLOADING) .where(DOWNLOADING_ITEM.ITEM_ID.eq(id)) - .toMono() - .block() + .execute() } fun remove(id: UUID, hasToBeStopped: Boolean) { query .deleteFrom(DOWNLOADING_ITEM) .where(DOWNLOADING_ITEM.ITEM_ID.eq(id)) - .toMono() - .block() + .execute() if (hasToBeStopped) stopItem(id) } @@ -191,8 +178,7 @@ class DownloadRepository(private val query: DSLContext) { .update(DOWNLOADING_ITEM) .set(DOWNLOADING_ITEM.POSITION, numberOfDownloadingItem + position + 1 ) .where(DOWNLOADING_ITEM.ITEM_ID.eq(id)) - .toMono() - .block() + .execute() } fun stopItem(id: UUID): Int { @@ -200,8 +186,7 @@ class DownloadRepository(private val query: DSLContext) { .update(ITEM) .set(ITEM.STATUS, STOPPED) .where(ITEM.ID.eq(id)) - .toMono() - .block() ?: 0 + .execute() } fun updateDownloadItem(item: DownloadingItem): Int { @@ -210,8 +195,7 @@ class DownloadRepository(private val query: DSLContext) { .set(ITEM.STATUS, item.status.toDb()) .set(ITEM.NUMBER_OF_FAIL, item.numberOfFail) .where(ITEM.ID.eq(item.id)) - .toMono() - .block() ?: 0 + .execute() } fun finishDownload(id: UUID, length: Long, mimeType: String, fileName: Path, downloadDate: OffsetDateTime): Int { @@ -223,17 +207,15 @@ class DownloadRepository(private val query: DSLContext) { .set(ITEM.FILE_NAME, fileName) .set(ITEM.DOWNLOAD_DATE, downloadDate) .where(ITEM.ID.eq(id)) - .toMono() - .block() ?: 0 + .execute() } fun resetToWaitingStateAllDownloadingItems(): Int { return query. - update(DOWNLOADING_ITEM) + update(DOWNLOADING_ITEM) .set(DOWNLOADING_ITEM.STATE, DownloadingState.WAITING) .where(DOWNLOADING_ITEM.STATE.eq(DownloadingState.DOWNLOADING)) - .toMono() - .block() ?: 0 + .execute() } } diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/item/ItemRepository.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/item/ItemRepository.kt index fc4c10142..b6dd010ee 100644 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/item/ItemRepository.kt +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/item/ItemRepository.kt @@ -12,8 +12,6 @@ import org.jooq.* import org.jooq.impl.DSL import org.jooq.impl.DSL.* import org.slf4j.LoggerFactory -import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toMono import java.net.URI import java.nio.file.Path import java.time.OffsetDateTime @@ -29,59 +27,56 @@ class ItemRepository(private val query: DSLContext) { fun findById(id: UUID): Item? = findById(listOf(id)).firstOrNull() private fun findById(ids: List): List { - return Flux.from( - query - .select( - ITEM.ID, ITEM.TITLE, ITEM.URL, - ITEM.PUB_DATE, ITEM.DOWNLOAD_DATE, ITEM.CREATION_DATE, - ITEM.DESCRIPTION, ITEM.MIME_TYPE, ITEM.LENGTH, ITEM.FILE_NAME, ITEM.STATUS, + return query + .select( + ITEM.ID, ITEM.TITLE, ITEM.URL, + ITEM.PUB_DATE, ITEM.DOWNLOAD_DATE, ITEM.CREATION_DATE, + ITEM.DESCRIPTION, ITEM.MIME_TYPE, ITEM.LENGTH, ITEM.FILE_NAME, ITEM.STATUS, - PODCAST.ID, PODCAST.TITLE, PODCAST.URL, - COVER.ID, COVER.URL, COVER.WIDTH, COVER.HEIGHT - ) - .from( - ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID)) - .innerJoin(COVER).on(ITEM.COVER_ID.eq(COVER.ID)) - ) - .where(ITEM.ID.`in`(ids)) - ) + PODCAST.ID, PODCAST.TITLE, PODCAST.URL, + COVER.ID, COVER.URL, COVER.WIDTH, COVER.HEIGHT + ) + .from( + ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID)) + .innerJoin(COVER).on(ITEM.COVER_ID.eq(COVER.ID)) + ) + .where(ITEM.ID.`in`(ids)) + .fetch() .map(::toItem) - .collectList() - .block()!! } fun findAllToDelete(date: OffsetDateTime): List { - return Flux.from( - query - .select(ITEM.ID, ITEM.FILE_NAME, PODCAST.TITLE) - .from(ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID))) - .where(ITEM.DOWNLOAD_DATE.lessOrEqual(date)) - .and(ITEM.STATUS.eq(FINISH)) - .and(PODCAST.HAS_TO_BE_DELETED.isTrue) - .and(ITEM.ID.notIn(query.select(WATCH_LIST_ITEMS.ITEMS_ID).from(WATCH_LIST_ITEMS))) - ) + return query + .select(ITEM.ID, ITEM.FILE_NAME, PODCAST.TITLE) + .from(ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID))) + .where(ITEM.DOWNLOAD_DATE.lessOrEqual(date)) + .and(ITEM.STATUS.eq(FINISH)) + .and(PODCAST.HAS_TO_BE_DELETED.isTrue) + .and(ITEM.ID.notIn(query.select(WATCH_LIST_ITEMS.ITEMS_ID).from(WATCH_LIST_ITEMS))) + .fetch() .map { DeleteItemRequest(it[ITEM.ID], it[ITEM.FILE_NAME], it[PODCAST.TITLE]) } - .collectList() - .block()!! } fun deleteById(id: UUID): DeleteItemRequest? { query .delete(WATCH_LIST_ITEMS) .where(WATCH_LIST_ITEMS.ITEMS_ID.eq(id)) - .toMono() - .block() + .execute() - return query + val result = query .select(ITEM.ID, ITEM.FILE_NAME, ITEM.STATUS, PODCAST.TITLE, PODCAST.HAS_TO_BE_DELETED) .from(ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID))) .where(ITEM.ID.eq(id)) - .toMono() - .delayUntil { query.delete(ITEM).where(ITEM.ID.eq(id)).toMono() } + .fetch() + + query.delete(ITEM).where(ITEM.ID.eq(id)) + .execute() + + return result .filter { it[PODCAST.HAS_TO_BE_DELETED] } .filter { it[ITEM.STATUS] == FINISH } .map { DeleteItemRequest(it[ITEM.ID], it[ITEM.FILE_NAME], it[PODCAST.TITLE]) } - .block() + .firstOrNull() } fun updateAsDeleted(items: Collection) { @@ -90,8 +85,7 @@ class ItemRepository(private val query: DSLContext) { .set(ITEM.STATUS, DELETED) .set(ITEM.FILE_NAME, null as Path?) .where(ITEM.ID.`in`(items)) - .toMono() - .block() + .execute() } fun hasToBeDeleted(id: UUID): Boolean { @@ -99,9 +93,9 @@ class ItemRepository(private val query: DSLContext) { .select(PODCAST.HAS_TO_BE_DELETED) .from(ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID))) .where(ITEM.ID.eq(id)) - .toMono() - .map { it[PODCAST.HAS_TO_BE_DELETED] } - .block() ?: false + .fetchOne() + ?.let { (it) -> it } + ?: false } fun resetById(id: UUID): Item? { @@ -112,8 +106,7 @@ class ItemRepository(private val query: DSLContext) { .set(ITEM.FILE_NAME, null as Path?) .set(ITEM.NUMBER_OF_FAIL, 0) .where(ITEM.ID.eq(id)) - .toMono() - .block()!! + .execute() return findById(id) } @@ -154,7 +147,7 @@ class ItemRepository(private val query: DSLContext) { .limit((page.size * page.page), page.size) ) - val content = Flux.from(query + val content = query .with(fi) .select( fi.field(ITEM.ID), fi.field(ITEM.TITLE), fi.field(ITEM.URL), @@ -171,7 +164,7 @@ class ItemRepository(private val query: DSLContext) { .innerJoin(PODCAST).on(fi.field(ITEM.PODCAST_ID)?.eq(PODCAST.ID)) ) .orderBy(page.sort.toOrderBy(fi.field(ITEM.DOWNLOAD_DATE)!!, fi.field(ITEM.PUB_DATE)!!), fi.field(ITEM.ID)) - ) + .fetch() .map { ( id, title, url, pubDate, downloadDate, creationDate, @@ -190,16 +183,13 @@ class ItemRepository(private val query: DSLContext) { Item.Cover(coverId, URI(coverUrl), coverWidth, coverHeight) ) } - .collectList() - .block()!! val totalElements = query .select(countDistinct(ITEM.ID)) .from(ITEM) .where(filterConditions) - .toMono() - .map { (v) -> v } - .block()!! + .fetchOne()!! + .let { (v) -> v } return PageItem.of(content, totalElements, page) } @@ -290,9 +280,8 @@ class ItemRepository(private val query: DSLContext) { .set(ITEM.URL, item.url) } - val ids: List = Flux.from(query.batch(queries)) - .collectList() - .block()!! + val ids: List = query.batch(queries) + .execute() .withIndex() .filter { (_, isCreated) -> isCreated >= 1 } .map { (idx, _) -> itemsWithIds[idx].id } @@ -305,26 +294,22 @@ class ItemRepository(private val query: DSLContext) { .update(ITEM) .set(ITEM.STATUS, NOT_DOWNLOADED) .where(ITEM.STATUS.`in`(STARTED, PAUSED)) - .toMono() - .block()!! + .execute() log.info("Reset of item with downloading state done") } fun findPlaylistsContainingItem(itemId: UUID): List { - return Flux.from( - query - .select(WATCH_LIST.ID, WATCH_LIST.NAME) - .from( - WATCH_LIST - .innerJoin(WATCH_LIST_ITEMS) - .on(WATCH_LIST.ID.eq(WATCH_LIST_ITEMS.WATCH_LISTS_ID)) - ) - .where(WATCH_LIST_ITEMS.ITEMS_ID.eq(itemId)) - .orderBy(WATCH_LIST.ID) - ) - .collectList() - .block()!! + return query + .select(WATCH_LIST.ID, WATCH_LIST.NAME) + .from( + WATCH_LIST + .innerJoin(WATCH_LIST_ITEMS) + .on(WATCH_LIST.ID.eq(WATCH_LIST_ITEMS.WATCH_LISTS_ID)) + ) + .where(WATCH_LIST_ITEMS.ITEMS_ID.eq(itemId)) + .orderBy(WATCH_LIST.ID) + .fetch() .map { (id, name) -> ItemPlaylist(id, name) } } } diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepository.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepository.kt index 4f44fdd91..1fbdb396d 100644 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepository.kt +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepository.kt @@ -2,8 +2,6 @@ package com.github.davinkevin.podcastserver.playlist import com.github.davinkevin.podcastserver.database.Tables.* import org.jooq.DSLContext -import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toMono import java.net.URI import java.util.* @@ -12,29 +10,25 @@ class PlaylistRepository( ) { fun findAll(): List = - Flux.from(query + query .select(WATCH_LIST.ID, WATCH_LIST.NAME) .from(WATCH_LIST) .orderBy(WATCH_LIST.NAME) - ) + .fetch() .map { Playlist( id = it[WATCH_LIST.ID], name = it[WATCH_LIST.NAME] ) } - .collectList() - .block()!! fun findById(id: UUID): PlaylistWithItems? { val playlist = query .select(WATCH_LIST.ID, WATCH_LIST.NAME) .from(WATCH_LIST) .where(WATCH_LIST.ID.eq(id)) - .toMono() - .block() + .fetchOne() ?: return null - val items = Flux.from( - query + val items = query .select(ITEM.ID, ITEM.TITLE, ITEM.URL, ITEM.FILE_NAME, ITEM.DESCRIPTION, ITEM.MIME_TYPE, ITEM.LENGTH, ITEM.PUB_DATE, @@ -48,7 +42,7 @@ class PlaylistRepository( .innerJoin(COVER).on(ITEM.COVER_ID.eq(COVER.ID)) ) .where(WATCH_LIST_ITEMS.WATCH_LISTS_ID.eq(id)) - ) + .fetch() .map { PlaylistWithItems.Item( id = it[ITEM.ID], title = it[ITEM.TITLE], @@ -68,8 +62,6 @@ class PlaylistRepository( url = URI(it[COVER.URL]) ) ) } - .collectList() - .block()!! return PlaylistWithItems( id = playlist[WATCH_LIST.ID], @@ -86,8 +78,7 @@ class PlaylistRepository( .set(WATCH_LIST.ID, id) .set(WATCH_LIST.NAME, name) .onConflictDoNothing() - .toMono() - .block()!! + .execute() if (numberOfRowInserted == 1) { return PlaylistWithItems(id, name, emptyList()) @@ -97,8 +88,8 @@ class PlaylistRepository( .select(WATCH_LIST.ID) .from(WATCH_LIST) .where(WATCH_LIST.NAME.eq(name)) - .toMono() - .block()!! + .fetch() + .first() return findById(playlist[WATCH_LIST.ID])!! } @@ -109,8 +100,7 @@ class PlaylistRepository( .set(WATCH_LIST_ITEMS.WATCH_LISTS_ID, playlistId) .set(WATCH_LIST_ITEMS.ITEMS_ID, itemId) .onConflictDoNothing() - .toMono() - .block() + .execute() return findById(playlistId)!! } @@ -120,8 +110,7 @@ class PlaylistRepository( .deleteFrom(WATCH_LIST_ITEMS) .where(WATCH_LIST_ITEMS.WATCH_LISTS_ID.eq(playlistId)) .and(WATCH_LIST_ITEMS.ITEMS_ID.eq(itemId)) - .toMono() - .block() + .execute() return findById(playlistId)!! } @@ -130,14 +119,12 @@ class PlaylistRepository( query .deleteFrom(WATCH_LIST_ITEMS) .where(WATCH_LIST_ITEMS.WATCH_LISTS_ID.eq(id)) - .toMono() - .block() + .execute() query .deleteFrom(WATCH_LIST) .where(WATCH_LIST.ID.eq(id)) - .toMono() - .block() + .execute() } } diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepository.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepository.kt index dcfd13c31..fa5d2d867 100644 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepository.kt +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepository.kt @@ -9,8 +9,6 @@ import org.jooq.Record13 import org.jooq.Records.mapping import org.jooq.TableField import org.jooq.impl.DSL.* -import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toMono import java.net.URI import java.sql.Date import java.time.Duration @@ -39,13 +37,12 @@ class PodcastRepository(private val query: DSLContext) { ) .from(PODCAST) .where(PODCAST.ID.eq(id)) - .toMono() - .block() + .fetchOne() ?.let(::toPodcast) } fun findAll(): List { - val allPodcastQuery = Flux.from(query + val allPodcastQuery = query .select( PODCAST.ID, PODCAST.TITLE, PODCAST.DESCRIPTION, PODCAST.SIGNATURE, PODCAST.URL, PODCAST.HAS_TO_BE_DELETED, PODCAST.LAST_UPDATE, @@ -62,9 +59,8 @@ class PodcastRepository(private val query: DSLContext) { .convertFrom { r -> r.map(mapping(::Tag)) }, ) .from(PODCAST) - .orderBy(PODCAST.ID)) - .collectList() - .block()!! + .orderBy(PODCAST.ID) + .fetch() return allPodcastQuery.map(::toPodcast) } @@ -78,17 +74,14 @@ class PodcastRepository(private val query: DSLContext) { val startDate = ZonedDateTime.now().minusMonths(month.toLong()) val numberOfDays = Duration.between(startDate, ZonedDateTime.now()).toDays() - val stats = Flux.from( - query - .select(PODCAST.TYPE, count(), date) - .from(ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID))) - .where(field.isNotNull) - .and(dateDiff(currentDate(), field.cast(Date::class.java)).lessThan(numberOfDays.toInt())) - .groupBy(PODCAST.TYPE, date) - .orderBy(date.desc()) - ) - .collectList() - .block()!! + val stats = query + .select(PODCAST.TYPE, count(), date) + .from(ITEM.innerJoin(PODCAST).on(ITEM.PODCAST_ID.eq(PODCAST.ID))) + .where(field.isNotNull) + .and(dateDiff(currentDate(), field.cast(Date::class.java)).lessThan(numberOfDays.toInt())) + .groupBy(PODCAST.TYPE, date) + .orderBy(date.desc()) + .fetch() return stats .groupBy { it[PODCAST.TYPE] } @@ -108,18 +101,15 @@ class PodcastRepository(private val query: DSLContext) { val startDate = ZonedDateTime.now().minusMonths(month.toLong()) val numberOfDays = Duration.between(startDate, ZonedDateTime.now()).toDays() - val results = Flux.from( - query - .select(count(), date) - .from(ITEM) - .where(ITEM.PODCAST_ID.eq(pid)) - .and(field.isNotNull) - .and(dateDiff(currentDate(), field.cast(Date::class.java)).lessThan(numberOfDays.toInt())) - .groupBy(date) - .orderBy(date.desc()) - ) - .collectList() - .block()!! + val results = query + .select(count(), date) + .from(ITEM) + .where(ITEM.PODCAST_ID.eq(pid)) + .and(field.isNotNull) + .and(dateDiff(currentDate(), field.cast(Date::class.java)).lessThan(numberOfDays.toInt())) + .groupBy(date) + .orderBy(date.desc()) + .fetch() return results .map { (count, date) -> NumberOfItemByDateWrapper(date.toLocalDate(), count) } @@ -131,14 +121,12 @@ class PodcastRepository(private val query: DSLContext) { query .insertInto(PODCAST, PODCAST.ID, PODCAST.TITLE, PODCAST.URL, PODCAST.HAS_TO_BE_DELETED, PODCAST.TYPE, PODCAST.COVER_ID) .values(id, title, url, hasToBeDeleted, type, cover.id) - .toMono() - .block()!! + .execute() if (!tags.isEmpty()) { query.insertInto(PODCAST_TAGS, PODCAST_TAGS.PODCASTS_ID, PODCAST_TAGS.TAGS_ID ) .apply { tags.forEach { values(id, it.id) } } - .toMono() - .block()!! + .execute() } return findById(id)!! @@ -152,21 +140,18 @@ class PodcastRepository(private val query: DSLContext) { .set(PODCAST.HAS_TO_BE_DELETED, hasToBeDeleted) .set(PODCAST.COVER_ID, cover.id) .where(PODCAST.ID.eq(id)) - .toMono() - .block() + .execute() query .delete(PODCAST_TAGS) .where(PODCAST_TAGS.PODCASTS_ID.eq(id)) - .toMono() - .block() + .execute() if (tags.isNotEmpty()) { query .insertInto(PODCAST_TAGS, PODCAST_TAGS.PODCASTS_ID, PODCAST_TAGS.TAGS_ID) .apply { tags.forEach { values(id, it.id) } } - .toMono() - .block() + .execute() } return findById(id)!! @@ -177,8 +162,7 @@ class PodcastRepository(private val query: DSLContext) { .update(PODCAST) .set(PODCAST.SIGNATURE, newSignature) .where(PODCAST.ID.eq(podcastId)) - .toMono() - .block() + .execute() } fun updateLastUpdate(podcastId: UUID) { @@ -186,8 +170,7 @@ class PodcastRepository(private val query: DSLContext) { .update(PODCAST) .set(PODCAST.LAST_UPDATE, now()) .where(PODCAST.ID.eq(podcastId)) - .toMono() - .block() + .execute() } fun deleteById(id: UUID): DeletePodcastRequest? { @@ -201,35 +184,29 @@ class PodcastRepository(private val query: DSLContext) { .where(ITEM.PODCAST_ID.eq(id)) ) ) - .toMono() - .block() + .execute() query .delete(PODCAST_TAGS) .where(PODCAST_TAGS.PODCASTS_ID.eq(id)) - .toMono() - .block() + .execute() query .delete(ITEM) .where(ITEM.PODCAST_ID.eq(id)) - .toMono() - .block() + .execute() val podcast = query .select(PODCAST.ID, PODCAST.TITLE, PODCAST.HAS_TO_BE_DELETED, PODCAST.COVER_ID) .from(PODCAST) .where(PODCAST.ID.eq(id)) - .toMono() - .block()!! + .fetchOne()!! query.delete(PODCAST).where(PODCAST.ID.eq(id)) - .toMono() - .block() + .execute() query.delete(COVER).where(COVER.ID.eq(podcast[PODCAST.COVER_ID])) - .toMono() - .block() + .execute() if (!podcast[PODCAST.HAS_TO_BE_DELETED]) { return null diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/tag/TagRepository.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/tag/TagRepository.kt index 6e6c55d91..081c830fe 100644 --- a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/tag/TagRepository.kt +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/tag/TagRepository.kt @@ -2,59 +2,51 @@ package com.github.davinkevin.podcastserver.tag import com.github.davinkevin.podcastserver.database.Tables.TAG import org.jooq.DSLContext -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import reactor.kotlin.core.publisher.switchIfEmpty -import reactor.kotlin.core.publisher.toMono import java.util.* class TagRepository(val query: DSLContext) { - fun findById(id: UUID): Tag? = Mono.defer { - query - .select(TAG.ID, TAG.NAME) + fun findById(id: UUID): Tag? { + val (name) = query + .select(TAG.NAME) .from(TAG) .where(TAG.ID.eq(id)) - .toMono() - .map { (id, name) -> Tag(id, name) } - } - .block() + .fetchOne() + ?: return null + return Tag(id, name) + } fun findByNameLike(name: String): List { - return Flux.from( - query - .select(TAG.ID, TAG.NAME) - .from(TAG) - .where(TAG.NAME.containsIgnoreCase(name)) - .orderBy(TAG.NAME.asc()) - ) + return query + .select(TAG.ID, TAG.NAME) + .from(TAG) + .where(TAG.NAME.containsIgnoreCase(name)) + .orderBy(TAG.NAME.asc()) + .fetch() .map { (id, name) -> Tag(id, name) } - .collectList() - .block()!! } fun save(name: String): Tag { - val result = query + val (id) = query .select(TAG.ID, TAG.NAME) .from(TAG) .where(TAG.NAME.eq(name)) - .toMono() - .block() - ?.let { Tag(it[TAG.ID], it[TAG.NAME]) } + .fetchOne() + ?: return create(name) - if (result != null) { - return result - } + return Tag(id, name) + } + private fun create(name: String): Tag { val id = UUID.randomUUID() - return query + query .insertInto(TAG) .set(TAG.ID, id) .set(TAG.NAME, name) - .toMono() - .map { Tag(id, name) } - .block()!! + .execute() + + return Tag(id, name) } } diff --git a/backend/src/main/resources/application-local-pg.yml b/backend/src/main/resources/application-local-pg.yml index c07f4283d..8b56f94bf 100644 --- a/backend/src/main/resources/application-local-pg.yml +++ b/backend/src/main/resources/application-local-pg.yml @@ -1,5 +1,5 @@ spring: - r2dbc: + datasource: username: ${PG_ALTERNATE_USER:podcast-server-user} password: ${PG_ALTERNATE_PASSWORD:nAAdo5wNs7WEF1UxUobpJDfS9Si62PHa} - url: r2dbc:postgresql://postgres:5432/podcast-server \ No newline at end of file + url: jdbc:postgresql://postgres:5432/podcast-server \ No newline at end of file diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index cea2ca0b0..564994837 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -16,15 +16,15 @@ spring: server: port: 8080 -management: +management: endpoint: health: probes: enabled: true show-details: always group: - liveness.include: ["r2dbc", "ping"] + liveness.include: ["db", "ping"] readiness.include: ["ping"] endpoints: web: @@ -42,4 +42,4 @@ logging: level: org: apache: - catalina: off \ No newline at end of file + catalina: off diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/JOOQUtils.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/JOOQUtils.kt deleted file mode 100644 index 6e42738f0..000000000 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/JOOQUtils.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.github.davinkevin.podcastserver - -import com.github.davinkevin.podcastserver.config.JooqConfig -import org.jooq.Batch -import org.jooq.Field -import org.jooq.Record -import org.jooq.ResultQuery -import org.jooq.impl.DSL -import org.junit.jupiter.api.extension.ExtendWith -import org.springframework.boot.autoconfigure.ImportAutoConfiguration -import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration -import org.springframework.boot.autoconfigure.r2dbc.R2dbcTransactionManagerAutoConfiguration -import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration -import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration -import org.springframework.context.annotation.Import -import org.springframework.test.context.junit.jupiter.SpringExtension -import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toFlux -import reactor.kotlin.core.publisher.toMono -import java.lang.annotation.Inherited - -/** - * Created by kevin on 31/12/2021 - */ - -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -@MustBeDocumented -@Inherited -@ExtendWith(SpringExtension::class) -@OverrideAutoConfiguration(enabled = false) -@Import(JooqConfig::class) -@ImportAutoConfiguration( - R2dbcAutoConfiguration::class, - TransactionAutoConfiguration::class, - R2dbcTransactionManagerAutoConfiguration::class -) -annotation class JooqR2DBCTest - -fun ResultQuery.r2dbc() = JooqReactorResultQueryWrapper(this) -class JooqReactorResultQueryWrapper(private val query: ResultQuery) { - - fun fetchOne(): T = query.toMono().block()!! - - fun fetchOne(field: Field): T { - return query.toMono() - .map { it[field] } - .block()!! - } - fun fetch(): List { - return Flux.from(query) - .collectList() - .block()!! - } -} - -fun Batch.r2dbc() = JooqReactorBatchWrapper(this) -class JooqReactorBatchWrapper(private val batch: Batch) { - fun execute(): IntArray = batch.toFlux().collectList().block()!!.toIntArray() -} - diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/MockServer.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/MockServer.kt index 46ba903f0..b21b8322d 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/MockServer.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/MockServer.kt @@ -3,13 +3,9 @@ package com.github.davinkevin.podcastserver import com.github.tomakehurst.wiremock.WireMockServer import org.junit.jupiter.api.extension.* import org.springframework.boot.web.client.RestClientCustomizer -import org.springframework.boot.web.reactive.function.client.WebClientCustomizer import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod import org.springframework.http.HttpRequest -import org.springframework.web.reactive.function.client.ClientRequest -import org.springframework.web.reactive.function.client.ExchangeFilterFunction -import reactor.kotlin.core.publisher.toMono import java.net.URI private const val port = 5555 @@ -37,17 +33,6 @@ class MockServer: BeforeEachCallback, AfterEachCallback, ParameterResolver { } } -fun remapToMockServer(host: String) = WebClientCustomizer { it.filter(ExchangeFilterFunction.ofRequestProcessor { c -> - val mockServerUrl = c.url().toASCIIString() - .replace("https", "http") - .replace(host, "localhost:$port") - - ClientRequest.from(c) - .url(URI(mockServerUrl)) - .build() - .toMono() -}) } - fun remapRestClientToMockServer(host: String) = RestClientCustomizer { rc -> rc.requestInterceptor { request, body, execution -> val mockServerUrl = request.uri.toASCIIString() diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepositoryTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepositoryTest.kt index 21b7f5625..7197087b3 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepositoryTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/cover/CoverRepositoryTest.kt @@ -1,12 +1,10 @@ package com.github.davinkevin.podcastserver.cover -import com.github.davinkevin.podcastserver.JooqR2DBCTest import com.github.davinkevin.podcastserver.cover.DeleteCoverRequest.Item import com.github.davinkevin.podcastserver.cover.DeleteCoverRequest.Podcast import com.github.davinkevin.podcastserver.database.Tables.* import com.github.davinkevin.podcastserver.database.enums.ItemStatus import com.github.davinkevin.podcastserver.extension.assertthat.assertAll -import com.github.davinkevin.podcastserver.r2dbc import org.assertj.core.api.Assertions.assertThat import org.jooq.DSLContext import org.jooq.impl.DSL.insertInto @@ -16,6 +14,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.jooq.JooqTest import org.springframework.context.annotation.Import import org.springframework.transaction.annotation.Propagation.NEVER import org.springframework.transaction.annotation.Transactional @@ -27,7 +26,7 @@ import kotlin.io.path.Path /** * Created by kevin on 14/09/2019 */ -@JooqR2DBCTest +@JooqTest @Transactional(propagation = NEVER) @Import(CoverRepository::class) class CoverRepositoryTest( @@ -43,7 +42,7 @@ class CoverRepositoryTest( truncate(ITEM).cascade(), truncate(PODCAST).cascade(), truncate(COVER).cascade(), - ).r2dbc().execute() + ).execute() } @Nested @@ -94,7 +93,8 @@ class CoverRepositoryTest( .values(fromString("e9c89e7f-7a8a-43ad-8425-ba2dbad2c561"), fromString("eb355a23-e030-4966-b75a-b70881a8bd08")) .values(fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6")) - ).r2dbc().execute() + ) + .execute() } @Test @@ -108,7 +108,7 @@ class CoverRepositoryTest( ) /* When */ - val c = repository.save(cover)!! + val c = repository.save(cover) /* Then */ assertAll { @@ -118,7 +118,7 @@ class CoverRepositoryTest( assertThat(c.url).isEqualTo(url) } - val r = query.selectFrom(COVER).r2dbc().fetch() + val r = query.selectFrom(COVER).fetch() assertThat(r).hasSize(10) val coverRecord = r.first { it[COVER.URL] == url.toASCIIString() } @@ -127,7 +127,6 @@ class CoverRepositoryTest( assertThat(coverRecord.height).isEqualTo(200) assertThat(coverRecord.url).isEqualTo(url.toASCIIString()) } - } @Nested @@ -178,7 +177,7 @@ class CoverRepositoryTest( .values(fromString("e9c89e7f-7a8a-43ad-8425-ba2dbad2c561"), fromString("eb355a23-e030-4966-b75a-b70881a8bd08")) .values(fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6")) - ).r2dbc().execute() + ).execute() } @Test diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadHandlerTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadHandlerTest.kt index f4161408f..e334273a0 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadHandlerTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadHandlerTest.kt @@ -279,7 +279,6 @@ class DownloadHandlerTest( @Test fun `with success`() { /* Given */ -// whenever(idm.setLimitParallelDownload(12)).thenReturn(Mono.empty()) /* When */ rest .post() @@ -294,7 +293,7 @@ class DownloadHandlerTest( assertThat(limit).isEqualTo(12) } -// verify(idm, times(1)).setLimitParallelDownload(12) + verify(idm).limitParallelDownload = 12 } } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepositoryTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepositoryTest.kt index e4a1530ec..9f538d42a 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepositoryTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/download/DownloadRepositoryTest.kt @@ -1,6 +1,5 @@ package com.github.davinkevin.podcastserver.download -import com.github.davinkevin.podcastserver.JooqR2DBCTest import com.github.davinkevin.podcastserver.database.Tables.* import com.github.davinkevin.podcastserver.database.enums.DownloadingState import com.github.davinkevin.podcastserver.database.enums.ItemStatus @@ -8,7 +7,6 @@ import com.github.davinkevin.podcastserver.entity.Status import com.github.davinkevin.podcastserver.entity.toDb import com.github.davinkevin.podcastserver.extension.assertthat.assertAll import com.github.davinkevin.podcastserver.manager.downloader.DownloadingItem -import com.github.davinkevin.podcastserver.r2dbc import org.assertj.core.api.Assertions.assertThat import org.jooq.DSLContext import org.jooq.impl.DSL.* @@ -17,6 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.EnumSource import org.junit.jupiter.params.provider.ValueSource import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.jooq.JooqTest import org.springframework.context.annotation.Import import java.net.URI import java.time.Clock @@ -31,7 +30,7 @@ private val fixedDate = Clock.fixed(OffsetDateTime.of(2022, 3, 4, 5, 6, 7, 0, Zo /** * Created by kevin on 27/06/2020 */ -@JooqR2DBCTest +@JooqTest @Import(DownloadRepository::class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) class DownloadRepositoryTest( @@ -51,7 +50,6 @@ class DownloadRepositoryTest( truncate(PODCAST).cascade(), truncate(COVER).cascade(), ) - .r2dbc() .execute() } @@ -67,7 +65,7 @@ class DownloadRepositoryTest( repo.initQueue(OffsetDateTime.now(fixedDate), 5) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(0) } @@ -114,7 +112,6 @@ class DownloadRepositoryTest( .columns(p.ID, p.DESCRIPTION, p.HAS_TO_BE_DELETED, p.LAST_UPDATE, p.SIGNATURE, p.TITLE, p.TYPE, p.URL, p.COVER_ID) .values(podcastId, "desc", true, OffsetDateTime.now(fixedDate), "sign", "Podcast-Title", "Youtube", "https://www.youtube.com/channel/UCx83f-KzDd3o1QK2AdJIftg", coverId), ) - .r2dbc() .execute() } @@ -124,7 +121,6 @@ class DownloadRepositoryTest( selectOne(), truncate(DOWNLOADING_ITEM).cascade(), ) - .r2dbc() .execute() } @@ -144,7 +140,6 @@ class DownloadRepositoryTest( .values(itemId3, twoDaysAgo, twoDaysAgo, twoDaysAgo, "desc item 3", Path(""), 1, "video/mp4", 20, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDaysAgo, threeDaysAgo, threeDaysAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId), ) - .r2dbc() .execute() } @@ -155,7 +150,7 @@ class DownloadRepositoryTest( repo.initQueue(oneDayAgo, 999) /* Then */ - val (first) = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val (first) = query.selectFrom(DOWNLOADING_ITEM).fetch() first.apply { assertThat(itemId).isEqualTo(itemId1) assertThat(position).isEqualTo(1) @@ -170,7 +165,7 @@ class DownloadRepositoryTest( repo.initQueue(twoDaysAgo, 999) /* Then */ - val (first, second) = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val (first, second) = query.selectFrom(DOWNLOADING_ITEM).fetch() first.apply { assertThat(itemId).isEqualTo(itemId2) assertThat(position).isEqualTo(1) @@ -190,7 +185,7 @@ class DownloadRepositoryTest( repo.initQueue(threeDaysAgo, 999) /* Then */ - val (first, second, third) = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val (first, second, third) = query.selectFrom(DOWNLOADING_ITEM).fetch() first.apply { assertThat(itemId).isEqualTo(itemId3) assertThat(position).isEqualTo(1) @@ -225,7 +220,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDaysAgo, twoDaysAgo, twoDaysAgo, "desc item 3", Path(""), 1, "video/mp4", 20, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDaysAgo, threeDaysAgo, threeDaysAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId), ) - .r2dbc() + .execute() } @@ -236,7 +231,7 @@ class DownloadRepositoryTest( repo.initQueue(now.minusYears(1) , 0) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).isEmpty() } @@ -247,7 +242,7 @@ class DownloadRepositoryTest( repo.initQueue(now.minusYears(1) , 5+1) /* Then */ - val (first) = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val (first) = query.selectFrom(DOWNLOADING_ITEM).fetch() first.apply { assertThat(itemId).isEqualTo(itemId1) assertThat(position).isEqualTo(1) @@ -262,7 +257,7 @@ class DownloadRepositoryTest( repo.initQueue(now.minusYears(1) , 10+1) /* Then */ - val (first, second) = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val (first, second) = query.selectFrom(DOWNLOADING_ITEM).fetch() first.apply { assertThat(itemId).isEqualTo(itemId2) assertThat(position).isEqualTo(1) @@ -282,7 +277,7 @@ class DownloadRepositoryTest( repo.initQueue(now.minusYears(1) , 20+1) /* Then */ - val (first, second, third) = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val (first, second, third) = query.selectFrom(DOWNLOADING_ITEM).fetch() first.apply { assertThat(itemId).isEqualTo(itemId3) assertThat(position).isEqualTo(1) @@ -353,7 +348,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDaysAgo, twoDaysAgo, twoDaysAgo, "desc item 3", Path(""), 1, "video/mp4", 20, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDaysAgo, threeDaysAgo, threeDaysAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -363,7 +358,7 @@ class DownloadRepositoryTest( selectOne(), truncate(DOWNLOADING_ITEM).cascade(), ) - .r2dbc() + .execute() } @@ -378,7 +373,7 @@ class DownloadRepositoryTest( repo.addItemToQueue(itemId1) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(1) items.last().apply { assertThat(itemId).isEqualTo(itemId1) @@ -396,13 +391,13 @@ class DownloadRepositoryTest( .columns(DOWNLOADING_ITEM.ITEM_ID, DOWNLOADING_ITEM.STATE, DOWNLOADING_ITEM.POSITION) .values(itemId2, DownloadingState.WAITING, 1) ) - .r2dbc().execute() + .execute() /* When */ repo.addItemToQueue(itemId1) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(2) items.last().apply { assertThat(itemId).isEqualTo(itemId1) @@ -420,13 +415,13 @@ class DownloadRepositoryTest( .columns(DOWNLOADING_ITEM.ITEM_ID, DOWNLOADING_ITEM.STATE, DOWNLOADING_ITEM.POSITION) .values(itemId2, DownloadingState.WAITING, 123) ) - .r2dbc().execute() + .execute() /* When */ repo.addItemToQueue(itemId1) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(2) items.last().apply { assertThat(itemId).isEqualTo(itemId1) @@ -445,13 +440,13 @@ class DownloadRepositoryTest( .values(itemId2, DownloadingState.WAITING, 128) .values(itemId3, DownloadingState.WAITING, 256) ) - .r2dbc().execute() + .execute() /* When */ repo.addItemToQueue(itemId1) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(3) items.last().apply { assertThat(itemId).isEqualTo(itemId1) @@ -470,13 +465,13 @@ class DownloadRepositoryTest( .values(itemId2, DownloadingState.WAITING, 128) .values(itemId3, DownloadingState.WAITING, 256) ) - .r2dbc().execute() + .execute() /* When */ repo.addItemToQueue(itemId3) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(2) items.last().apply { assertThat(itemId).isEqualTo(itemId3) @@ -495,13 +490,13 @@ class DownloadRepositoryTest( .values(itemId2, DownloadingState.DOWNLOADING, 128) .values(itemId3, DownloadingState.WAITING, 256) ) - .r2dbc().execute() + .execute() /* When */ repo.addItemToQueue(itemId2) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(2) items.first().apply { assertThat(itemId).isEqualTo(itemId2) @@ -520,12 +515,12 @@ class DownloadRepositoryTest( .values(itemId2, DownloadingState.DOWNLOADING, 128) .values(itemId3, DownloadingState.WAITING, 256) ) - .r2dbc().execute() + .execute() /* When */ repo.addItemToQueue(UUID.fromString("65a10b6e-5474-4e1c-9697-eba5330aee1d")) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() assertThat(items).hasSize(2) } } @@ -578,7 +573,7 @@ class DownloadRepositoryTest( .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -587,7 +582,7 @@ class DownloadRepositoryTest( query.batch( truncate(DOWNLOADING_ITEM).cascade() ) - .r2dbc() + .execute() } @@ -616,7 +611,7 @@ class DownloadRepositoryTest( .values(itemId3, 3) .values(itemId4, 4) ) - .r2dbc() + .execute() /* When */ val items = repo.findAllToDownload(30) @@ -644,7 +639,7 @@ class DownloadRepositoryTest( .values(itemId3, 3) .values(itemId4, 4) ) - .r2dbc() + .execute() /* When */ val items = repo.findAllToDownload(1) @@ -666,7 +661,7 @@ class DownloadRepositoryTest( .values(itemId3, 3) .values(itemId4, 4) ) - .r2dbc() + .execute() /* When */ val items = repo.findAllToDownload(2) @@ -696,7 +691,7 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() /* When */ val items = repo.findAllToDownload(3) @@ -720,7 +715,7 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() /* When */ @@ -743,7 +738,7 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.DOWNLOADING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() /* When */ val items = repo.findAllToDownload(3) @@ -764,7 +759,7 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.DOWNLOADING) .values(itemId4, 4, DownloadingState.DOWNLOADING) ) - .r2dbc() + .execute() /* When */ @@ -825,7 +820,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDaysAgo, twoDaysAgo, twoDaysAgo, "desc item 3", Path(""), 1, "video/mp4", 20, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDaysAgo, threeDaysAgo, threeDaysAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -835,7 +830,7 @@ class DownloadRepositoryTest( selectOne(), truncate(DOWNLOADING_ITEM).cascade(), ) - .r2dbc() + .execute() } @@ -857,7 +852,7 @@ class DownloadRepositoryTest( .columns(DOWNLOADING_ITEM.ITEM_ID, DOWNLOADING_ITEM.STATE, DOWNLOADING_ITEM.POSITION) .values(itemId2, DownloadingState.WAITING, 123) ) - .r2dbc().execute() + .execute() /* When */ val items = repo.findAllDownloading() @@ -875,7 +870,7 @@ class DownloadRepositoryTest( .columns(DOWNLOADING_ITEM.ITEM_ID, DOWNLOADING_ITEM.STATE, DOWNLOADING_ITEM.POSITION) .values(itemId2, DownloadingState.DOWNLOADING, 123) ) - .r2dbc().execute() + .execute() /* When */ val items = repo.findAllDownloading() @@ -912,7 +907,7 @@ class DownloadRepositoryTest( .values(itemId2, DownloadingState.DOWNLOADING, 128) .values(itemId3, DownloadingState.DOWNLOADING, 256) ) - .r2dbc().execute() + .execute() /* When */ val items = repo.findAllDownloading() @@ -1010,7 +1005,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDaysAgo, twoDaysAgo, twoDaysAgo, "desc item 3", Path(""), 1, "video/mp4", 20, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDaysAgo, threeDaysAgo, threeDaysAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -1020,7 +1015,7 @@ class DownloadRepositoryTest( selectOne(), truncate(DOWNLOADING_ITEM).cascade(), ) - .r2dbc() + .execute() } @@ -1043,7 +1038,7 @@ class DownloadRepositoryTest( .columns(DOWNLOADING_ITEM.ITEM_ID, DOWNLOADING_ITEM.STATE, DOWNLOADING_ITEM.POSITION) .values(itemId2, DownloadingState.DOWNLOADING, 123) ) - .r2dbc().execute() + .execute() /* When */ val items = repo.findAllWaiting() @@ -1061,7 +1056,7 @@ class DownloadRepositoryTest( .columns(DOWNLOADING_ITEM.ITEM_ID, DOWNLOADING_ITEM.STATE, DOWNLOADING_ITEM.POSITION) .values(itemId2, DownloadingState.WAITING, 123) ) - .r2dbc().execute() + .execute() /* When */ val items = repo.findAllWaiting() @@ -1098,7 +1093,7 @@ class DownloadRepositoryTest( .values(itemId2, DownloadingState.WAITING, 128) .values(itemId3, DownloadingState.WAITING, 256) ) - .r2dbc().execute() + .execute() /* When */ val items = repo.findAllWaiting() @@ -1197,7 +1192,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDayAgo, twoDayAgo, twoDayAgo, "desc item 3", Path(""), 1, "video/mp4", 20, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId), ) - .r2dbc() + .execute() } @@ -1210,7 +1205,7 @@ class DownloadRepositoryTest( /* Then */ val numberOfStoppedItems = query.selectCount().from(ITEM).where(ITEM.STATUS.eq(ItemStatus.STOPPED)) - .r2dbc().fetchOne(count()) + .fetchOne(count()) assertThat(numberOfStoppedItems).isEqualTo(1) } @@ -1228,7 +1223,7 @@ class DownloadRepositoryTest( val notStoppedItems = query .selectFrom(ITEM) .where(ITEM.STATUS.notEqual(ItemStatus.STOPPED)) - .r2dbc() + .fetch() assertThat(notStoppedItems).hasSize(3) @@ -1242,7 +1237,7 @@ class DownloadRepositoryTest( truncate(PODCAST).cascade(), truncate(COVER).cascade(), ) - .r2dbc() + .execute() } } @@ -1292,7 +1287,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDayAgo, twoDayAgo, twoDayAgo, "desc item 3", Path(""), 1, "video/mp4", 6, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 6, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId), ) - .r2dbc() + .execute() } @@ -1318,9 +1313,9 @@ class DownloadRepositoryTest( repo.updateDownloadItem(withStatus) /* Then */ - val item = query.selectFrom(i).where(i.ID.eq(downloadingItem.id)).r2dbc().fetchOne() ?: error("item not found") + val item = query.selectFrom(i).where(i.ID.eq(downloadingItem.id)).fetchOne() ?: error("item not found") assertThat(item[ITEM.STATUS]).isEqualTo(status.toDb()) - val others = query.selectFrom(i).where(i.ID.notEqual(downloadingItem.id)).r2dbc().fetch() + val others = query.selectFrom(i).where(i.ID.notEqual(downloadingItem.id)).fetch() assertThat(others.map { it[i.STATUS] }).containsOnly(ItemStatus.NOT_DOWNLOADED) } @@ -1334,9 +1329,9 @@ class DownloadRepositoryTest( repo.updateDownloadItem(withFails) /* Then */ - val item = query.selectFrom(i).where(i.ID.eq(downloadingItem.id)).r2dbc().fetchOne() ?: error("item not found") + val item = query.selectFrom(i).where(i.ID.eq(downloadingItem.id)).fetchOne() ?: error("item not found") assertThat(item[i.NUMBER_OF_FAIL]).isEqualTo(numberOfFails) - val others = query.selectFrom(i).where(i.ID.notEqual(downloadingItem.id)).r2dbc().fetch() + val others = query.selectFrom(i).where(i.ID.notEqual(downloadingItem.id)).fetch() assertThat(others.map { it[i.NUMBER_OF_FAIL] }).containsOnly(6) } @@ -1347,7 +1342,7 @@ class DownloadRepositoryTest( truncate(PODCAST).cascade(), truncate(COVER).cascade(), ) - .r2dbc() + .execute() } } @@ -1400,7 +1395,7 @@ class DownloadRepositoryTest( .values(itemId3, twoDayAgo, twoDayAgo, twoDayAgo, "desc item 3", Path(""), 1, "video/mp4", 6, ItemStatus.NOT_DOWNLOADED, "item_3", "https://foo.bar.com/item/3", "https://foo.bar.com/item/3", itemCoverId3, podcastId) .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 6, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId), ) - .r2dbc() + .execute() } @@ -1419,7 +1414,7 @@ class DownloadRepositoryTest( ) /* Then */ - val item = query.selectFrom(i).where(i.ID.eq(itemId1)).r2dbc().fetchOne() ?: error("item not found") + val item = query.selectFrom(i).where(i.ID.eq(itemId1)).fetchOne() ?: error("item not found") assertThat(item[i.STATUS]).isEqualTo(ItemStatus.FINISH) assertThat(item[i.LENGTH]).isEqualTo(100L) assertThat(item[i.MIME_TYPE]).isEqualTo("video/avi") @@ -1431,7 +1426,7 @@ class DownloadRepositoryTest( fun `without changing other elements`() { /* Given */ val now = OffsetDateTime.now(fixedDate) - val itemsBefore = query.selectFrom(i).where(i.ID.notEqual(itemId1)).r2dbc().fetch() + val itemsBefore = query.selectFrom(i).where(i.ID.notEqual(itemId1)).fetch() /* When */ repo.finishDownload( @@ -1443,7 +1438,7 @@ class DownloadRepositoryTest( ) /* Then */ - val itemsAfter = query.selectFrom(i).where(i.ID.notEqual(itemId1)).r2dbc().fetch() + val itemsAfter = query.selectFrom(i).where(i.ID.notEqual(itemId1)).fetch() assertThat(itemsBefore).containsAll(itemsAfter) } @@ -1454,7 +1449,7 @@ class DownloadRepositoryTest( truncate(PODCAST).cascade(), truncate(COVER).cascade(), ) - .r2dbc() + .execute() } } @@ -1514,7 +1509,7 @@ class DownloadRepositoryTest( .values(itemId1, 1) .values(itemId2, 2) ) - .r2dbc() + .execute() } @@ -1526,7 +1521,7 @@ class DownloadRepositoryTest( repo.remove(id = itemId1, hasToBeStopped = false) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() .map { it[DOWNLOADING_ITEM.ITEM_ID] to it[DOWNLOADING_ITEM.POSITION] } assertThat(items).contains(itemId2 to 2) } @@ -1538,10 +1533,10 @@ class DownloadRepositoryTest( repo.remove(id = itemId1, hasToBeStopped = true) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).fetch() .map { it[DOWNLOADING_ITEM.ITEM_ID] to it[DOWNLOADING_ITEM.POSITION] } assertThat(items).contains(itemId2 to 2) - val status = query.selectFrom(i).where(i.ID.eq(itemId1)).r2dbc().fetchOne(i.STATUS) + val status = query.selectFrom(i).where(i.ID.eq(itemId1)).fetchOne(i.STATUS) assertThat(status).isEqualTo(ItemStatus.STOPPED) } } @@ -1593,7 +1588,7 @@ class DownloadRepositoryTest( .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -1602,7 +1597,7 @@ class DownloadRepositoryTest( query.batch( truncate(DOWNLOADING_ITEM).cascade() ) - .r2dbc() + .execute() } @@ -1622,14 +1617,14 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() /* When */ repo.moveItemInQueue(itemId3, 0) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION).fetch() assertThat(items[0].itemId).isEqualTo(itemId1) assertThat(items[1].itemId).isEqualTo(itemId3) assertThat(items[2].itemId).isEqualTo(itemId2) @@ -1648,14 +1643,14 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() /* When */ repo.moveItemInQueue(itemId2, 1) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION).fetch() assertThat(items[0].itemId).isEqualTo(itemId1) assertThat(items[1].itemId).isEqualTo(itemId3) assertThat(items[2].itemId).isEqualTo(itemId2) @@ -1674,13 +1669,13 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() /* When */ repo.moveItemInQueue(itemId2, 2) /* Then */ - val items = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION).r2dbc().fetch() + val items = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION).fetch() assertThat(items[0].itemId).isEqualTo(itemId1) assertThat(items[1].itemId).isEqualTo(itemId3) assertThat(items[2].itemId).isEqualTo(itemId4) @@ -1738,7 +1733,7 @@ class DownloadRepositoryTest( .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -1753,7 +1748,7 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() } @@ -1765,7 +1760,7 @@ class DownloadRepositoryTest( /* Then */ val item = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION) - .r2dbc().fetch() + .fetch() .first { it.itemId == itemId2 } assertThat(item.state).isEqualTo(DownloadingState.DOWNLOADING) assertThat(item.position).isEqualTo(2) @@ -1779,7 +1774,7 @@ class DownloadRepositoryTest( /* Then */ val (first, second, third, fourth) = query.selectFrom(DOWNLOADING_ITEM).orderBy(DOWNLOADING_ITEM.POSITION) - .r2dbc().fetch() + .fetch() assertThat(first.itemId).isEqualTo(itemId1) assertThat(first.position).isEqualTo(1) @@ -1847,7 +1842,7 @@ class DownloadRepositoryTest( .values(itemId4, threeDayAgo, threeDayAgo, threeDayAgo, "desc item 4", Path(""), 1, "video/mp4", 30, ItemStatus.NOT_DOWNLOADED, "item_4", "https://foo.bar.com/item/4", "https://foo.bar.com/item/4", itemCoverId4, podcastId) ) - .r2dbc() + .execute() } @@ -1862,7 +1857,7 @@ class DownloadRepositoryTest( .values(itemId3, 3, DownloadingState.WAITING) .values(itemId4, 4, DownloadingState.WAITING) ) - .r2dbc() + .execute() } @@ -1875,7 +1870,7 @@ class DownloadRepositoryTest( /* Then */ val items = query .selectFrom(DOWNLOADING_ITEM) - .r2dbc().fetch() + .fetch() assertThat(items.all { it.state == DownloadingState.WAITING }).isTrue() } @@ -1889,7 +1884,7 @@ class DownloadRepositoryTest( .set(DOWNLOADING_ITEM.STATE, DownloadingState.DOWNLOADING) .where(DOWNLOADING_ITEM.POSITION.`in`(1)) ) - .r2dbc() + .execute() /* When */ @@ -1900,7 +1895,7 @@ class DownloadRepositoryTest( val items = query .selectFrom(DOWNLOADING_ITEM) - .r2dbc().fetch() + .fetch() assertThat(items.all { it.state == DownloadingState.WAITING }).isTrue() } @@ -1914,7 +1909,7 @@ class DownloadRepositoryTest( .set(DOWNLOADING_ITEM.STATE, DownloadingState.DOWNLOADING) .where(DOWNLOADING_ITEM.POSITION.`in`(1, 2)) ) - .r2dbc() + .execute() /* When */ @@ -1924,7 +1919,7 @@ class DownloadRepositoryTest( assertThat(result).isEqualTo(2) val items = query .selectFrom(DOWNLOADING_ITEM) - .r2dbc().fetch() + .fetch() assertThat(items.all { it.state == DownloadingState.WAITING }).isTrue() } @@ -1938,7 +1933,7 @@ class DownloadRepositoryTest( .set(DOWNLOADING_ITEM.STATE, DownloadingState.DOWNLOADING) .where(DOWNLOADING_ITEM.POSITION.`in`(1, 2, 3)) ) - .r2dbc() + .execute() /* When */ @@ -1948,7 +1943,7 @@ class DownloadRepositoryTest( assertThat(result).isEqualTo(3) val items = query .selectFrom(DOWNLOADING_ITEM) - .r2dbc().fetch() + .fetch() assertThat(items.all { it.state == DownloadingState.WAITING }).isTrue() } @@ -1961,7 +1956,7 @@ class DownloadRepositoryTest( update(DOWNLOADING_ITEM) .set(DOWNLOADING_ITEM.STATE, DownloadingState.DOWNLOADING) ) - .r2dbc() + .execute() /* When */ @@ -1971,7 +1966,7 @@ class DownloadRepositoryTest( assertThat(result).isEqualTo(4) val items = query .selectFrom(DOWNLOADING_ITEM) - .r2dbc().fetch() + .fetch() assertThat(items.all { it.state == DownloadingState.WAITING }).isTrue() } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/item/ItemRepositoryTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/item/ItemRepositoryTest.kt index ad8afb4bf..d1de10909 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/item/ItemRepositoryTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/item/ItemRepositoryTest.kt @@ -1,24 +1,22 @@ package com.github.davinkevin.podcastserver.item -import com.github.davinkevin.podcastserver.JooqR2DBCTest import com.github.davinkevin.podcastserver.cover.CoverForCreation import com.github.davinkevin.podcastserver.database.Tables.* import com.github.davinkevin.podcastserver.database.enums.ItemStatus import com.github.davinkevin.podcastserver.entity.Status import com.github.davinkevin.podcastserver.extension.assertthat.assertAll -import com.github.davinkevin.podcastserver.r2dbc import org.assertj.core.api.Assertions.* import org.jooq.DSLContext -import org.jooq.exception.DataAccessException import org.jooq.impl.DSL.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.jooq.JooqTest import org.springframework.context.annotation.Import +import org.springframework.dao.DataIntegrityViolationException import reactor.core.publisher.Flux -import reactor.kotlin.core.publisher.toMono import java.net.URI import java.time.OffsetDateTime import java.time.OffsetDateTime.now @@ -32,7 +30,7 @@ import kotlin.io.path.Path /** * Created by kevin on 2019-02-09 */ -@JooqR2DBCTest +@JooqTest @Import(ItemRepository::class) class ItemRepositoryTest( @Autowired val query: DSLContext, @@ -51,7 +49,7 @@ class ItemRepositoryTest( truncate(WATCH_LIST).cascade(), truncate(WATCH_LIST_ITEMS).cascade(), ) - .r2dbc() + .execute() } @@ -103,7 +101,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .r2dbc() + .execute() } @@ -180,7 +178,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .r2dbc() + .execute() } @@ -249,8 +247,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .toMono() - .block() + .execute() } @@ -368,8 +365,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .toMono() - .block() + .execute() } @@ -443,8 +439,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .toMono() - .block() + .execute() } @@ -466,7 +461,7 @@ class ItemRepositoryTest( assertThat((it.downloadDate == null)).isEqualTo(true) } /* And */ - val numberOfFail = query.selectFrom(ITEM).where(ITEM.ID.eq(id)).toMono().block()?.numberOfFail + val numberOfFail = query.selectFrom(ITEM).where(ITEM.ID.eq(id)).fetchOne()?.numberOfFail assertThat(numberOfFail).isEqualTo(0) } @@ -520,8 +515,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .toMono() - .block() + .execute() } @Test @@ -592,8 +586,8 @@ class ItemRepositoryTest( .values(fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6")) .values(fromString("ccb75276-7a8c-4da9-b4fd-27ccec075c65"), fromString("6936b895-0de6-43f6-acaa-678511d3c37b")) .values(fromString("4dc2ccef-42ab-4733-8945-e3f2849b8083"), fromString("eb355a23-e030-4966-b75a-b70881a8bd08")) - ).toMono() - .block() + ) + .execute() } @Nested @@ -1383,8 +1377,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .toMono() - .block() + .execute() } @Nested @@ -1416,8 +1409,8 @@ class ItemRepositoryTest( podcastId = fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), cover = CoverForCreation(100, 100, URI("http://foo.bar.com/cover/item.jpg")) ) - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count()) - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count()) + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count()) ?: 0 + val numberOfCover = query.selectCount().from(COVER).fetchOne(count()) ?: 0 /* When */ val it = repository.create(item)!! @@ -1443,8 +1436,8 @@ class ItemRepositoryTest( assertThat(it.cover.width).isEqualTo(100) assertThat(it.cover.url).isEqualTo(URI("http://foo.bar.com/cover/item.jpg")) - assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) } } @@ -1470,8 +1463,8 @@ class ItemRepositoryTest( podcastId = fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), cover = CoverForCreation(100, 100, URI("http://foo.bar.com/cover/item.jpg")) ) - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count())!! - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count())!! + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count())!! + val numberOfCover = query.selectCount().from(COVER).fetchOne(count())!! /* When */ val it = repository.create(item)!! @@ -1497,8 +1490,8 @@ class ItemRepositoryTest( assertThat(it.cover.width).isEqualTo(100) assertThat(it.cover.url).isEqualTo(URI("http://foo.bar.com/cover/item.jpg")) - assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) } } @@ -1524,15 +1517,15 @@ class ItemRepositoryTest( podcastId = fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), cover = CoverForCreation(100, 100, URI("http://foo.bar.com/cover/item.jpg")) ) - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count()) - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count()) + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count()) + val numberOfCover = query.selectCount().from(COVER).fetchOne(count()) /* When */ val it = repository.create(item) /* Then */ assertThat(it).isNull() - assertThat(numberOfItem).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) } @Test @@ -1556,8 +1549,8 @@ class ItemRepositoryTest( podcastId = fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), cover = CoverForCreation(100, 100, URI("http://foo.bar.com/cover/item.jpg")) ) - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count()) - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count()) + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count()) + val numberOfCover = query.selectCount().from(COVER).fetchOne(count()) /* When */ val it = repository.create(item) @@ -1565,12 +1558,12 @@ class ItemRepositoryTest( /* Then */ assertThat(it).isNull() - assertThat(numberOfItem).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) val updatedItem = query.selectFrom(ITEM) .where(ITEM.GUID.eq("geekinc.123.mp3")) - .r2dbc().fetch() + .fetch() .firstOrNull() ?: error("item not found") assertThat(updatedItem[ITEM.URL]).isEqualTo("http://another-url.com/geekinc.123.mp3") @@ -1600,8 +1593,8 @@ class ItemRepositoryTest( podcastId = fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), cover = CoverForCreation(100, 100, URI("http://foo.bar.com/cover/item.jpg")) ) - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count()) - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count()) + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count()) ?: 0 + val numberOfCover = query.selectCount().from(COVER).fetchOne(count()) ?: 0 /* When */ val it = repository.create(item)!! @@ -1628,8 +1621,8 @@ class ItemRepositoryTest( assertThat(it.cover.url).isEqualTo(URI("http://foo.bar.com/cover/item.jpg")) } - assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) } @Test @@ -1654,8 +1647,8 @@ class ItemRepositoryTest( podcastId = fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), cover = null ) - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count()) - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count()) + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count()) ?: 0 + val numberOfCover = query.selectCount().from(COVER).fetchOne(count()) ?: 0 /* When */ val it = repository.create(item)!! @@ -1682,8 +1675,8 @@ class ItemRepositoryTest( assertThat(it.cover.url).isEqualTo(URI("http://fake.url.com/geekinc/cover.png")) } - assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem + 1).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover + 1).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) } } @@ -1717,7 +1710,7 @@ class ItemRepositoryTest( assertThatThrownBy { repository.create(item) } /* Then */ - .isInstanceOf(DataAccessException::class.java) + .isInstanceOf(DataIntegrityViolationException::class.java) } @@ -1747,7 +1740,7 @@ class ItemRepositoryTest( assertThatThrownBy { repository.create(item) } /* Then */ - .isInstanceOf(DataAccessException::class.java) + .isInstanceOf(DataIntegrityViolationException::class.java) } } @@ -1819,8 +1812,8 @@ class ItemRepositoryTest( @Test fun `with no specificities`() { /* Given */ - val numberOfItem = query.selectCount().from(ITEM).r2dbc().fetchOne(count())!! - val numberOfCover = query.selectCount().from(COVER).r2dbc().fetchOne(count())!! + val numberOfItem = query.selectCount().from(ITEM).fetchOne(count())!! + val numberOfCover = query.selectCount().from(COVER).fetchOne(count())!! /* When */ val items = repository.create(listOf(item1, item2, item3)) @@ -1828,8 +1821,8 @@ class ItemRepositoryTest( /* Then */ assertThat(items).hasSize(3) - assertThat(numberOfItem + 3).isEqualTo(query.selectCount().from(ITEM).r2dbc().fetchOne(count())) - assertThat(numberOfCover + 3).isEqualTo(query.selectCount().from(COVER).r2dbc().fetchOne(count())) + assertThat(numberOfItem + 3).isEqualTo(query.selectCount().from(ITEM).fetchOne(count())) + assertThat(numberOfCover + 3).isEqualTo(query.selectCount().from(COVER).fetchOne(count())) } } } @@ -1892,8 +1885,7 @@ class ItemRepositoryTest( .values(fromString("0a774613-c867-44df-b7e0-5e5af31f7b56"), "Geek INC 141", "http://fakeurl.com/geekinc.141.mp3", "http://fakeurl.com/geekinc.141.mp3", Path("geekinc.141.mp3"), fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), ItemStatus.PAUSED, fixedDate.minusDays(1), null, fixedDate.minusWeeks(2), 3, fromString("9f050dc4-6a2e-46c3-8276-43098c011e68"), "desc", "video/mp4") .values(fromString("0a674614-c867-44df-b7e0-5e5af31f7b56"), "Geek INC 142", "http://fakeurl.com/geekinc.142.mp3", "http://fakeurl.com/geekinc.142.mp3", Path("geekinc.142.mp3"), fromString("67b56578-454b-40a5-8d55-5fe1a14673e8"), ItemStatus.STARTED, fixedDate.minusDays(1), null, fixedDate.minusWeeks(1), 7, fromString("9f050dc4-6a2e-46c3-8276-43098c011e68"), "desc", "video/mp4") ) - .toMono() - .block() + .execute() } @Test @@ -1909,13 +1901,13 @@ class ItemRepositoryTest( /* Then */ val statuses = query.selectFrom(ITEM).where(ITEM.ID.`in`(ids)) - .r2dbc() + .fetch() .map { it[ITEM.STATUS] } val others = query .selectFrom(ITEM).where(ITEM.ID.notIn(ids)).orderBy(ITEM.ID.asc()) - .r2dbc() + .fetch() .mapNotNull { it[ITEM.STATUS] }.toSet() @@ -1973,8 +1965,7 @@ class ItemRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) ) - .toMono() - .block() + .execute() } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepositoryTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepositoryTest.kt index 3c401bc1e..4fa5400c8 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepositoryTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/playlist/PlaylistRepositoryTest.kt @@ -1,10 +1,8 @@ package com.github.davinkevin.podcastserver.playlist -import com.github.davinkevin.podcastserver.JooqR2DBCTest import com.github.davinkevin.podcastserver.database.Tables.* import com.github.davinkevin.podcastserver.database.enums.ItemStatus import com.github.davinkevin.podcastserver.extension.assertthat.assertAll -import com.github.davinkevin.podcastserver.r2dbc import org.assertj.core.api.Assertions.assertThat import org.jooq.DSLContext import org.jooq.impl.DSL.* @@ -13,6 +11,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.jooq.JooqTest import org.springframework.context.annotation.Import import java.net.URI import java.time.OffsetDateTime @@ -23,7 +22,7 @@ import kotlin.io.path.Path /** * Created by kevin on 2019-07-06 */ -@JooqR2DBCTest +@JooqTest @Import(PlaylistRepository::class) class PlaylistRepositoryTest( @Autowired val query: DSLContext, @@ -84,7 +83,7 @@ class PlaylistRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c857-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c857-44df-b7e0-5e5af31f7b56")) - ).r2dbc().execute() + ).execute() } @Nested @@ -229,7 +228,7 @@ class PlaylistRepositoryTest( assertThat(playlist.items).isEmpty() } - val numberOfPlaylist = query.selectCount().from(WATCH_LIST).r2dbc().fetchOne(count()) + val numberOfPlaylist = query.selectCount().from(WATCH_LIST).fetchOne(count()) assertThat(numberOfPlaylist).isEqualTo(4) } @@ -246,7 +245,7 @@ class PlaylistRepositoryTest( assertThat(playlist.name).isEqualTo("Humour Playlist") assertThat(playlist.items).hasSize(2) } - val numberOfPlaylist = query.selectCount().from(WATCH_LIST).r2dbc().fetchOne(count()) + val numberOfPlaylist = query.selectCount().from(WATCH_LIST).fetchOne(count()) assertThat(numberOfPlaylist).isEqualTo(3) } } @@ -262,8 +261,8 @@ class PlaylistRepositoryTest( repository.deleteById(fromString("9706ba78-2df2-4b37-a573-04367dc6f0ea")) /* Then */ - assertThat(query.selectCount().from(WATCH_LIST).r2dbc().fetchOne(count())).isEqualTo(2) - assertThat(query.selectCount().from(WATCH_LIST_ITEMS).r2dbc().fetchOne(count())).isEqualTo(3) + assertThat(query.selectCount().from(WATCH_LIST).fetchOne(count())).isEqualTo(2) + assertThat(query.selectCount().from(WATCH_LIST_ITEMS).fetchOne(count())).isEqualTo(3) } @Test @@ -274,8 +273,8 @@ class PlaylistRepositoryTest( repository.deleteById(fromString("dc024a30-bd02-11e5-a837-0800200c9a66")) /* Then */ - assertThat(query.selectCount().from(WATCH_LIST).r2dbc().fetchOne(count())).isEqualTo(2) - assertThat(query.selectCount().from(WATCH_LIST_ITEMS).r2dbc().fetchOne(count())).isEqualTo(1) + assertThat(query.selectCount().from(WATCH_LIST).fetchOne(count())).isEqualTo(2) + assertThat(query.selectCount().from(WATCH_LIST_ITEMS).fetchOne(count())).isEqualTo(1) } } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepositoryTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepositoryTest.kt index 4daa16e84..8d144bec6 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepositoryTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/podcast/PodcastRepositoryTest.kt @@ -1,11 +1,9 @@ package com.github.davinkevin.podcastserver.podcast -import com.github.davinkevin.podcastserver.JooqR2DBCTest import com.github.davinkevin.podcastserver.cover.Cover import com.github.davinkevin.podcastserver.database.Tables.* import com.github.davinkevin.podcastserver.database.enums.ItemStatus import com.github.davinkevin.podcastserver.extension.assertthat.assertAll -import com.github.davinkevin.podcastserver.r2dbc import com.github.davinkevin.podcastserver.tag.Tag import org.assertj.core.api.Assertions.assertThat import org.jooq.DSLContext @@ -16,6 +14,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.jooq.JooqTest import org.springframework.context.annotation.Import import java.net.URI import java.time.LocalDate @@ -28,7 +27,7 @@ import kotlin.io.path.Path /** * Created by kevin on 2019-02-16 */ -@JooqR2DBCTest +@JooqTest @Import(PodcastRepository::class) class PodcastRepositoryTest( @Autowired val repository: PodcastRepository, @@ -44,7 +43,7 @@ class PodcastRepositoryTest( truncate(TAG).cascade(), truncate(WATCH_LIST).cascade(), truncate(WATCH_LIST_ITEMS).cascade() - ).r2dbc().execute() + ).execute() } @Nested @@ -68,7 +67,7 @@ class PodcastRepositoryTest( .values(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), fromString("eb355a23-e030-4966-b75a-b70881a8bd08")) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("df801a7a-5630-4442-8b83-0cb36ae94981")) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6")) - ).r2dbc().execute() + ).execute() } @Test @@ -136,7 +135,7 @@ class PodcastRepositoryTest( .values(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), fromString("eb355a23-e030-4966-b75a-b70881a8bd08")) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("df801a7a-5630-4442-8b83-0cb36ae94981")) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6")) - ).r2dbc().execute() + ).execute() } @Test @@ -216,7 +215,7 @@ class PodcastRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a674611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("0a774611-c867-44df-b7e0-5e5af31f7b56")), - ).r2dbc().execute() + ).execute() } @Nested @@ -352,7 +351,7 @@ class PodcastRepositoryTest( .values(fromString("ad109389-9568-4bdb-ae61-6f26bf6ffdf6"), "Another Bar"), insertInto(COVER, COVER.ID, COVER.URL, COVER.WIDTH, COVER.HEIGHT) .values(fromString("8ea0373e-7af6-4e15-b0fd-9ec4b10822ec"), "http://fake.url.com/a-podcast-to-save/cover.png", 100, 100), - ).r2dbc().execute() + ).execute() } @Nested @@ -445,7 +444,7 @@ class PodcastRepositoryTest( insertInto(PODCAST_TAGS, PODCAST_TAGS.PODCASTS_ID, PODCAST_TAGS.TAGS_ID) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("eb355a23-e030-4966-b75a-b70881a8bd08")) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6")) - ).r2dbc().execute() + ).execute() } @Test @@ -641,16 +640,16 @@ class PodcastRepositoryTest( .columns(PODCAST.ID, PODCAST.TITLE, PODCAST.URL, PODCAST.COVER_ID, PODCAST.HAS_TO_BE_DELETED, PODCAST.TYPE) .values(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), "Appload", "http://fake.url.com/appload.rss", fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e1"), false, "RSS") .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), "Geek Inc HD", "http://fake.url.com/geekinc.rss", fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e2"), true, "RSS")) - .r2dbc().execute() + .execute() /* When */ repository.deleteById(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82")) /* Then */ - assertThat(query.selectFrom(COVER).r2dbc().fetch().map { it[COVER.ID] }).containsOnly( + assertThat(query.selectFrom(COVER).fetch().map { it[COVER.ID] }).containsOnly( fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e2") ) - assertThat(query.selectFrom(PODCAST).r2dbc().fetch().map { it[PODCAST.ID] }).containsOnly( + assertThat(query.selectFrom(PODCAST).fetch().map { it[PODCAST.ID] }).containsOnly( fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d") ) } @@ -667,7 +666,7 @@ class PodcastRepositoryTest( .columns(PODCAST.ID, PODCAST.TITLE, PODCAST.URL, PODCAST.COVER_ID, PODCAST.HAS_TO_BE_DELETED, PODCAST.TYPE) .values(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), "Appload", "http://fake.url.com/appload.rss", fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e1"), false, "RSS") .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), "Geek Inc HD", "http://fake.url.com/geekinc.rss", fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e2"), true, "RSS") - ).r2dbc().execute() + ).execute() /* When */ val deletionRequest = repository.deleteById(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d")) @@ -698,13 +697,13 @@ class PodcastRepositoryTest( .values(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), fromString("1c526048-f240-4db9-9526-6cc037fdc851")) .values(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), fromString("2c526048-f240-4db9-9526-6cc037fdc851")) .values(fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("3c526048-f240-4db9-9526-6cc037fdc851")) - ).r2dbc().execute() + ).execute() /* When */ repository.deleteById(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82")) /* Then */ - assertThat(query.selectFrom(PODCAST_TAGS).r2dbc().fetch().map { it[PODCAST_TAGS.PODCASTS_ID] to it[PODCAST_TAGS.TAGS_ID] }).containsOnly( + assertThat(query.selectFrom(PODCAST_TAGS).fetch().map { it[PODCAST_TAGS.PODCASTS_ID] to it[PODCAST_TAGS.TAGS_ID] }).containsOnly( fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d") to fromString("3c526048-f240-4db9-9526-6cc037fdc851") ) } @@ -730,13 +729,13 @@ class PodcastRepositoryTest( .values(fromString("1b83a383-25ec-4aeb-8e82-f317449da37b"), "Item 1", "http://fakeurl.com/item.1.mp3", "http://fakeurl.com/item.1.mp3", fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82"), fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e3"), "audio/mp3") .values(fromString("2b83a383-25ec-4aeb-8e82-f317449da37b"), "Item 2", "http://fakeurl.com/item.2.mp3", "http://fakeurl.com/item.2.mp3", fromString("ef85dcd3-758c-473f-a8fc-b82104762d9d"), fromString("8ea0373e-7af7-4e15-b0fd-9ec4b10822e4"), "audio/mp3") - ).r2dbc().execute() + ).execute() /* When */ repository.deleteById(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82")) /* Then */ - assertThat(query.selectFrom(ITEM).r2dbc().fetch().map { it[ITEM.ID] }).containsOnly( + assertThat(query.selectFrom(ITEM).fetch().map { it[ITEM.ID] }).containsOnly( fromString("2b83a383-25ec-4aeb-8e82-f317449da37b") ) } @@ -772,13 +771,13 @@ class PodcastRepositoryTest( .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("1b83a383-25ec-4aeb-8e82-f317449da37b")) .values(fromString("24248480-bd04-11e5-a837-0800200c9a66"), fromString("1b83a383-25ec-4aeb-8e82-f317449da37b")) .values(fromString("dc024a30-bd02-11e5-a837-0800200c9a66"), fromString("2b83a383-25ec-4aeb-8e82-f317449da37b")) - ).r2dbc().execute() + ).execute() /* When */ repository.deleteById(fromString("214be5e3-a9e0-4814-8ee1-c9b7986bac82")) /* Then */ - assertThat(query.selectFrom(WATCH_LIST_ITEMS).r2dbc().fetch().map{ it[WATCH_LIST_ITEMS.WATCH_LISTS_ID] to it[WATCH_LIST_ITEMS.ITEMS_ID] }).containsOnly( + assertThat(query.selectFrom(WATCH_LIST_ITEMS).fetch().map{ it[WATCH_LIST_ITEMS.WATCH_LISTS_ID] to it[WATCH_LIST_ITEMS.ITEMS_ID] }).containsOnly( fromString("dc024a30-bd02-11e5-a837-0800200c9a66") to fromString("2b83a383-25ec-4aeb-8e82-f317449da37b") ) } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/tag/TagRepositoryTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/tag/TagRepositoryTest.kt index 49989004a..e6bff5a89 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/tag/TagRepositoryTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/tag/TagRepositoryTest.kt @@ -1,8 +1,6 @@ package com.github.davinkevin.podcastserver.tag -import com.github.davinkevin.podcastserver.JooqR2DBCTest import com.github.davinkevin.podcastserver.database.tables.Tag.TAG -import com.github.davinkevin.podcastserver.r2dbc import org.assertj.core.api.Assertions.assertThat import org.jooq.DSLContext import org.jooq.impl.DSL.* @@ -11,13 +9,14 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.jooq.JooqTest import org.springframework.context.annotation.Import import java.util.UUID.fromString /** * Created by kevin on 2019-03-24 */ -@JooqR2DBCTest +@JooqTest @Import(TagRepository::class) class TagRepositoryTest( @Autowired val repository: TagRepository, @@ -34,7 +33,7 @@ class TagRepositoryTest( .values(fromString("ad109389-9568-4bdb-ae61-5f26bf6ffdf6"), "bAr") .values(fromString("ad109389-9568-4bdb-ae61-6f26bf6ffdf6"), "Another Bar") ) - .r2dbc() + .execute() } @@ -111,7 +110,7 @@ class TagRepositoryTest( assertThat(tag.id).isNotNull() assertThat(tag.name).isEqualTo(name) - val numberOfTag = query.selectCount().from(TAG).r2dbc().fetchOne(count()) + val numberOfTag = query.selectCount().from(TAG).fetchOne(count()) assertThat(numberOfTag).isEqualTo(4) } @@ -126,7 +125,7 @@ class TagRepositoryTest( assertThat(tag.id).isNotNull() assertThat(tag.name).isEqualTo(name) - val numberOfTag = query.selectCount().from(TAG).r2dbc().fetchOne(count()) + val numberOfTag = query.selectCount().from(TAG).fetchOne(count()) assertThat(numberOfTag).isEqualTo(3) } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/francetv/FranceTvUpdaterTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/francetv/FranceTvUpdaterTest.kt index f0441be3d..e1ebf3e9e 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/francetv/FranceTvUpdaterTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/francetv/FranceTvUpdaterTest.kt @@ -4,7 +4,6 @@ import com.github.davinkevin.podcastserver.MockServer import com.github.davinkevin.podcastserver.extension.assertthat.assertAll import com.github.davinkevin.podcastserver.fileAsString import com.github.davinkevin.podcastserver.remapRestClientToMockServer -import com.github.davinkevin.podcastserver.remapToMockServer import com.github.davinkevin.podcastserver.service.image.CoverInformation import com.github.davinkevin.podcastserver.service.image.ImageService import com.github.davinkevin.podcastserver.update.updaters.PodcastToUpdate @@ -51,7 +50,6 @@ class FranceTvUpdaterTest( @Bean fun remapFranceTvToMock() = remapRestClientToMockServer("www.france.tv") @Bean fun remapApiToMock() = remapRestClientToMockServer("player.webservices.francetelevisions.fr") @Bean fun imageMockServer() = remapRestClientToMockServer("assets.webservices.francetelevisions.fr") - @Bean fun assetsOnFranceTv() = remapToMockServer("www.france.tv") @Bean fun fixedClock(): Clock = Clock.fixed(fixedDate.toInstant(), ZoneId.of("UTC")) } diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/youtube/YoutubeByApiUpdaterTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/youtube/YoutubeByApiUpdaterTest.kt index 05042167f..8fd855b5e 100644 --- a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/youtube/YoutubeByApiUpdaterTest.kt +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/update/updaters/youtube/YoutubeByApiUpdaterTest.kt @@ -24,9 +24,6 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Import import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit.jupiter.SpringExtension -import reactor.core.publisher.Mono -import reactor.kotlin.core.publisher.toMono -import reactor.test.StepVerifier import java.net.URI import java.util.* @@ -354,34 +351,5 @@ class YoutubeByApiUpdaterTest( assertThat(type.name).isEqualTo("Youtube") assertThat(type.key).isEqualTo("Youtube") } - - data class CompositeType(val idx: Int, val other: Int) { - companion object { - fun from(idx: Int): CompositeType { - val i = idx * idx - val other = i.toString().length - - return CompositeType(i, other) - } - } - } - @Test - fun `should test`() { - /* Given */ - val p = Mono.just(2) - .map { CompositeType(it, it.toString().length) } - .expand { CompositeType.from(it.idx).toMono() } - .map { it.other } - .take(4) - /* When */ - StepVerifier.create(p) - /* Then */ - .expectNext(1) - .expectNext(1) - .expectNext(2) - .expectNext(3) - - .verifyComplete() - } } diff --git a/backend/src/test/resources/application.yml b/backend/src/test/resources/application.yml index f53fc9146..a843d190f 100644 --- a/backend/src/test/resources/application.yml +++ b/backend/src/test/resources/application.yml @@ -1,9 +1,7 @@ spring: - datasource: - username: podcast-server-user - password: nAAdo5wNs7WEF1UxUobpJDfS9Si62PHa - url: jdbc:postgresql://postgres:5432/podcast-server + jooq: + sql-dialect: postgres main: banner-mode: "off" threads: diff --git a/backend/src/test/resources/logback-test.xml b/backend/src/test/resources/logback-test.xml index b6ae6c2ef..39fcd5c08 100644 --- a/backend/src/test/resources/logback-test.xml +++ b/backend/src/test/resources/logback-test.xml @@ -4,6 +4,4 @@ - - diff --git a/distribution/kubernetes/base/backend.yaml b/distribution/kubernetes/base/backend.yaml index f21fcd15e..5b32615c9 100644 --- a/distribution/kubernetes/base/backend.yaml +++ b/distribution/kubernetes/base/backend.yaml @@ -150,16 +150,16 @@ spec: - name: http-port containerPort: 8080 protocol: TCP - livenessProbe: - failureThreshold: 10 - timeoutSeconds: 6 - httpGet: - path: /actuator/health/liveness - port: 8080 - readinessProbe: - httpGet: - path: /actuator/health/readiness - port: 8080 +# livenessProbe: +# failureThreshold: 10 +# timeoutSeconds: 6 +# httpGet: +# path: /actuator/health/liveness +# port: 8080 +# readinessProbe: +# httpGet: +# path: /actuator/health/readiness +# port: 8080 --- apiVersion: batch/v1 kind: CronJob