Skip to content

Commit

Permalink
Merge branch 'dev' into renovate/all-minor-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
vendelieu authored Dec 27, 2024
2 parents 673d9ae + dc07b70 commit 0068433
Show file tree
Hide file tree
Showing 63 changed files with 436 additions and 320 deletions.
25 changes: 6 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
@file:Suppress("PropertyName")

import kotlinx.validation.ExperimentalBCVApi
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import java.time.LocalDate

plugins {
alias(libs.plugins.deteKT)
alias(libs.plugins.dokka)
alias(libs.plugins.ktlinter)
alias(libs.plugins.kotlin.binvalid)
alias(libs.plugins.kover)
id("publish")
dokka
publish
}

group = "eu.vendeli.re.this"
Expand All @@ -33,7 +30,6 @@ configureKotlin {

jvmTest.dependencies {
implementation(libs.kotlin.reflect)
implementation(libs.test.kotest.junit5)
implementation(libs.test.kotest.assertions)
implementation(libs.logback)
implementation("com.redis:testcontainers-redis:1.7.0") {
Expand All @@ -44,25 +40,16 @@ configureKotlin {
implementation("commons-io:commons-io:2.18.0")
implementation("org.apache.commons:commons-compress:1.27.1")
implementation("com.fasterxml.woodstox:woodstox-core:7.1.0")

implementation(libs.kotlin.junit)
implementation(libs.junit.api)
runtimeOnly(libs.junit.engine)
}
}
}

buildscript { dependencies.classpath(libs.dokka.base) }

tasks {
withType<Test> { useJUnitPlatform() }
dokkaHtml.configure {
outputDirectory = layout.buildDirectory.asFile.orNull?.resolve("dokka")
dokkaSourceSets {
collectionSchema.elements.forEach { _ -> moduleName = "re.this" }
}
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
customAssets = listOf(rootDir.resolve("assets/logo-icon.svg"))
homepageLink = "https://github.com/vendelieu/re.this"
footerMessage = "© ${LocalDate.now().year} Vendelieu"
}
}
}

