diff --git a/build.gradle b/build.gradle index 320f1598..a2430f3e 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,12 @@ compileJava { options.compilerArgs.add('-Xlint') } +compileTestJava { + sourceCompatibility = '8' + targetCompatibility = '8' + options.compilerArgs.add('-Xlint') +} + repositories { mavenLocal() mavenCentral() diff --git a/src/test/scala/tlschannel/async/AsyncTest.java b/src/test/scala/tlschannel/async/AsyncTest.java new file mode 100644 index 00000000..87c30875 --- /dev/null +++ b/src/test/scala/tlschannel/async/AsyncTest.java @@ -0,0 +1,86 @@ +package tlschannel.async; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +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.AsyncLoops; +import tlschannel.helpers.AsyncSocketPair; +import tlschannel.helpers.SocketPairFactory; +import tlschannel.helpers.SslContextFactory; + +@TestInstance(Lifecycle.PER_CLASS) +public class AsyncTest implements AsyncTestBase { + + private final SslContextFactory sslContextFactory = new SslContextFactory(); + private final SocketPairFactory factory = new SocketPairFactory(sslContextFactory.defaultContext()); + private final int socketPairCount = 50; + + // real engine - run tasks + @Test + public void testRunTasks() { + System.out.println("testRunTasks():"); + AsynchronousTlsChannelGroup channelGroup = new AsynchronousTlsChannelGroup(); + int dataSize = 5 * 1024 * 1024; + System.out.printf("data size: %d\n", dataSize); + Seq socketPairs = + factory.asyncN(Option.apply(null), channelGroup, socketPairCount, true, false); + AsyncLoops.Report report = AsyncLoops.loop(socketPairs, dataSize); + + shutdownChannelGroup(channelGroup); + assertChannelGroupConsistency(channelGroup); + assertEquals(0, channelGroup.getFailedReadCount()); + assertEquals(0, channelGroup.getFailedWriteCount()); + + report.print(); + printChannelGroupStatus(channelGroup); + } + + // real engine - do not run tasks + @Test + public void testNotRunTasks() { + System.out.println("testNotRunTasks():"); + AsynchronousTlsChannelGroup channelGroup = new AsynchronousTlsChannelGroup(); + int dataSize = 2 * 1024 * 1024; + System.out.printf("data size: %d\n", dataSize); + Seq socketPairs = + factory.asyncN(Option.apply(null), channelGroup, socketPairCount, false, false); + AsyncLoops.Report report = AsyncLoops.loop(socketPairs, dataSize); + + shutdownChannelGroup(channelGroup); + assertChannelGroupConsistency(channelGroup); + + assertEquals(0, channelGroup.getFailedReadCount()); + assertEquals(0, channelGroup.getFailedWriteCount()); + assertEquals(0, channelGroup.getCancelledReadCount()); + assertEquals(0, channelGroup.getCancelledWriteCount()); + + report.print(); + printChannelGroupStatus(channelGroup); + } + + // null engine + @Test + public void testNullEngine() { + System.out.println("testNullEngine():"); + AsynchronousTlsChannelGroup channelGroup = new AsynchronousTlsChannelGroup(); + int dataSize = 12 * 1024 * 1024; + System.out.printf("data size: %d\n", dataSize); + Seq socketPairs = factory.asyncN(null, channelGroup, socketPairCount, true, false); + AsyncLoops.Report report = AsyncLoops.loop(socketPairs, dataSize); + + shutdownChannelGroup(channelGroup); + assertChannelGroupConsistency(channelGroup); + + assertEquals(0, channelGroup.getFailedReadCount()); + assertEquals(0, channelGroup.getFailedWriteCount()); + assertEquals(0, channelGroup.getCancelledReadCount()); + assertEquals(0, channelGroup.getCancelledWriteCount()); + + report.print(); + printChannelGroupStatus(channelGroup); + } +} diff --git a/src/test/scala/tlschannel/async/AsyncTest.scala b/src/test/scala/tlschannel/async/AsyncTest.scala deleted file mode 100644 index 4dee8acd..00000000 --- a/src/test/scala/tlschannel/async/AsyncTest.scala +++ /dev/null @@ -1,80 +0,0 @@ -package tlschannel.async - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.{Test, TestInstance} -import org.junit.jupiter.api.TestInstance.Lifecycle -import tlschannel.helpers.AsyncLoops -import tlschannel.helpers.SocketPairFactory -import tlschannel.helpers.SslContextFactory - -@TestInstance(Lifecycle.PER_CLASS) -class AsyncTest extends AsyncTestBase { - - val sslContextFactory = new SslContextFactory - val factory = new SocketPairFactory(sslContextFactory.defaultContext) - val socketPairCount = 50 - - // real engine - run tasks - @Test - def testRunTasks(): Unit = { - println("testRunTasks():") - val channelGroup = new AsynchronousTlsChannelGroup() - val dataSize = 5 * 1024 * 1024 - println(s"data size: $dataSize") - val socketPairs = factory.asyncN(None, channelGroup, socketPairCount, runTasks = true) - val report = AsyncLoops.loop(socketPairs, dataSize) - - shutdownChannelGroup(channelGroup) - assertChannelGroupConsistency(channelGroup) - assertEquals(0, channelGroup.getFailedReadCount) - assertEquals(0, channelGroup.getFailedWriteCount) - - report.print() - printChannelGroupStatus(channelGroup) - } - - // real engine - do not run tasks - @Test - def testNotRunTasks(): Unit = { - println("testNotRunTasks():") - val channelGroup = new AsynchronousTlsChannelGroup() - val dataSize = 2 * 1024 * 1024 - println(s"data size: $dataSize") - val socketPairs = factory.asyncN(None, channelGroup, socketPairCount, runTasks = false) - val report = AsyncLoops.loop(socketPairs, dataSize) - - shutdownChannelGroup(channelGroup) - assertChannelGroupConsistency(channelGroup) - - assertEquals(0, channelGroup.getFailedReadCount) - assertEquals(0, channelGroup.getFailedWriteCount) - assertEquals(0, channelGroup.getCancelledReadCount) - assertEquals(0, channelGroup.getCancelledWriteCount) - - report.print() - printChannelGroupStatus(channelGroup) - } - - // null engine - @Test - def testNullEngine(): Unit = { - println("testNullEngine():") - val channelGroup = new AsynchronousTlsChannelGroup() - val dataSize = 12 * 1024 * 1024 - println(s"data size: $dataSize") - val socketPairs = factory.asyncN(cipher = null, channelGroup, socketPairCount, runTasks = true) - val report = AsyncLoops.loop(socketPairs, dataSize) - - shutdownChannelGroup(channelGroup) - assertChannelGroupConsistency(channelGroup) - - assertEquals(0, channelGroup.getFailedReadCount) - assertEquals(0, channelGroup.getFailedWriteCount) - assertEquals(0, channelGroup.getCancelledReadCount) - assertEquals(0, channelGroup.getCancelledWriteCount) - - report.print() - printChannelGroupStatus(channelGroup) - } - -}