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: AsyncTestBase #171

Merged
merged 1 commit into from
Nov 25, 2023
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
50 changes: 50 additions & 0 deletions src/test/scala/tlschannel/async/AsyncTestBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tlschannel.async;

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

import java.util.concurrent.TimeUnit;

interface AsyncTestBase {

default void printChannelGroupStatus(AsynchronousTlsChannelGroup channelGroup) {
System.out.println("channel group:");
System.out.printf(" selection cycles: %8d\n", channelGroup.getSelectionCount());
System.out.printf(" started reads: %8d\n", channelGroup.getStartedReadCount());
System.out.printf(" successful reads: %8d\n", channelGroup.getSuccessfulReadCount());
System.out.printf(" failed reads: %8d\n", channelGroup.getFailedReadCount());
System.out.printf(" cancelled reads: %8d\n", channelGroup.getCancelledReadCount());
System.out.printf(" started writes: %8d\n", channelGroup.getStartedWriteCount());
System.out.printf(" successful write: %8d\n", channelGroup.getSuccessfulWriteCount());
System.out.printf(" failed writes: %8d\n", channelGroup.getFailedWriteCount());
System.out.printf(" cancelled writes: %8d\n", channelGroup.getCancelledWriteCount());
}

default void shutdownChannelGroup(AsynchronousTlsChannelGroup group) {
group.shutdown();
try {
boolean terminated = group.awaitTermination(100, TimeUnit.MILLISECONDS);
assertTrue(terminated);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

default void assertChannelGroupConsistency(AsynchronousTlsChannelGroup group) {
// give time to adders to converge
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
assertEquals(0, group.getCurrentRegistrationCount());
assertEquals(0, group.getCurrentReadCount());
assertEquals(0, group.getCurrentWriteCount());
assertEquals(
group.getCancelledReadCount() + group.getSuccessfulReadCount() + group.getFailedReadCount(),
group.getStartedReadCount());
assertEquals(
group.getCancelledWriteCount() + group.getSuccessfulWriteCount() + group.getFailedWriteCount(),
group.getStartedWriteCount());
}
}
43 changes: 0 additions & 43 deletions src/test/scala/tlschannel/async/AsyncTestBase.scala

This file was deleted.