@OptIn(ExperimentalBCVApi::class)
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
implementation(libs.kotlin.gradlePlugin)
implementation(libs.dokka)
implementation(libs.publisher)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
object EnvParams {
object CommonParams {
val releaseMode get() = System.getenv("release") != null
val metadataOnly: Boolean get() = System.getenv("meta_only") != null

const val REPO_URL = "https://github.com/vendelieu/re.this"
}
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/CompilationConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum class HostType {
}

fun KotlinTarget.isCompilationAllowed(): Boolean {
if ((name == KotlinMetadataTarget.METADATA_TARGET_NAME) || !EnvParams.releaseMode) {
if ((name == KotlinMetadataTarget.METADATA_TARGET_NAME) || !CommonParams.releaseMode) {
return true
}

Expand Down Expand Up @@ -73,9 +73,9 @@ fun AbstractPublishToMaven.isAllowed(targets: NamedDomainObjectCollection<Kotlin
val publicationName: String? = publication?.name

return when {
publicationName == "kotlinMultiplatform" -> !EnvParams.releaseMode || EnvParams.metadataOnly
publicationName == "kotlinMultiplatform" -> !CommonParams.releaseMode || CommonParams.metadataOnly

EnvParams.metadataOnly -> false
CommonParams.metadataOnly -> false

publicationName != null -> {
val target = targets.find { it.name.startsWith(publicationName) }
Expand Down
22 changes: 22 additions & 0 deletions buildSrc/src/main/kotlin/dokka.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import CommonParams.REPO_URL
import java.time.LocalDate

plugins {
id("org.jetbrains.dokka")
}
dokka {
moduleName = "re.this"
dokkaSourceSets.configureEach {
sourceRoots.setFrom(project.projectDir.resolve("src/$name/kotlin"))
sourceLink {
localDirectory.set(file("src/$name/kotlin"))
remoteUrl("$REPO_URL/blob/master/src/$name/kotlin")
remoteLineSuffix.set("#L")
}
}
pluginsConfiguration.html {
customAssets.from(rootDir.resolve("assets/logo-icon.svg"))
footerMessage.set("© ${LocalDate.now().year} Vendelieu")
homepageLink.set(REPO_URL)
}
}
9 changes: 5 additions & 4 deletions buildSrc/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CommonParams.REPO_URL
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.SonatypeHost
Expand All @@ -17,7 +18,7 @@ mavenPublishing {
val javaDoc = if (releaseMode) {
signAllPublications()

JavadocJar.Dokka("dokkaHtml")
JavadocJar.Dokka("dokkaGenerate")
} else JavadocJar.Empty()

configure(KotlinMultiplatform(javaDoc, true))
Expand All @@ -26,7 +27,7 @@ mavenPublishing {
name = project.name
description = "Kotlin Multiplatform Redis Client: coroutine-based, DSL-powered, and easy to use."
inceptionYear = "2024"
url = "https://github.com/vendelieu/re.this"
url = REPO_URL

licenses {
license {
Expand All @@ -45,11 +46,11 @@ mavenPublishing {
scm {
connection = "scm:git:github.com/vendelieu/re.this.git"
developerConnection = "scm:git:ssh://github.com/vendelieu/re.this.git"
url = "https://github.com/vendelieu/re.this.git"
url = "$REPO_URL.git"
}
issueManagement {
system = "Github"
url = "https://github.com/vendelieu/re.this/issues"
url = "$REPO_URL/issues"
}
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kotlin.code.style=official
kotlin.native.ignoreDisabledTargets=true
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ binvalid = "0.17.0"
kover = "0.9.0"

kotest = "5.9.1"
junit = "5.11.4"
logback = "1.5.15"

[libraries]
Expand All @@ -25,18 +26,19 @@ ktor-network-tls = { module = "io.ktor:ktor-network-tls", version.ref = "ktor" }
bignum = { module = "com.ionspin.kotlin:bignum", version.ref = "bignum" }

coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
dokka-base = { module = "org.jetbrains.dokka:dokka-base", version.ref = "dokka" }
dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
publisher = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "publisher" }

# testing
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
test-kotest-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotlin-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
test-kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }

[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
ktlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter" }
deteKT = { id = "io.gitlab.arturbosch.detekt", version.ref = "deteKT" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
Expand Down
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/eu/vendeli/rethis/ReThis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eu.vendeli.rethis.utils.Const.DEFAULT_PORT
import io.ktor.network.sockets.*
import io.ktor.util.logging.*
import io.ktor.utils.io.*
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.io.Buffer
Expand All @@ -32,6 +33,7 @@ class ReThis(
internal val logger = KtorSimpleLogger("eu.vendeli.rethis.ReThis")
internal val cfg: ClientConfiguration = ClientConfiguration().apply(configurator)
internal val rootJob = SupervisorJob()
internal val rethisCoScope = rootJob + CoroutineName("ReThis")
internal val connectionPool by lazy { ConnectionPool(this, address.socket).also { it.prepare() } }

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class ConnectionPool(

private val job = SupervisorJob(client.rootJob)
private val connections = Channel<Connection>(client.cfg.poolConfiguration.poolSize)
private val selector = SelectorManager(client.cfg.poolConfiguration.dispatcher + job)
private val selector = SelectorManager(client.cfg.poolConfiguration.dispatcher + job + CoroutineName("ReThis Pool"))

internal suspend fun createConn(): Connection {
logger.trace("Creating connection to $address")
Expand Down
4 changes: 1 addition & 3 deletions src/jvmTest/kotlin/eu/vendeli/rethis/ReThisTestCtx.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package eu.vendeli.rethis

import com.redis.testcontainers.RedisContainer
import io.kotest.core.spec.style.AnnotationSpec
import io.ktor.network.sockets.*
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import org.testcontainers.utility.DockerImageName

abstract class ReThisTestCtx(
withJsonModule: Boolean = false,
) : AnnotationSpec() {
) {
protected val targetDb = 1L
protected val timestamp: Instant get() = Clock.System.now()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package eu.vendeli.rethis.tests

import eu.vendeli.rethis.ReThisTestCtx
import eu.vendeli.rethis.commands.ping
import io.kotest.core.spec.IsolationMode
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test

class ClientConnectionTest : ReThisTestCtx() {
override fun isolationMode(): IsolationMode = IsolationMode.InstancePerLeaf

@Test
suspend fun `client disconnect test`() {
fun `client disconnect test`(): Unit = runBlocking {
client.ping()

client.isDisconnected shouldBe false
Expand All @@ -19,7 +19,7 @@ class ClientConnectionTest : ReThisTestCtx() {
}

@Test
suspend fun `client reconnect test`() {
fun `client reconnect test`(): Unit = runBlocking {
client.ping()

client.isDisconnected shouldBe false
Expand Down
12 changes: 7 additions & 5 deletions src/jvmTest/kotlin/eu/vendeli/rethis/tests/PipeliningTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import eu.vendeli.rethis.types.core.PlainString
import eu.vendeli.rethis.types.core.RespVer
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test

class PipeliningTest : ReThisTestCtx() {
@Test
suspend fun `pipelining test`() {
fun `pipelining test`(): Unit = runBlocking {
val v2Client = ReThis(redis.host, redis.firstMappedPort, protocol = RespVer.V2) {
pool {
poolSize = 1
Expand All @@ -30,7 +32,7 @@ class PipeliningTest : ReThisTestCtx() {
}

@Test
suspend fun `pipelining + transaction test`() {
fun `pipelining + transaction test`(): Unit = runBlocking {
client
.transaction {
client.pipeline {
Expand All @@ -45,7 +47,7 @@ class PipeliningTest : ReThisTestCtx() {
}

@Test
suspend fun `transaction + pipeline test`() {
fun `transaction + pipeline test`(): Unit = runBlocking {
client
.pipeline {
client.transaction {
Expand All @@ -65,7 +67,7 @@ class PipeliningTest : ReThisTestCtx() {
}

@Test
suspend fun `nested pipeline test`() {
fun `nested pipeline test`(): Unit = runBlocking {
client
.pipeline {
set("test1", "testv1")
Expand All @@ -85,7 +87,7 @@ class PipeliningTest : ReThisTestCtx() {
}

@Test
suspend fun `nested transaction test`() {
fun `nested transaction test`(): Unit = runBlocking {
client
.transaction {
set("test1", "testv1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ import io.kotest.matchers.ints.shouldBeGreaterThan
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test

class ConnectionCommandsTest : ReThisTestCtx() {
@Test
fun `test HELLO command with default parameters`() = runTest {
fun `test HELLO command with default parameters`(): Unit = runBlocking {
client.hello().shouldNotBeNull().size shouldBeGreaterThan 1
}

@Test
fun `test HELLO command with proto parameter`() = runTest {
fun `test HELLO command with proto parameter`(): Unit = runBlocking {
client.hello(proto = 2).shouldNotBeNull()["proto"] shouldBe Int64(2)
}

@Test
fun `test HELLO command with username and password parameters`() = runTest {
fun `test HELLO command with username and password parameters`(): Unit = runBlocking {
shouldThrow<ReThisException> {
client.hello(
username = "test",
Expand All @@ -35,31 +36,31 @@ class ConnectionCommandsTest : ReThisTestCtx() {
}

@Test
fun `test HELLO command with name parameter`() = runTest {
fun `test HELLO command with name parameter`(): Unit = runBlocking {
client.hello(name = "test").shouldNotBeNull().size shouldBeGreaterThan 1
}

@Test
fun `test PING command with default message`() = runTest {
fun `test PING command with default message`(): Unit = runBlocking {
val response = client.ping()
response shouldBe "PONG"
}

@Test
fun `test PING command with custom message`() = runTest {
fun `test PING command with custom message`(): Unit = runBlocking {
val message = "Hello, Redis!"
val response = client.ping(message)
response shouldBe message
}

@Test
fun `test SELECT command with valid database index`() = runTest {
fun `test SELECT command with valid database index`(): Unit = runBlocking {
val response = client.select(0)
response shouldBe "OK"
}

@Test
fun `test SELECT command with invalid database index`() = runTest {
fun `test SELECT command with invalid database index`(): Unit = runBlocking {
shouldThrow<ReThisException> {
client.select(100)
}
Expand Down
Loading

0 comments on commit 0068433

Please sign in to comment.