@@ -7,10 +7,6 @@ import com.viartemev.thewhiterabbit.channel.ConfirmChannel
77import com.viartemev.thewhiterabbit.channel.createConfirmChannel
88import com.viartemev.thewhiterabbit.publisher.ConfirmPublisher
99import com.viartemev.thewhiterabbit.publisher.OutboundMessage
10- import com.viartemev.thewhiterabbit.queue.DeleteQueueSpecification
11- import com.viartemev.thewhiterabbit.queue.QueueSpecification
12- import com.viartemev.thewhiterabbit.queue.declareQueue
13- import com.viartemev.thewhiterabbit.queue.deleteQueue
1410import kotlinx.coroutines.awaitAll
1511import kotlinx.coroutines.runBlocking
1612import org.openjdk.jmh.annotations.Benchmark
@@ -40,39 +36,31 @@ open class ConfirmPublisherBenchmark {
4036 @Param(" 1" , " 10" , " 100" , " 1000" , " 10000" , " 100000" )
4137 private var numberOfMessages: Int = 0
4238 private val testQueueName = " jmh_test_queue"
39+ private val factory = ConnectionFactory ().apply { useNio() }
4340 private lateinit var connection: Connection
4441 private lateinit var channel: ConfirmChannel
4542 private lateinit var publisher: ConfirmPublisher
4643 private lateinit var messages: List <OutboundMessage >
4744
48- @Setup
49- fun setupConnection () {
50- val factory = ConnectionFactory ().apply { useNio() }
51- connection = factory.newConnection()
52- }
53-
5445 @Setup(Level .Iteration )
5546 fun setup () {
47+ connection = factory.newConnection()
5648 channel = connection.createConfirmChannel()
57- runBlocking { channel.declareQueue( QueueSpecification ( testQueueName)) }
49+ channel.queueDeclare( testQueueName, false , false , false , mapOf ())
5850 publisher = channel.publisher()
5951 messages = (1 .. numberOfMessages).map { createMessage() }
6052 }
6153
6254 @TearDown(Level .Iteration )
6355 fun tearDownPublisher () {
64- runBlocking { channel.deleteQueue( DeleteQueueSpecification ( testQueueName)) }
56+ channel.queueDelete( testQueueName)
6557 channel.close()
66- }
67-
68- @TearDown
69- fun tearDown () {
7058 connection.close()
7159 }
7260
7361 @Benchmark
7462 fun sendWithPublishConfirm (blackhole : Blackhole ) = runBlocking {
75- blackhole.consume(publisher.asyncPublishWithConfirm( messages).awaitAll())
63+ blackhole.consume(publisher.publishWithConfirmAsync(messages = messages).awaitAll())
7664 }
7765
7866 private fun createMessage (): OutboundMessage = OutboundMessage (" " , testQueueName, MessageProperties .MINIMAL_BASIC , " " )
0 commit comments