Home / Class/ TrafficShapingHandlerTest Class — netty Architecture

TrafficShapingHandlerTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  89b0606a_219d_4de0_ef55_0f86426aafb3["TrafficShapingHandlerTest"]
  bdd08ecf_67ca_c093_7826_8944cb8a89d6["TrafficShapingHandlerTest.java"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|defined in| bdd08ecf_67ca_c093_7826_8944cb8a89d6
  14752bc1_3e71_06c6_d5af_6f16c3753a25["createGroup()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 14752bc1_3e71_06c6_d5af_6f16c3753a25
  69319afa_a32e_26dc_e481_fd4b87029d40["destroyGroup()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 69319afa_a32e_26dc_e481_fd4b87029d40
  fde649a6_c64f_d508_d230_6f38967ee20e["computeWaitRead()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| fde649a6_c64f_d508_d230_6f38967ee20e
  8ee7ab04_b410_2f74_f09b_3dbbf45ba780["computeWaitWrite()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 8ee7ab04_b410_2f74_f09b_3dbbf45ba780
  3e493cbd_07b8_9344_786f_99b3effadf54["computeWaitAutoRead()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 3e493cbd_07b8_9344_786f_99b3effadf54
  10a02e5a_8b37_a336_5546_fcd13e8b0aa0["testNoTrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 10a02e5a_8b37_a336_5546_fcd13e8b0aa0
  9e9db304_6fcc_01b0_297d_06f1d584a682["testWriteTrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 9e9db304_6fcc_01b0_297d_06f1d584a682
  843703ca_65b2_ba15_f670_303f35ddecc5["testReadTrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 843703ca_65b2_ba15_f670_303f35ddecc5
  90f04944_7cdd_66d8_ec2c_4bad43f5ce31["testWrite1TrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 90f04944_7cdd_66d8_ec2c_4bad43f5ce31
  fdb11d66_dc79_d514_44e8_a61532e04b5c["testRead1TrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| fdb11d66_dc79_d514_44e8_a61532e04b5c
  7ded4b52_9519_7f3a_7191_52cc1c988916["testWriteGlobalTrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 7ded4b52_9519_7f3a_7191_52cc1c988916
  8cef2b65_a06b_da07_a37a_93b6875460a4["testReadGlobalTrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 8cef2b65_a06b_da07_a37a_93b6875460a4
  503172e1_7515_719f_2b96_1bd3020235eb["testAutoReadTrafficShapping()"]
  89b0606a_219d_4de0_ef55_0f86426aafb3 -->|method| 503172e1_7515_719f_2b96_1bd3020235eb

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java lines 49–604

public class TrafficShapingHandlerTest extends AbstractSocketTest {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(TrafficShapingHandlerTest.class);
    private static final InternalLogger loggerServer = InternalLoggerFactory.getInstance("ServerTSH");
    private static final InternalLogger loggerClient = InternalLoggerFactory.getInstance("ClientTSH");

    static final int messageSize = 1024;
    static final int bandwidthFactor = 12;
    static final int minfactor = 3;
    static final int maxfactor = bandwidthFactor + bandwidthFactor / 2;
    static final long stepms = (1000 / bandwidthFactor - 10) / 10 * 10;
    static final long minimalms = Math.max(stepms / 2, 20) / 10 * 10;
    static final long check = 10;
    private static final Random random = new Random();
    static final byte[] data = new byte[messageSize];

    private static final String TRAFFIC = "traffic";
    private static String currentTestName;
    private static int currentTestRun;

    private static EventExecutorGroup group;
    private static EventExecutorGroup groupForGlobal;
    private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(10);
    static {
        random.nextBytes(data);
    }

    @BeforeAll
    public static void createGroup() {
        logger.info("Bandwidth: " + minfactor + " <= " + bandwidthFactor + " <= " + maxfactor +
                    " StepMs: " + stepms + " MinMs: " + minimalms + " CheckMs: " + check);
        group = new DefaultEventExecutorGroup(8);
        groupForGlobal = new DefaultEventExecutorGroup(8);
    }

    @AfterAll
    public static void destroyGroup() throws Exception {
        group.shutdownGracefully().sync();
        groupForGlobal.shutdownGracefully().sync();
        executor.shutdown();
    }

    private static long[] computeWaitRead(int[] multipleMessage) {
        long[] minimalWaitBetween = new long[multipleMessage.length + 1];
        minimalWaitBetween[0] = 0;
        for (int i = 0; i < multipleMessage.length; i++) {
            if (multipleMessage[i] > 1) {
                minimalWaitBetween[i + 1] = (multipleMessage[i] - 1) * stepms + minimalms;
            } else {
                minimalWaitBetween[i + 1] = 10;
            }
        }
        return minimalWaitBetween;
    }

    private static long[] computeWaitWrite(int[] multipleMessage) {
        long[] minimalWaitBetween = new long[multipleMessage.length + 1];
        for (int i = 0; i < multipleMessage.length; i++) {
            if (multipleMessage[i] > 1) {
                minimalWaitBetween[i] = (multipleMessage[i] - 1) * stepms + minimalms;
            } else {
                minimalWaitBetween[i] = 10;
            }
        }
        return minimalWaitBetween;
    }

    private static long[] computeWaitAutoRead(int []autoRead) {
        long [] minimalWaitBetween = new long[autoRead.length + 1];
        minimalWaitBetween[0] = 0;
        for (int i = 0; i < autoRead.length; i++) {
            if (autoRead[i] != 0) {
                if (autoRead[i] > 0) {
                    minimalWaitBetween[i + 1] = -1;
                } else {
                    minimalWaitBetween[i + 1] = check;
                }
            } else {
                minimalWaitBetween[i + 1] = 0;
            }
        }
        return minimalWaitBetween;

Frequently Asked Questions

What is the TrafficShapingHandlerTest class?
TrafficShapingHandlerTest is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java.
Where is TrafficShapingHandlerTest defined?
TrafficShapingHandlerTest is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java at line 49.

Analyze Your Own Codebase

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

Try Supermodel Free