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: NonBlockingLoops #224

Merged
merged 1 commit into from
May 9, 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
27 changes: 16 additions & 11 deletions src/test/scala/tlschannel/MultiNonBlockingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
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 scala.jdk.CollectionConverters;
import tlschannel.helpers.NonBlockingLoops;
import tlschannel.helpers.SocketGroups.SocketPair;
import tlschannel.helpers.SocketPairFactory;
Expand All @@ -25,19 +26,21 @@ public class MultiNonBlockingTest {
@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));
List<SocketPair> pairs = CollectionConverters.SeqHasAsJava(factory.nioNioN(
Option.apply(null), totalConnections, Option.apply(null), true, false, Option.apply(null)))
.asJava();
NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, false);
assertEquals(0, report.asyncTasksRun());
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));
List<SocketPair> pairs = CollectionConverters.SeqHasAsJava(factory.nioNioN(
Option.apply(null), totalConnections, Option.apply(null), false, false, Option.apply(null)))
.asJava();
NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, false);
report.print();
}
Expand All @@ -46,19 +49,21 @@ public void testTasksInExecutor() {
@Test
public void testTasksInLoopWithRenegotiation() {
System.out.println("testTasksInExecutorWithRenegotiation():");
Seq<SocketPair> pairs = factory.nioNioN(
Option.apply(null), totalConnections, Option.apply(null), true, false, Option.apply(null));
List<SocketPair> pairs = CollectionConverters.SeqHasAsJava(factory.nioNioN(
Option.apply(null), totalConnections, Option.apply(null), true, false, Option.apply(null)))
.asJava();
NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, true);
assertEquals(0, report.asyncTasksRun());
assertEquals(0, report.asyncTasksRun);
report.print();
}

// running tasks in executor - with renegotiation
@Test
public void testTasksInExecutorWithRenegotiation() {
System.out.println("testTasksInExecutorWithRenegotiation():");
Seq<SocketPair> pairs = factory.nioNioN(
Option.apply(null), totalConnections, Option.apply(null), false, false, Option.apply(null));
List<SocketPair> pairs = CollectionConverters.SeqHasAsJava(factory.nioNioN(
Option.apply(null), totalConnections, Option.apply(null), false, false, Option.apply(null)))
.asJava();
NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, true);
report.print();
}
Expand Down
8 changes: 2 additions & 6 deletions src/test/scala/tlschannel/NonBlockingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.jupiter.api.TestInstance.Lifecycle;
import scala.Option;
import scala.Some;
import scala.jdk.javaapi.CollectionConverters;
import tlschannel.helpers.NonBlockingLoops;
import tlschannel.helpers.SocketGroups.SocketPair;
import tlschannel.helpers.SocketPairFactory;
Expand Down Expand Up @@ -46,11 +45,8 @@ public Collection<DynamicTest> testSelectorLoop() {
false,
Option.apply(null));

NonBlockingLoops.Report report = NonBlockingLoops.loop(
CollectionConverters.asScala(Collections.singletonList(socketPair))
.toSeq(),
dataSize,
true);
NonBlockingLoops.Report report =
NonBlockingLoops.loop(Collections.singletonList(socketPair), dataSize, true);
System.out.printf("%5d -eng-> %5d -net-> %5d -eng-> %5d\n", size1, size2, size1, size2);
report.print();
}));
Expand Down
10 changes: 6 additions & 4 deletions src/test/scala/tlschannel/NullMultiNonBlockingTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package tlschannel;

import java.util.List;
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 scala.jdk.CollectionConverters;
import tlschannel.helpers.NonBlockingLoops;
import tlschannel.helpers.SocketGroups.SocketPair;
import tlschannel.helpers.SocketPairFactory;
Expand All @@ -25,10 +26,11 @@ public class NullMultiNonBlockingTest {

@Test
public void testRunTasksInNonBlockingLoop() {
Seq<SocketPair> pairs =
factory.nioNioN(null, totalConnections, Option.apply(null), true, false, Option.apply(null));
List<SocketPair> pairs = CollectionConverters.SeqHasAsJava(
factory.nioNioN(null, totalConnections, Option.apply(null), true, false, Option.apply(null)))
.asJava();
NonBlockingLoops.Report report = NonBlockingLoops.loop(pairs, dataSize, false);
Assertions.assertEquals(0, report.asyncTasksRun());
Assertions.assertEquals(0, report.asyncTasksRun);
}

@AfterAll
Expand Down
Loading