diff --git a/.github/workflows/pull-request-checks.yml b/.github/workflows/pull-request-checks.yml new file mode 100644 index 0000000..73c4116 --- /dev/null +++ b/.github/workflows/pull-request-checks.yml @@ -0,0 +1,21 @@ +name: Testing + +on: + pull_request: + types: + - opened + - synchronize + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Release in Maven Central + run: | + ./gradlew test \ No newline at end of file diff --git a/README.md b/README.md index 4abe27a..d2628f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ![KabbitMQ](https://github.com/user-attachments/assets/bc22917b-d6bd-4f34-8775-707e575677a0)abbitMQ -![Deployment Status](https://github.com/DamirDenis-Tudor/ktor-server-rabbitmq/actions/workflows/deployment.yml/badge.svg) +![Deployment Status](https://github.com/DamirDenis-Tudor/ktor-server-rabbitmq/actions/workflows/deployment.yml/badge.svg) | ![Pull Request Checks](https://github.com/DamirDenis-Tudor/ktor-server-rabbitmq/actions/workflows/pull-request-checks.yml/badge.svg) ## Overview diff --git a/build.gradle.kts b/build.gradle.kts index 752a795..d7e3eac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,9 +63,16 @@ dependencies { tasks { test { useJUnitPlatform() + testLogging { + events("passed", "skipped", "failed") + showCauses = true + showStackTraces = true + } } } + + tasks.register("javadocJar") { archiveClassifier.set("javadoc") from(tasks["javadoc"]) diff --git a/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/Demo.kt b/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/Demo.kt index c8bf6ba..1faf504 100644 --- a/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/Demo.kt +++ b/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/Demo.kt @@ -47,7 +47,7 @@ internal fun Application.module() { basicConsume { autoAck = true queue = "demo-queue" - deliveryCallback { tag, message -> + deliverCallback { tag, message -> } } diff --git a/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/builders/BasicConsumeBuilder.kt b/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/builders/BasicConsumeBuilder.kt index 3360c16..90d112b 100644 --- a/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/builders/BasicConsumeBuilder.kt +++ b/src/main/kotlin/io/github/damir/denis/tudor/ktor/server/rabbitmq/builders/BasicConsumeBuilder.kt @@ -58,7 +58,7 @@ class BasicConsumeBuilder( } @RabbitDslMarker - inline fun deliveryCallback(crossinline callback: suspend (tag: Long, message: T) -> Unit) { + inline fun deliverCallback(crossinline callback: suspend (tag: Long, message: T) -> Unit) { connectionManager.coroutineScope.launch(dispatcher) { receiverChannel.consumeAsFlow().collect { (deliveryTag, message) -> callback(deliveryTag, Json.decodeFromString(message)) diff --git a/src/test/kotlin/InstallTests.kt b/src/test/kotlin/InstallTests.kt index 6918a01..45e20d7 100644 --- a/src/test/kotlin/InstallTests.kt +++ b/src/test/kotlin/InstallTests.kt @@ -40,17 +40,38 @@ class InstallTests { } @Test - fun `test install rabbitmq with attempts and delay lower than 0`() = testApplication { + fun `test install rabbitmq with attemptDelay lower than 0`() = testApplication { application{ assertFailsWith { install(RabbitMQ) { attemptDelay = -1 + } + } + } + } + + @Test + fun `test install rabbitmq with connectionAttempts and delay lower than 0`() = testApplication { + application{ + assertFailsWith { + install(RabbitMQ) { connectionAttempts = -1 } } } } + @Test + fun `test install rabbitmq with dispatcherThreadPollSize and delay lower than 0`() = testApplication { + application{ + assertFailsWith { + install(RabbitMQ) { + dispatcherThreadPollSize = -1 + } + } + } + } + @Test fun `test install rabbitmq with uri empty`() = testApplication { application{ @@ -67,9 +88,11 @@ class InstallTests { application{ assertFailsWith { install(RabbitMQ) { - uri = "" + defaultConnectionName = "" } } } } + + } diff --git a/src/test/kotlin/OperationsTests.kt b/src/test/kotlin/OperationsTests.kt index ee442f5..df7fd2d 100644 --- a/src/test/kotlin/OperationsTests.kt +++ b/src/test/kotlin/OperationsTests.kt @@ -121,16 +121,12 @@ class OperationsTests { } } - assertEquals(messageCount { queue = "test-queue" }, 10) + assertEquals(messageCount { queue = "test-queue" }.getOrNull(), 10) basicConsume { queue = "test-queue" autoAck = false deliverCallback { tag, message -> - /* process message */ - // ... - - /* simulate something went wrong */ basicReject { deliveryTag = tag requeue = false @@ -140,7 +136,7 @@ class OperationsTests { Thread.sleep(2_000) - assertEquals(messageCount { queue = "dlq" }, 10) + assertEquals(messageCount { queue = "dlq" }.getOrNull(), 10) basicConsume { queue = "dlq" @@ -152,7 +148,7 @@ class OperationsTests { Thread.sleep(2_000) - assertEquals(messageCount { queue = "dlq" }, 0) + assertEquals(messageCount { queue = "dlq" }.getOrNull(), 0) } } }