Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to java multi non blocking tes #194

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/test/scala/tlschannel/MultiNonBlockingTest.java
Original file line number Diff line number Diff line change
@@ -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<SocketPair> 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<SocketPair> 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<tlschannel.helpers.SocketPair> 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<tlschannel.helpers.SocketPair> 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());
}
}
61 changes: 0 additions & 61 deletions src/test/scala/tlschannel/MultiNonBlockingTest.scala

This file was deleted.

38 changes: 38 additions & 0 deletions src/test/scala/tlschannel/NullMultiNonBlockingTest.java
Original file line number Diff line number Diff line change
@@ -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<SocketPair> 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());
}
}
32 changes: 0 additions & 32 deletions src/test/scala/tlschannel/NullMultiNonBlockingTest.scala

This file was deleted.