Home / Class/ AutoScalingEventExecutorChooserFactoryTest Class — netty Architecture

AutoScalingEventExecutorChooserFactoryTest Class — netty Architecture

Architecture documentation for the AutoScalingEventExecutorChooserFactoryTest class in AutoScalingEventExecutorChooserFactoryTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  b457a618_1afa_e8a9_dd34_152c53154c93["AutoScalingEventExecutorChooserFactoryTest"]
  64bbeca7_14ae_a6e0_13bc_10ee775d5e7c["AutoScalingEventExecutorChooserFactoryTest.java"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|defined in| 64bbeca7_14ae_a6e0_13bc_10ee775d5e7c
  c5a0b3a7_c8b4_5eef_b007_12c15fd9bf15["busyTask()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| c5a0b3a7_c8b4_5eef_b007_12c15fd9bf15
  c2d47c78_2668_c707_abc4_78fb1fc4e33a["testScaleDown()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| c2d47c78_2668_c707_abc4_78fb1fc4e33a
  31e8cd5d_3da2_e457_e392_791da6763b49["testScaleUp()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| 31e8cd5d_3da2_e457_e392_791da6763b49
  52a56cd5_ecdb_476a_59ff_d4822ab9dbb6["testScaleDownWhenExecutorIsNotStarted()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| 52a56cd5_ecdb_476a_59ff_d4822ab9dbb6
  fa39d00b_2276_5a04_7a4c_fcb81e990f8e["testScaleDownDoesNotGoBelowMinThreads()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| fa39d00b_2276_5a04_7a4c_fcb81e990f8e
  37ecfbd1_4171_5557_1ae6_d06132219da3["testScaleUpDoesNotExceedMaxThreads()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| 37ecfbd1_4171_5557_1ae6_d06132219da3
  ece7134e_ee36_459c_5aa3_071609b9fe1d["testSmarterPickingConsolidatesWorkOnActiveExecutor()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| ece7134e_ee36_459c_5aa3_071609b9fe1d
  a73f4628_6eda_d777_896e_c431ad8bcfd7["testMetricsProvideCorrectUtilizationAndActiveExecutorCount()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| a73f4628_6eda_d777_896e_c431ad8bcfd7
  70a22675_9cb3_276f_a519_80257cc8a1a0["startAllExecutors()"]
  b457a618_1afa_e8a9_dd34_152c53154c93 -->|method| 70a22675_9cb3_276f_a519_80257cc8a1a0

Relationship Graph

Source Code

common/src/test/java/io/netty/util/concurrent/AutoScalingEventExecutorChooserFactoryTest.java lines 33–348

public class AutoScalingEventExecutorChooserFactoryTest {

    private static void busyTask(long duration, TimeUnit unit) {
        long endTime = System.nanoTime() + unit.toNanos(duration);
        while (System.nanoTime() < endTime) {
            // Spin-wait to simulate CPU usage
        }
    }

    private static final class TestEventExecutor extends SingleThreadEventExecutor {
        private final AtomicBoolean highLoad = new AtomicBoolean(false);

        TestEventExecutor(EventExecutorGroup parent, Executor executor) {
            super(parent, executor, true, true, DEFAULT_MAX_PENDING_EXECUTOR_TASKS,
                  RejectedExecutionHandlers.reject());
        }

        void setHighLoad(boolean highLoad) {
            this.highLoad.set(highLoad);
        }

        @Override
        protected void run() {
            do {
                if (highLoad.get()) {
                    runAllTasks(TimeUnit.MILLISECONDS.toNanos(20));
                    long busyWorkStart = ticker().nanoTime();
                    busyTask(35, TimeUnit.MILLISECONDS);
                    long busyWorkEnd = ticker().nanoTime();
                    reportActiveIoTime(busyWorkEnd - busyWorkStart);
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        break;
                    }
                } else {
                    boolean ranTask = runAllTasks();
                    if (ranTask) {
                        updateLastExecutionTime();
                        // If we ran tasks, immediately loop back to check highLoad state
                        continue;
                    }

                    // No immediate tasks available, sleep to avoid busy waiting
                    // This allows the thread to be responsive to state changes while staying idle
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        break;
                    }
                }
            } while (!confirmShutdown() && !canSuspend());
        }
    }

    private static final class TestEventExecutorGroup extends MultithreadEventExecutorGroup {
        private static final Object[] ARGS = new Object[0];

        TestEventExecutorGroup(int minThreads, int maxThreads, long checkPeriod, TimeUnit unit) {
            super(maxThreads,
                  new ThreadPerTaskExecutor(Executors.defaultThreadFactory()),
                  new AutoScalingEventExecutorChooserFactory(
                          minThreads, maxThreads, checkPeriod, unit, 0.4, 0.6,
                          maxThreads, maxThreads, 2),
                  ARGS);
        }

        @Override
        protected EventExecutor newChild(Executor executor, Object... args) {
            return new TestEventExecutor(this, executor);
        }
    }

    @Test
    @Timeout(30)
    void testScaleDown() throws InterruptedException {
        TestEventExecutorGroup group = new TestEventExecutorGroup(1, 3, 50, TimeUnit.MILLISECONDS);
        try {
            startAllExecutors(group);

Frequently Asked Questions

What is the AutoScalingEventExecutorChooserFactoryTest class?
AutoScalingEventExecutorChooserFactoryTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/concurrent/AutoScalingEventExecutorChooserFactoryTest.java.
Where is AutoScalingEventExecutorChooserFactoryTest defined?
AutoScalingEventExecutorChooserFactoryTest is defined in common/src/test/java/io/netty/util/concurrent/AutoScalingEventExecutorChooserFactoryTest.java at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free