Skip to content

Commit

Permalink
Command-line args for SocketPoolTest main().
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox committed Oct 15, 2024
1 parent af1c1e6 commit 4403e8a
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/test/kotlin/org/ice4j/socket/SocketPoolTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,30 @@ class SocketPoolTest : ShouldSpec() {
}

companion object {
private fun sendTimeOnAllSockets(pool: SocketPool, numThreads: Int = pool.numSockets): Duration {
private fun sendTimeOnAllSockets(
pool: SocketPool,
numThreads: Int = pool.numSockets,
numPackets: Int = Sender.NUM_PACKETS
): Duration {
val threads = mutableListOf<Thread>()
Sender.reset(numThreads)
repeat(numThreads) {
val thread = Thread(Sender(Sender.NUM_PACKETS / numThreads, pool, loopbackDiscard))
val thread = Thread(Sender(numPackets / numThreads, pool, loopbackDiscard))
threads.add(thread)
thread.start()
}
threads.forEach { it.join() }
return Sender.elapsed
}

fun testSendingOnce(numSockets: Int, numThreads: Int, warmup: Boolean = false) {
private fun testSendingOnce(
numSockets: Int,
numThreads: Int,
numPackets: Int = Sender.NUM_PACKETS,
warmup: Boolean = false
) {
val pool = SocketPool(loopbackAny, numSockets)
val elapsed = sendTimeOnAllSockets(pool, numThreads)
val elapsed = sendTimeOnAllSockets(pool, numThreads, numPackets)
if (!warmup) {
println(
"Send ${Sender.NUM_PACKETS} packets on $numSockets sockets on $numThreads threads " +
Expand Down Expand Up @@ -229,7 +238,18 @@ class SocketPoolTest : ShouldSpec() {

@JvmStatic
fun main(args: Array<String>) {
testSending()
if (args.size >= 2) {
val numThreads = args[0].toInt()
val numSockets = args[1].toInt()
val numPackets = if (args.size > 2) {
args[2].toInt()
} else {
Sender.NUM_PACKETS
}
testSendingOnce(numThreads = numThreads, numSockets = numSockets, numPackets = numPackets)
} else {
testSending()
}
}
}
}

0 comments on commit 4403e8a

Please sign in to comment.