Home / Function/ testMetricsProvideCorrectUtilizationAndActiveExecutorCount() — netty Function Reference

testMetricsProvideCorrectUtilizationAndActiveExecutorCount() — netty Function Reference

Architecture documentation for the testMetricsProvideCorrectUtilizationAndActiveExecutorCount() function in AutoScalingEventExecutorChooserFactoryTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  a73f4628_6eda_d777_896e_c431ad8bcfd7["testMetricsProvideCorrectUtilizationAndActiveExecutorCount()"]
  b457a618_1afa_e8a9_dd34_152c53154c93["AutoScalingEventExecutorChooserFactoryTest"]
  a73f4628_6eda_d777_896e_c431ad8bcfd7 -->|defined in| b457a618_1afa_e8a9_dd34_152c53154c93
  451cbcf6_6cbf_b404_e07f_191549368cc2["TestEventExecutorGroup()"]
  a73f4628_6eda_d777_896e_c431ad8bcfd7 -->|calls| 451cbcf6_6cbf_b404_e07f_191549368cc2
  70a22675_9cb3_276f_a519_80257cc8a1a0["startAllExecutors()"]
  a73f4628_6eda_d777_896e_c431ad8bcfd7 -->|calls| 70a22675_9cb3_276f_a519_80257cc8a1a0
  c81b705e_9115_5b4b_23a6_5102d314a007["setHighLoad()"]
  a73f4628_6eda_d777_896e_c431ad8bcfd7 -->|calls| c81b705e_9115_5b4b_23a6_5102d314a007
  style a73f4628_6eda_d777_896e_c431ad8bcfd7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/test/java/io/netty/util/concurrent/AutoScalingEventExecutorChooserFactoryTest.java lines 273–339

    @Test
    @Timeout(30)
    void testMetricsProvideCorrectUtilizationAndActiveExecutorCount() throws InterruptedException {
        TestEventExecutorGroup group = new TestEventExecutorGroup(1, 3, 50, TimeUnit.MILLISECONDS);
        try {
            startAllExecutors(group);
            long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
            while (group.activeExecutorCount() > 1 && System.nanoTime() < deadline) {
                Thread.sleep(50);
            }
            assertEquals(1, group.activeExecutorCount(), "Should have scaled down to 1 active executor.");

            TestEventExecutor activeExecutor = null;
            for (EventExecutor exec : group) {
                if (!exec.isSuspended()) {
                    activeExecutor = (TestEventExecutor) exec;
                    break;
                }
            }
            if (activeExecutor == null) {
                fail("Could not find an active executor.");
            }

            activeExecutor.setHighLoad(true);

            while (System.nanoTime() < deadline) {
                List<AutoScalingUtilizationMetric> utilizationMetrics = group.executorUtilizations();
                TestEventExecutor finalActiveExecutor = activeExecutor;
                double utilization = utilizationMetrics.stream()
                                                       .filter(metric -> metric.executor().equals(finalActiveExecutor))
                                                       .findFirst()
                        .map(AutoScalingUtilizationMetric::utilization)
                        .orElse(0.0);
                if (utilization > 0.4) {
                    break;
                }
                Thread.sleep(50);
            }

            assertEquals(1, group.activeExecutorCount(), "Active count should still be 1 before scaling up.");

            List<AutoScalingUtilizationMetric> utilizationMetrics = group.executorUtilizations();
            assertEquals(3, utilizationMetrics.size(), "Utilization list should report on all executors.");

            TestEventExecutor finalActiveExecutor2 = activeExecutor;
            double activeUtilization = utilizationMetrics.stream()
                                                         .filter(metric -> metric.executor()
                                                                                 .equals(finalActiveExecutor2))
                                                         .findFirst()
                                                         .map(AutoScalingUtilizationMetric::utilization)
                                                         .orElse(0.0);
            assertTrue(activeUtilization > 0.4,
                       "Active executor should have utilization above the scale-down threshold. " +
                       "Was: " + activeUtilization);

            TestEventExecutor finalActiveExecutor1 = activeExecutor;
            utilizationMetrics.stream()
                              .filter(metric -> metric.executor() != finalActiveExecutor1)
                              .forEach(metric -> {
                                  assertTrue(metric.executor().isSuspended(), "Other executors should be suspended.");
                                  assertEquals(0.0, metric.utilization(),
                                               "Suspended executor should have 0.0 utilization.");
                              });
        } finally {
            group.shutdownGracefully().syncUninterruptibly();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testMetricsProvideCorrectUtilizationAndActiveExecutorCount() do?
testMetricsProvideCorrectUtilizationAndActiveExecutorCount() is a function in the netty codebase, defined in common/src/test/java/io/netty/util/concurrent/AutoScalingEventExecutorChooserFactoryTest.java.
Where is testMetricsProvideCorrectUtilizationAndActiveExecutorCount() defined?
testMetricsProvideCorrectUtilizationAndActiveExecutorCount() is defined in common/src/test/java/io/netty/util/concurrent/AutoScalingEventExecutorChooserFactoryTest.java at line 273.
What does testMetricsProvideCorrectUtilizationAndActiveExecutorCount() call?
testMetricsProvideCorrectUtilizationAndActiveExecutorCount() calls 3 function(s): TestEventExecutorGroup, setHighLoad, startAllExecutors.

Analyze Your Own Codebase

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

Try Supermodel Free