Skip to content

Commit

Permalink
Migrate to Java: AsyncTest
Browse files Browse the repository at this point in the history
  • Loading branch information
marianobarrios committed Feb 10, 2024
1 parent b001ca1 commit 3bf2b5a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 80 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ compileJava {
options.compilerArgs.add('-Xlint')
}

compileTestJava {
sourceCompatibility = '8'
targetCompatibility = '8'
options.compilerArgs.add('-Xlint')
}

repositories {
mavenLocal()
mavenCentral()
Expand Down
86 changes: 86 additions & 0 deletions src/test/scala/tlschannel/async/AsyncTest.java
Original file line number Diff line number Diff line change
@@ -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<AsyncSocketPair> 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<AsyncSocketPair> 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<AsyncSocketPair> 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);
}
}
80 changes: 0 additions & 80 deletions src/test/scala/tlschannel/async/AsyncTest.scala

This file was deleted.

0 comments on commit 3bf2b5a

Please sign in to comment.