diff --git a/src/test/scala/tlschannel/MultiNonBlockingTest.java b/src/test/scala/tlschannel/MultiNonBlockingTest.java new file mode 100644 index 00000000..e2d77bdc --- /dev/null +++ b/src/test/scala/tlschannel/MultiNonBlockingTest.java @@ -0,0 +1,70 @@ +package tlschannel; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import scala.Option; +import scala.collection.immutable.Seq; +import tlschannel.helpers.NonBlockingLoops; +import tlschannel.helpers.SocketPair; +import tlschannel.helpers.SocketPairFactory; +import tlschannel.helpers.SslContextFactory; + +@TestInstance(Lifecycle.PER_CLASS) +public class MultiNonBlockingTest { + + private final SslContextFactory sslContextFactory = new SslContextFactory(); + private final SocketPairFactory factory = new SocketPairFactory(sslContextFactory.defaultContext()); + private final int dataSize = 50 * 1024; + private final int totalConnections = 200; + + // running tasks in non-blocking loop - no renegotiation + @Test + public void testTaskLoop() { + System.out.println("testTasksInExecutorWithRenegotiation():"); + Seq pairs = factory.nioNioN( + Option.apply(null), totalConnections, Option.apply(null), true, false, Option.apply(null)); + NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, false); + assertEquals(0, report.asyncTasksRun()); + report.print(); + } + + // running tasks in executor - no renegotiation + @Test + public void testTasksInExecutor() { + System.out.println("testTasksInExecutorWithRenegotiation():"); + Seq pairs = factory.nioNioN( + Option.apply(null), totalConnections, Option.apply(null), false, false, Option.apply(null)); + NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, false); + report.print(); + } + + // running tasks in non-blocking loop - with renegotiation + @Test + public void testTasksInLoopWithRenegotiation() { + System.out.println("testTasksInExecutorWithRenegotiation():"); + Seq pairs = factory.nioNioN( + Option.apply(null), totalConnections, Option.apply(null), true, false, Option.apply(null)); + NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, true); + assertEquals(0, report.asyncTasksRun()); + report.print(); + } + + // running tasks in executor - with renegotiation + @Test + public void testTasksInExecutorWithRenegotiation() { + System.out.println("testTasksInExecutorWithRenegotiation():"); + Seq pairs = factory.nioNioN( + Option.apply(null), totalConnections, Option.apply(null), false, false, Option.apply(null)); + NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, true); + report.print(); + } + + @AfterAll + public void afterAll() { + System.out.println(factory.getGlobalAllocationReport()); + } +} diff --git a/src/test/scala/tlschannel/MultiNonBlockingTest.scala b/src/test/scala/tlschannel/MultiNonBlockingTest.scala deleted file mode 100644 index bdf65ab0..00000000 --- a/src/test/scala/tlschannel/MultiNonBlockingTest.scala +++ /dev/null @@ -1,61 +0,0 @@ -package tlschannel - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.{AfterAll, Test, TestInstance} -import org.junit.jupiter.api.TestInstance.Lifecycle -import tlschannel.helpers.NonBlockingLoops -import tlschannel.helpers.SocketPairFactory -import tlschannel.helpers.SslContextFactory - -@TestInstance(Lifecycle.PER_CLASS) -class MultiNonBlockingTest { - - val sslContextFactory = new SslContextFactory - val factory = new SocketPairFactory(sslContextFactory.defaultContext) - val dataSize = 50 * 1024 - val totalConnections = 200 - - // running tasks in non-blocking loop - no renegotiation - @Test - def testTaskLoop(): Unit = { - println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, runTasks = true) - val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = false) - assertEquals(0, report.asyncTasksRun) - report.print() - } - - // running tasks in executor - no renegotiation - @Test - def testTasksInExecutor(): Unit = { - println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, runTasks = false) - val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = false) - report.print() - } - - // running tasks in non-blocking loop - with renegotiation - @Test - def testTasksInLoopWithRenegotiation(): Unit = { - println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, runTasks = true) - val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = true) - assertEquals(0, report.asyncTasksRun) - report.print() - } - - // running tasks in executor - with renegotiation - @Test - def testTasksInExecutorWithRenegotiation(): Unit = { - println("testTasksInExecutorWithRenegotiation():") - val pairs = factory.nioNioN(None, totalConnections, None, runTasks = false) - val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = true) - report.print() - } - - @AfterAll - def afterAll() = { - println(factory.getGlobalAllocationReport()) - } - -}