SingleThreadIoEventLoopTest Class — netty Architecture
Architecture documentation for the SingleThreadIoEventLoopTest class in SingleThreadIoEventLoopTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 3ae7759e_3f36_7ed2_6a26_d7826488440e["SingleThreadIoEventLoopTest"] e1570af9_af6d_987e_8115_c6e9e15ab1f4["SingleThreadIoEventLoopTest.java"] 3ae7759e_3f36_7ed2_6a26_d7826488440e -->|defined in| e1570af9_af6d_987e_8115_c6e9e15ab1f4 fd455cb0_5585_1cd9_663c_b50724be2315["testIsIoType()"] 3ae7759e_3f36_7ed2_6a26_d7826488440e -->|method| fd455cb0_5585_1cd9_663c_b50724be2315 a6139035_c244_cbb1_20c9_20cfb4748628["testIsCompatible()"] 3ae7759e_3f36_7ed2_6a26_d7826488440e -->|method| a6139035_c244_cbb1_20c9_20cfb4748628 150f9b58_d062_6dfa_329b_040b38e2d740["testSuspendingWhileRegistrationActive()"] 3ae7759e_3f36_7ed2_6a26_d7826488440e -->|method| 150f9b58_d062_6dfa_329b_040b38e2d740
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/SingleThreadIoEventLoopTest.java lines 30–186
public class SingleThreadIoEventLoopTest {
@Test
void testIsIoType() {
class TestIoHandler2 extends TestIoHandler {
TestIoHandler2(ThreadAwareExecutor executor) {
super(executor);
}
}
IoEventLoopGroup group = new SingleThreadIoEventLoop(null,
Executors.defaultThreadFactory(), TestIoHandler::new);
assertTrue(group.isIoType(TestIoHandler.class));
assertFalse(group.isIoType(TestIoHandler2.class));
group.shutdownGracefully();
}
static final class CompatibleTestIoHandler extends TestIoHandler {
CompatibleTestIoHandler(ThreadAwareExecutor executor) {
super(executor);
}
@Override
public boolean isCompatible(Class<? extends IoHandle> handleType) {
return handleType.equals(TestIoHandle.class);
}
}
@Test
void testIsCompatible() {
IoHandle handle = new TestIoHandle() { };
IoEventLoopGroup group = new SingleThreadIoEventLoop(null,
Executors.defaultThreadFactory(), CompatibleTestIoHandler::new);
assertTrue(group.isCompatible(TestIoHandle.class));
assertFalse(group.isCompatible(handle.getClass()));
group.shutdownGracefully();
}
private static final class TestThreadFactory implements ThreadFactory {
final LinkedBlockingQueue<Thread> threads = new LinkedBlockingQueue<>();
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
threads.add(thread);
return thread;
}
}
@Disabled("This test is flaky and will often stall the build")
@Test
void testSuspendingWhileRegistrationActive() throws Exception {
TestThreadFactory threadFactory = new TestThreadFactory();
IoEventLoop loop = new SingleThreadIoEventLoop(null, threadFactory,
eventLoop -> new TestIoHandler(eventLoop) {
@Override
public boolean isCompatible(Class<? extends IoHandle> handleType) {
return true;
}
});
assertFalse(loop.isSuspended());
IoRegistration registration = loop.register(new TestIoHandle()).sync().getNow();
Thread currentThread = threadFactory.threads.take();
assertTrue(currentThread.isAlive());
assertTrue(loop.trySuspend());
// Still should be alive as until the registration is cancelled we can not suspend the loop.
assertTrue(currentThread.isAlive());
registration.cancel();
assertFalse(registration.isValid());
// The current thread should be able to die now.
currentThread.join();
assertTrue(threadFactory.threads.isEmpty());
loop.shutdownGracefully();
}
private static class TestIoHandler implements IoHandler {
private final Semaphore semaphore = new Semaphore(0);
Source
Frequently Asked Questions
What is the SingleThreadIoEventLoopTest class?
SingleThreadIoEventLoopTest is a class in the netty codebase, defined in transport/src/test/java/io/netty/channel/SingleThreadIoEventLoopTest.java.
Where is SingleThreadIoEventLoopTest defined?
SingleThreadIoEventLoopTest is defined in transport/src/test/java/io/netty/channel/SingleThreadIoEventLoopTest.java at line 30.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free