diff --git a/src/test/scala/tlschannel/AllocationTest.java b/src/test/scala/tlschannel/AllocationTest.java index 0a8b4118..efaf43cc 100644 --- a/src/test/scala/tlschannel/AllocationTest.java +++ b/src/test/scala/tlschannel/AllocationTest.java @@ -24,33 +24,12 @@ public static void main(String[] args) { MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); - SocketPair socketPair1 = factory.nioNio( - Option.apply(null), - Option.apply(null), - Option.apply(null), - Option.apply(null), - Option.apply(null), - true, - false, - Option.apply(null)); - SocketPair socketPair2 = factory.nioNio( - Option.apply(null), - Option.apply(null), - Option.apply(null), - Option.apply(null), - Option.apply(null), - true, - false, - Option.apply(null)); - SocketPair socketPair3 = factory.nioNio( - Option.apply(null), - Option.apply(null), - Option.apply(null), - Option.apply(null), - Option.apply(null), - true, - false, - Option.apply(null)); + SocketPair socketPair1 = + factory.nioNio(Option.apply(null), Option.apply(null), true, false, Option.apply(null)); + SocketPair socketPair2 = + factory.nioNio(Option.apply(null), Option.apply(null), true, false, Option.apply(null)); + SocketPair socketPair3 = + factory.nioNio(Option.apply(null), Option.apply(null), true, false, Option.apply(null)); // do a "warm-up" loop, in order to not count anything statically allocated Loops.halfDuplex(socketPair1, 10000, false, false); diff --git a/src/test/scala/tlschannel/BlockingTest.scala b/src/test/scala/tlschannel/BlockingTest.scala index 29534140..75f9bf1f 100644 --- a/src/test/scala/tlschannel/BlockingTest.scala +++ b/src/test/scala/tlschannel/BlockingTest.scala @@ -6,6 +6,8 @@ import tlschannel.helpers.TestUtil.LazyListWithTakeWhileInclusive import tlschannel.helpers.SslContextFactory import tlschannel.helpers.SocketPairFactory import tlschannel.helpers.Loops +import tlschannel.helpers.SocketPairFactory.ChunkSizeConfig +import tlschannel.helpers.SocketPairFactory.ChuckSizes import java.util import java.util.logging.Logger @@ -31,10 +33,12 @@ class BlockingTest { s"testHalfDuplexWireRenegotiations() - size1=$size1, size2=$size2", () => { val socketPair = factory.nioNio( - internalClientChunkSize = Some(size1), - externalClientChunkSize = Some(size2), - internalServerChunkSize = Some(size1), - externalServerChunkSize = Some(size2) + chunkSizeConfig = Some( + ChunkSizeConfig( + ChuckSizes(Some(size1), Some(size2)), + ChuckSizes(Some(size1), Some(size2)) + ) + ) ) Loops.halfDuplex(socketPair, dataSize, renegotiation = true) println(f"$size1%5d -eng-> $size2%5d -net-> $size1%5d -eng-> $size2%5d") @@ -54,11 +58,13 @@ class BlockingTest { s"testFullDuplex() - size1=$size1,size2=$size2", () => { logger.fine(() => s"Testing sizes: size1=$size1,size2=$size2") - val socketPair = factory.nioNio( - internalClientChunkSize = Some(size1), - externalClientChunkSize = Some(size2), - internalServerChunkSize = Some(size1), - externalServerChunkSize = Some(size2) + val socketPair = factory.nioNio(chunkSizeConfig = + Some( + ChunkSizeConfig( + ChuckSizes(Some(size1), Some(size2)), + ChuckSizes(Some(size1), Some(size2)) + ) + ) ) Loops.fullDuplex(socketPair, dataSize) println(f"$size1%5d -eng-> $size2%5d -net-> $size1%5d -eng-> $size2%5d") diff --git a/src/test/scala/tlschannel/CloseTest.scala b/src/test/scala/tlschannel/CloseTest.scala index d777f656..c01de8b7 100644 --- a/src/test/scala/tlschannel/CloseTest.scala +++ b/src/test/scala/tlschannel/CloseTest.scala @@ -5,6 +5,8 @@ import java.nio.channels.ClosedChannelException import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue} import org.junit.jupiter.api.TestInstance.Lifecycle import org.junit.jupiter.api.{Assertions, Test, TestInstance} +import tlschannel.helpers.SocketPairFactory.ChunkSizeConfig +import tlschannel.helpers.SocketPairFactory.ChuckSizes import java.nio.channels.AsynchronousCloseException import tlschannel.helpers.{SocketPairFactory, SslContextFactory, TestUtil} @@ -23,8 +25,9 @@ class CloseTest { @Test def testTcpImmediateClose(): Unit = { - val socketPair = - factory.nioNio(internalClientChunkSize = internalBufferSize, internalServerChunkSize = internalBufferSize) + val socketPair = factory.nioNio(chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))) + ) val clientGroup = socketPair.client val serverGroup = socketPair.server val client = clientGroup.external @@ -56,8 +59,9 @@ class CloseTest { @Test def testTcpClose(): Unit = { - val socketPair = - factory.nioNio(internalClientChunkSize = internalBufferSize, internalServerChunkSize = internalBufferSize) + val socketPair = factory.nioNio(chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))) + ) val clientGroup = socketPair.client val serverGroup = socketPair.server val client = clientGroup.external @@ -94,8 +98,9 @@ class CloseTest { @Test def testClose(): Unit = { - val socketPair = - factory.nioNio(internalClientChunkSize = internalBufferSize, internalServerChunkSize = internalBufferSize) + val socketPair = factory.nioNio(chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))) + ) val clientGroup = socketPair.client val serverGroup = socketPair.server val client = clientGroup.external @@ -133,8 +138,8 @@ class CloseTest { @Test def testCloseAndWait(): Unit = { val socketPair = factory.nioNio( - internalClientChunkSize = internalBufferSize, - internalServerChunkSize = internalBufferSize, + chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))), waitForCloseConfirmation = true ) val clientGroup = socketPair.client @@ -174,8 +179,8 @@ class CloseTest { @Test def testCloseAndWaitForever(): Unit = { val socketPair = factory.nioNio( - internalClientChunkSize = internalBufferSize, - internalServerChunkSize = internalBufferSize, + chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))), waitForCloseConfirmation = true ) val clientGroup = socketPair.client @@ -212,8 +217,9 @@ class CloseTest { @Test def testShutdownAndForget(): Unit = { - val socketPair = - factory.nioNio(internalClientChunkSize = internalBufferSize, internalServerChunkSize = internalBufferSize) + val socketPair = factory.nioNio(chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))) + ) val clientGroup = socketPair.client val serverGroup = socketPair.server val client = clientGroup.external @@ -248,8 +254,9 @@ class CloseTest { @Test def testShutdownAndWait(): Unit = { - val socketPair = - factory.nioNio(internalClientChunkSize = internalBufferSize, internalServerChunkSize = internalBufferSize) + val socketPair = factory.nioNio(chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))) + ) val clientGroup = socketPair.client val serverGroup = socketPair.server val client = clientGroup.external @@ -294,8 +301,9 @@ class CloseTest { @Test def testShutdownAndWaitForever(): Unit = { - val socketPair = - factory.nioNio(internalClientChunkSize = internalBufferSize, internalServerChunkSize = internalBufferSize) + val socketPair = factory.nioNio(chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(internalBufferSize, None), ChuckSizes(internalBufferSize, None))) + ) val clientGroup = socketPair.client val serverGroup = socketPair.server val client = clientGroup.external diff --git a/src/test/scala/tlschannel/MultiNonBlockingTest.scala b/src/test/scala/tlschannel/MultiNonBlockingTest.scala index 0feea25e..bdf65ab0 100644 --- a/src/test/scala/tlschannel/MultiNonBlockingTest.scala +++ b/src/test/scala/tlschannel/MultiNonBlockingTest.scala @@ -19,7 +19,7 @@ class MultiNonBlockingTest { @Test def testTaskLoop(): Unit = { println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, None, None, None, runTasks = true) + val pairs = factory.nioNioN(None, totalConnections, None, runTasks = true) val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = false) assertEquals(0, report.asyncTasksRun) report.print() @@ -29,7 +29,7 @@ class MultiNonBlockingTest { @Test def testTasksInExecutor(): Unit = { println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, None, None, None, runTasks = false) + val pairs = factory.nioNioN(None, totalConnections, None, runTasks = false) val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = false) report.print() } @@ -38,7 +38,7 @@ class MultiNonBlockingTest { @Test def testTasksInLoopWithRenegotiation(): Unit = { println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, None, None, None, runTasks = true) + val pairs = factory.nioNioN(None, totalConnections, None, runTasks = true) val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = true) assertEquals(0, report.asyncTasksRun) report.print() @@ -48,7 +48,7 @@ class MultiNonBlockingTest { @Test def testTasksInExecutorWithRenegotiation(): Unit = { println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, None, None, None, runTasks = false) + val pairs = factory.nioNioN(None, totalConnections, None, runTasks = false) val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = true) report.print() } diff --git a/src/test/scala/tlschannel/NonBlockingTest.scala b/src/test/scala/tlschannel/NonBlockingTest.scala index a27d4f18..674e55be 100644 --- a/src/test/scala/tlschannel/NonBlockingTest.scala +++ b/src/test/scala/tlschannel/NonBlockingTest.scala @@ -4,8 +4,11 @@ import org.junit.jupiter.api.{DynamicTest, TestFactory, TestInstance} import org.junit.jupiter.api.TestInstance.Lifecycle import tlschannel.helpers.NonBlockingLoops import tlschannel.helpers.SocketPairFactory +import tlschannel.helpers.SocketPairFactory.ChunkSizeConfig +import tlschannel.helpers.SocketPairFactory.ChuckSizes import tlschannel.helpers.SslContextFactory import tlschannel.helpers.TestUtil.LazyListWithTakeWhileInclusive + import scala.jdk.CollectionConverters._ import java.util @@ -24,11 +27,13 @@ class NonBlockingTest { DynamicTest.dynamicTest( s"testSelectorLoop() - size1=$size1, size2=$size2", () => { - val socketPair = factory.nioNio( - internalClientChunkSize = Some(size1), - externalClientChunkSize = Some(size2), - internalServerChunkSize = Some(size1), - externalServerChunkSize = Some(size2) + val socketPair = factory.nioNio(chunkSizeConfig = + Some( + ChunkSizeConfig( + ChuckSizes(Some(size1), Some(size2)), + ChuckSizes(Some(size1), Some(size2)) + ) + ) ) val report = NonBlockingLoops.loop(Seq(socketPair), dataSize, renegotiate = true) println(f"** $size1%d -eng-> $size2%d -net-> $size1%d -eng-> $size2%d **") diff --git a/src/test/scala/tlschannel/NullEngineTest.scala b/src/test/scala/tlschannel/NullEngineTest.scala index 03ecac83..5e8870a5 100644 --- a/src/test/scala/tlschannel/NullEngineTest.scala +++ b/src/test/scala/tlschannel/NullEngineTest.scala @@ -5,6 +5,7 @@ import org.junit.jupiter.api.TestInstance.Lifecycle import tlschannel.helpers.TestUtil.LazyListWithTakeWhileInclusive import tlschannel.helpers.SocketPairFactory import tlschannel.helpers.Loops +import tlschannel.helpers.SocketPairFactory.{ChuckSizes, ChunkSizeConfig} import tlschannel.helpers.SslContextFactory import scala.jdk.CollectionConverters._ @@ -36,7 +37,15 @@ class NullEngineTest { s"testHalfDuplexHeapBuffers() - size1=$size1", () => { val socketPair = - factory.nioNio(cipher = null, internalClientChunkSize = Some(size1), internalServerChunkSize = Some(size1)) + factory.nioNio( + cipher = null, + chunkSizeConfig = Some( + ChunkSizeConfig( + ChuckSizes(Some(size1), None), + ChuckSizes(Some(size1), None) + ) + ) + ) Loops.halfDuplex(socketPair, dataSize) println(f"-eng-> $size1%5d -net-> $size1%5d -eng->") } @@ -56,7 +65,15 @@ class NullEngineTest { () => { logger.fine(() => s"Testing sizes: size1=$size1") val socketPair = - factory.nioNio(cipher = null, internalClientChunkSize = Some(size1), internalServerChunkSize = Some(size1)) + factory.nioNio( + cipher = null, + chunkSizeConfig = Some( + ChunkSizeConfig( + ChuckSizes(Some(size1), None), + ChuckSizes(Some(size1), None) + ) + ) + ) Loops.halfDuplex(socketPair, dataSize) println(f"-eng-> $size1%5d -net-> $size1%5d -eng->") } diff --git a/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala b/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala index 9f539dae..e4a6e163 100644 --- a/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala +++ b/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala @@ -19,7 +19,7 @@ class NullMultiNonBlockingTest { @Test def testRunTasksInNonBlockingLoop(): Unit = { - val pairs = factory.nioNioN(cipher = null, totalConnections, None, None) + val pairs = factory.nioNioN(cipher = null, totalConnections) val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = false) Assertions.assertEquals(0, report.asyncTasksRun) } diff --git a/src/test/scala/tlschannel/async/PseudoAsyncTest.scala b/src/test/scala/tlschannel/async/PseudoAsyncTest.scala index 3ecebb6a..5f76ba84 100644 --- a/src/test/scala/tlschannel/async/PseudoAsyncTest.scala +++ b/src/test/scala/tlschannel/async/PseudoAsyncTest.scala @@ -4,6 +4,7 @@ import org.junit.jupiter.api.{DynamicTest, Test, TestFactory, TestInstance} import org.junit.jupiter.api.TestInstance.Lifecycle import tlschannel.helpers.Loops import tlschannel.helpers.SocketPairFactory +import tlschannel.helpers.SocketPairFactory.{ChuckSizes, ChunkSizeConfig} import tlschannel.helpers.SslContextFactory import tlschannel.helpers.TestUtil.LazyListWithTakeWhileInclusive @@ -29,10 +30,8 @@ class PseudoAsyncTest { s"testHalfDuplex() - size1=$size1, size2=$size2", () => { val socketPair = factory.nioNio( - internalClientChunkSize = Some(size1), - externalClientChunkSize = Some(size2), - internalServerChunkSize = Some(size1), - externalServerChunkSize = Some(size2), + chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(Some(size1), Some(size2)), ChuckSizes(Some(size1), Some(size2)))), pseudoAsyncGroup = Some(channelGroup) ) Loops.halfDuplex(socketPair, dataSize) @@ -51,10 +50,8 @@ class PseudoAsyncTest { s"testFullDuplex() - size1=$size1, size2=$size2", () => { val socketPair = factory.nioNio( - internalClientChunkSize = Some(size1), - externalClientChunkSize = Some(size2), - internalServerChunkSize = Some(size1), - externalServerChunkSize = Some(size2), + chunkSizeConfig = + Some(ChunkSizeConfig(ChuckSizes(Some(size1), Some(size2)), ChuckSizes(Some(size1), Some(size2)))), pseudoAsyncGroup = Some(channelGroup) ) Loops.fullDuplex(socketPair, dataSize) diff --git a/src/test/scala/tlschannel/helpers/SocketPairFactory.scala b/src/test/scala/tlschannel/helpers/SocketPairFactory.scala index 40dad997..5081a7fc 100644 --- a/src/test/scala/tlschannel/helpers/SocketPairFactory.scala +++ b/src/test/scala/tlschannel/helpers/SocketPairFactory.scala @@ -37,6 +37,8 @@ case class AsyncSocketGroup(external: ExtendedAsynchronousByteChannel, tls: TlsC */ class SocketPairFactory(val sslContext: SSLContext, val serverName: String) { + import SocketPairFactory._ + def this(sslContext: SSLContext) = { this(sslContext, SslContextFactory.certificateCommonName) } @@ -152,10 +154,7 @@ class SocketPairFactory(val sslContext: SSLContext, val serverName: String) { def nioNio( cipher: Option[String] = None, - externalClientChunkSize: Option[Int] = None, - internalClientChunkSize: Option[Int] = None, - externalServerChunkSize: Option[Int] = None, - internalServerChunkSize: Option[Int] = None, + chunkSizeConfig: Option[ChunkSizeConfig] = None, runTasks: Boolean = true, waitForCloseConfirmation: Boolean = false, pseudoAsyncGroup: Option[AsynchronousTlsChannelGroup] = None @@ -163,10 +162,7 @@ class SocketPairFactory(val sslContext: SSLContext, val serverName: String) { nioNioN( cipher, 1, - externalClientChunkSize, - internalClientChunkSize, - externalServerChunkSize, - internalServerChunkSize, + chunkSizeConfig, runTasks, waitForCloseConfirmation, pseudoAsyncGroup @@ -176,10 +172,7 @@ class SocketPairFactory(val sslContext: SSLContext, val serverName: String) { def nioNioN( cipher: Option[String] = None, qtty: Int, - externalClientChunkSize: Option[Int] = None, - internalClientChunkSize: Option[Int] = None, - externalServerChunkSize: Option[Int] = None, - internalServerChunkSize: Option[Int] = None, + chunkSizeConfig: Option[ChunkSizeConfig] = None, runTasks: Boolean = true, waitForCloseConfirmation: Boolean = false, pseudoAsyncGroup: Option[AsynchronousTlsChannelGroup] = None @@ -193,14 +186,24 @@ class SocketPairFactory(val sslContext: SSLContext, val serverName: String) { val rawClient = SocketChannel.open(address) val rawServer = serverSocket.accept() - val plainClient = internalClientChunkSize match { - case Some(size) => new ChunkingByteChannel(rawClient, size) - case None => rawClient + val plainClient = chunkSizeConfig match { + case Some(config) => + config.clientChuckSize.internalSize match { + case Some(size) => new ChunkingByteChannel(rawClient, size) + case None => rawClient + } + case None => + rawClient } - val plainServer = internalServerChunkSize match { - case Some(size) => new ChunkingByteChannel(rawServer, size) - case None => rawServer + val plainServer = chunkSizeConfig match { + case Some(config) => + config.serverChunkSize.internalSize match { + case Some(size) => new ChunkingByteChannel(rawServer, size) + case None => rawServer + } + case None => + rawServer } val clientEngine = if (cipher == null) { @@ -255,13 +258,24 @@ class SocketPairFactory(val sslContext: SSLContext, val serverName: String) { serverChannel } - val externalClient = externalClientChunkSize match { - case Some(size) => new ChunkingByteChannel(clientAsyncChannel, chunkSize = size) - case None => clientChannel + val externalClient = chunkSizeConfig match { + case Some(config) => + config.clientChuckSize.externalSize match { + case Some(size) => new ChunkingByteChannel(clientAsyncChannel, chunkSize = size) + case None => clientChannel + } + case None => + clientChannel } - val externalServer = externalServerChunkSize match { - case Some(size) => new ChunkingByteChannel(serverAsyncChannel, chunkSize = size) - case None => serverChannel + + val externalServer = chunkSizeConfig match { + case Some(config) => + config.serverChunkSize.externalSize match { + case Some(size) => new ChunkingByteChannel(serverAsyncChannel, chunkSize = size) + case None => serverChannel + } + case None => + serverChannel } val clientPair = SocketGroup(externalClient, clientChannel, rawClient) @@ -400,4 +414,8 @@ object SocketPairFactory { math.max(exp.toInt, 1) } + case class ChunkSizeConfig(clientChuckSize: ChuckSizes, serverChunkSize: ChuckSizes) + + case class ChuckSizes(internalSize: Option[Int], externalSize: Option[Int]) + }