SingleThreadEventExecutorTest Class — netty Architecture
Architecture documentation for the SingleThreadEventExecutorTest class in SingleThreadEventExecutorTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD bbf4ea8d_698f_542a_1559_437b1b237a04["SingleThreadEventExecutorTest"] 68341706_e7dd_ee7e_305a_0cb38675254c["SingleThreadEventExecutorTest.java"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|defined in| 68341706_e7dd_ee7e_305a_0cb38675254c 6183ac82_bfc9_e2f8_7bde_8cb885fe093e["testSuspension()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 6183ac82_bfc9_e2f8_7bde_8cb885fe093e 6271404d_9287_da8b_368e_d0293a2734ac["testSuspensionWhenExecutorIsNotStarted()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 6271404d_9287_da8b_368e_d0293a2734ac 628c3ed1_70af_f127_38c3_4dcd0512b255["testNotSuspendedUntilScheduledTaskIsCancelled()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 628c3ed1_70af_f127_38c3_4dcd0512b255 b84ad0b5_80d6_fc5f_bbe8_3123af2a736a["testNotSuspendedUntilScheduledTaskDidRun()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| b84ad0b5_80d6_fc5f_bbe8_3123af2a736a 719b13be_b489_cd13_248f_561b21ae715e["testWrappedExecutorIsShutdown()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 719b13be_b489_cd13_248f_561b21ae715e b72bd0d3_e8d8_a3b6_089f_5128610a4cc0["executeShouldFail()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| b72bd0d3_e8d8_a3b6_089f_5128610a4cc0 df833e4a_f808_ea25_ad90_415d001157d1["testThreadProperties()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| df833e4a_f808_ea25_ad90_415d001157d1 2634351a_7ff9_b82e_bcee_1c2dd769eaa6["testInvokeAnyInEventLoop()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 2634351a_7ff9_b82e_bcee_1c2dd769eaa6 3d50b8a6_c8c4_64d9_388d_272fd712d181["testInvokeAnyInEventLoopWithTimeout()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 3d50b8a6_c8c4_64d9_388d_272fd712d181 4207a2c6_dde6_32e9_0e6f_e6aed99e0f26["testInvokeAllInEventLoop()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 4207a2c6_dde6_32e9_0e6f_e6aed99e0f26 4365b07d_2f97_d255_0545_65991544e68b["testInvokeAllInEventLoopWithTimeout()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 4365b07d_2f97_d255_0545_65991544e68b 2074a46e_da44_0185_8b5f_faf9b78d6aa0["testInvokeInEventLoop()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| 2074a46e_da44_0185_8b5f_faf9b78d6aa0 a9f57147_c664_bf2e_153f_8f0cf7452606["testLazyExecution()"] bbf4ea8d_698f_542a_1559_437b1b237a04 -->|method| a9f57147_c664_bf2e_153f_8f0cf7452606
Relationship Graph
Source Code
common/src/test/java/io/netty/util/concurrent/SingleThreadEventExecutorTest.java lines 45–662
public class SingleThreadEventExecutorTest {
private static final class TestThread extends Thread {
private final CountDownLatch startedLatch = new CountDownLatch(1);
private final CountDownLatch runLatch = new CountDownLatch(1);
TestThread(Runnable task) {
super(task);
}
@Override
public void start() {
super.start();
startedLatch.countDown();
}
@Override
public void run() {
runLatch.countDown();
super.run();
}
void awaitStarted() throws InterruptedException {
startedLatch.await();
}
void awaitRunnableExecution() throws InterruptedException {
runLatch.await();
}
}
private static final class TestThreadFactory implements ThreadFactory {
final LinkedBlockingQueue<TestThread> threads = new LinkedBlockingQueue<>();
@Override
public Thread newThread(@NotNull Runnable r) {
TestThread thread = new TestThread(r);
threads.add(thread);
return thread;
}
}
private static final class SuspendingSingleThreadEventExecutor extends SingleThreadEventExecutor {
SuspendingSingleThreadEventExecutor(ThreadFactory threadFactory) {
super(null, threadFactory, false, true,
Integer.MAX_VALUE, RejectedExecutionHandlers.reject());
}
@Override
protected void run() {
while (!confirmShutdown() && !canSuspend()) {
Runnable task = takeTask();
if (task != null) {
task.run();
}
}
}
@Override
protected void wakeup(boolean inEventLoop) {
interruptThread();
}
}
@Test
void testSuspension() throws Exception {
TestThreadFactory threadFactory = new TestThreadFactory();
final SingleThreadEventExecutor executor = new SuspendingSingleThreadEventExecutor(threadFactory);
LatchTask task1 = new LatchTask();
executor.execute(task1);
Thread currentThread = threadFactory.threads.take();
assertTrue(executor.trySuspend());
task1.await();
// Let's wait till the current Thread did die....
currentThread.join();
// Should be suspended now, we should be able to also call trySuspend() again.
assertTrue(executor.isSuspended());
// There was no thread created as we did not try to execute something yet.
assertTrue(threadFactory.threads.isEmpty());
Source
Frequently Asked Questions
What is the SingleThreadEventExecutorTest class?
SingleThreadEventExecutorTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/concurrent/SingleThreadEventExecutorTest.java.
Where is SingleThreadEventExecutorTest defined?
SingleThreadEventExecutorTest is defined in common/src/test/java/io/netty/util/concurrent/SingleThreadEventExecutorTest.java at line 45.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free