Skip to content

Commit

Permalink
Simplify SocketPairFactory signature
Browse files Browse the repository at this point in the history
  • Loading branch information
marianobarrios committed Nov 4, 2023
1 parent 2104991 commit 6831156
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 96 deletions.
33 changes: 6 additions & 27 deletions src/test/scala/tlschannel/AllocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 15 additions & 9 deletions src/test/scala/tlschannel/BlockingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand Down
40 changes: 24 additions & 16 deletions src/test/scala/tlschannel/CloseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/test/scala/tlschannel/MultiNonBlockingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}
Expand All @@ -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()
Expand All @@ -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()
}
Expand Down
15 changes: 10 additions & 5 deletions src/test/scala/tlschannel/NonBlockingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 **")
Expand Down
21 changes: 19 additions & 2 deletions src/test/scala/tlschannel/NullEngineTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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->")
}
Expand All @@ -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->")
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/tlschannel/NullMultiNonBlockingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 5 additions & 8 deletions src/test/scala/tlschannel/async/PseudoAsyncTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 6831156

Please sign in to comment.