From f70fe4341bdde11c2c1af9ec806430d6fe79d32c Mon Sep 17 00:00:00 2001 From: Mariano Barrios Date: Sun, 31 Mar 2024 19:01:17 +0200 Subject: [PATCH 1/2] Migrate to Java: NullMultiNonBlockingTest --- .../tlschannel/NullMultiNonBlockingTest.java | 38 +++++++++++++++++++ .../tlschannel/NullMultiNonBlockingTest.scala | 32 ---------------- 2 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 src/test/scala/tlschannel/NullMultiNonBlockingTest.java delete mode 100644 src/test/scala/tlschannel/NullMultiNonBlockingTest.scala diff --git a/src/test/scala/tlschannel/NullMultiNonBlockingTest.java b/src/test/scala/tlschannel/NullMultiNonBlockingTest.java new file mode 100644 index 00000000..30ae58c3 --- /dev/null +++ b/src/test/scala/tlschannel/NullMultiNonBlockingTest.java @@ -0,0 +1,38 @@ +package tlschannel; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +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; + +/** Test using concurrent, non-blocking connections, and a "null" [[javax.net.ssl.SSLEngine]] that just passes all byte + * as they are. + */ +@TestInstance(Lifecycle.PER_CLASS) +public class NullMultiNonBlockingTest { + + private final SslContextFactory sslContextFactory = new SslContextFactory(); + private final SocketPairFactory factory = new SocketPairFactory(sslContextFactory.defaultContext()); + private final int dataSize = 10 * 1024 * 1024; + private final int totalConnections = 50; + + @Test + public void testRunTasksInNonBlockingLoop() { + Seq pairs = + factory.nioNioN(null, totalConnections, Option.apply(null), true, false, Option.apply(null)); + NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, false); + Assertions.assertEquals(0, report.asyncTasksRun()); + } + + @AfterAll + public void afterAll() { + System.out.println(factory.getGlobalAllocationReport()); + } +} diff --git a/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala b/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala deleted file mode 100644 index e4a6e163..00000000 --- a/src/test/scala/tlschannel/NullMultiNonBlockingTest.scala +++ /dev/null @@ -1,32 +0,0 @@ -package tlschannel - -import org.junit.jupiter.api.TestInstance.Lifecycle -import org.junit.jupiter.api.{AfterAll, Assertions, Test, TestInstance} -import tlschannel.helpers.NonBlockingLoops -import tlschannel.helpers.SocketPairFactory -import tlschannel.helpers.SslContextFactory - -/** Test using concurrent, non-blocking connections, and a "null" [[javax.net.ssl.SSLEngine]] that just passes all byte - * as they are. - */ -@TestInstance(Lifecycle.PER_CLASS) -class NullMultiNonBlockingTest { - - val sslContextFactory = new SslContextFactory - val factory = new SocketPairFactory(sslContextFactory.defaultContext) - val dataSize = 10 * 1024 * 1024 - val totalConnections = 50 - - @Test - def testRunTasksInNonBlockingLoop(): Unit = { - val pairs = factory.nioNioN(cipher = null, totalConnections) - val report = NonBlockingLoops.loop(pairs, dataSize, renegotiate = false) - Assertions.assertEquals(0, report.asyncTasksRun) - } - - @AfterAll - def afterAll() = { - println(factory.getGlobalAllocationReport()) - } - -} From 89a2789bf2f922be28993e3886cc4701cb17b71f Mon Sep 17 00:00:00 2001 From: Mariano Barrios Date: Sun, 31 Mar 2024 22:58:23 +0200 Subject: [PATCH 2/2] Migrate to Java: MultiNonBlockingTest --- .../tlschannel/MultiNonBlockingTest.java | 70 +++++++++++++++++++ .../tlschannel/MultiNonBlockingTest.scala | 61 ---------------- 2 files changed, 70 insertions(+), 61 deletions(-) create mode 100644 src/test/scala/tlschannel/MultiNonBlockingTest.java delete mode 100644 src/test/scala/tlschannel/MultiNonBlockingTest.scala 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()) - } - -}