Skip to content

Commit

Permalink
Remove useless testss
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemyev Vyacheslav committed Nov 2, 2023
1 parent 9ad89dc commit 3e7afe6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 110 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ configure(rootProject) {
testImplementation("org.apache.httpcomponents.client5:httpclient5:$httpclient_version")
testImplementation("org.testcontainers:testcontainers:$testcontainers_version")
testImplementation("org.testcontainers:junit-jupiter:$testcontainers_version")
testImplementation("com.nhaarman:mockito-kotlin:1.6.0")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
testImplementation("org.mockito:mockito-inline:2.13.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.viartemev.thewhiterabbit.publisher

import com.rabbitmq.client.Channel
import com.viartemev.thewhiterabbit.common.cancelOnIOException
import kotlinx.coroutines.suspendCancellableCoroutine
import mu.KotlinLogging
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -31,13 +30,11 @@ class ConfirmPublisher internal constructor(private val channel: Channel) {
*/
suspend fun publishWithConfirm(message: OutboundMessage): Boolean {
val messageSequenceNumber = channel.nextPublishSeqNo
logger.debug { "The message Sequence Number: $messageSequenceNumber" }
logger.debug { "Generated message Sequence Number: $messageSequenceNumber" }
return suspendCancellableCoroutine { continuation ->
continuations[messageSequenceNumber] = continuation
continuation.invokeOnCancellation { continuations.remove(messageSequenceNumber) }
cancelOnIOException(continuation) {
message.run { channel.basicPublish(exchange, routingKey, properties, msg) }
}
continuations[messageSequenceNumber] = continuation
message.apply { channel.basicPublish(exchange, routingKey, properties, msg) }
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,46 @@ import com.viartemev.thewhiterabbit.channel.publish
import com.viartemev.thewhiterabbit.queue.QueueSpecification
import com.viartemev.thewhiterabbit.queue.declareQueue
import com.viartemev.thewhiterabbit.utils.createMessage
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class PublisherIntegrationTest : AbstractTestContainersTest() {

@Test
fun `test one message publishing`() {
fun `test one message publishing`(): Unit = runBlocking {
factory.newConnection().use {
val connection = it
runBlocking {
connection.confirmChannel {
val queue = declareQueue(QueueSpecification("")).queue
publish {
val message = createMessage(queue = queue, body = "Hello")
val ack = publishWithConfirm(message)
assertTrue { ack }
}
delay(5000)
val info = httpRabbitMQClient.getQueue(DEFAULT_VHOST, queue)
assertEquals(queue, info.name)
assertEquals(1, info.messagesReady)
connection.confirmChannel {
val queue = declareQueue(QueueSpecification("")).queue
publish {
val message = createMessage(queue = queue, body = "Hello")
val ack = publishWithConfirm(message)
assertTrue { ack }
}
delay(5000)
val info = httpRabbitMQClient.getQueue(DEFAULT_VHOST, queue)
assertEquals(queue, info.name)
assertEquals(1, info.messagesReady)
}
}
}

@Test
fun `test n-messages publishing manually`() {
val times = 10
fun `test n-messages publishing manually`(): Unit = runBlocking {
factory.newConnection().use { connection ->
runBlocking {
connection.confirmChannel {
val queue = declareQueue(QueueSpecification("")).queue
publish {
val acks = coroutineScope {
(1..times).map {
async {
publishWithConfirm(createMessage(queue = queue, body = "Hello #$it"))
}
}.awaitAll()
}
assertTrue { acks.all { it } }
}
connection.confirmChannel {
val queue = declareQueue(QueueSpecification("")).queue
val publisher = this.publisher()
val res1 = async(Dispatchers.IO) {
publisher.publishWithConfirm(createMessage(queue = queue, body = "Hello #1"))
}
val res2 = async(Dispatchers.IO) {
publisher.publishWithConfirm(createMessage(queue = queue, body = "Hello #2"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ const val PUBLISHER_EXCHANGE_NAME = ""
const val PUBLISHER_QUEUE_NAME = "test_queue"
const val TIMES = 100_000

fun main() {
fun main() = runBlocking {
val connectionFactory = ConnectionFactory().apply { useNio() }
val connection = connectionFactory.newConnection()
runBlocking {
connection.confirmChannel {
publish {
coroutineScope {
val messages = (1..TIMES).map { createMessage("") }
publishWithConfirmAsync(this.coroutineContext, messages).awaitAll()
}
connection.confirmChannel {
publish {
coroutineScope {
val messages = (1..TIMES).map { createMessage("") }.map { publishWithConfirm(it) }
}
}
}
Expand Down

0 comments on commit 3e7afe6

Please sign in to comment.