Home / Class/ IdleStateHandlerTest Class — netty Architecture

IdleStateHandlerTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f1a156c3_6366_afc7_6b64_9543e5f91ba9["IdleStateHandlerTest"]
  b59afc75_3039_0a17_e1e6_3e9ae434e05b["IdleStateHandlerTest.java"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|defined in| b59afc75_3039_0a17_e1e6_3e9ae434e05b
  ceebc117_e04c_1d25_7956_ad5233e6fcc2["testReaderIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| ceebc117_e04c_1d25_7956_ad5233e6fcc2
  2524cfc4_eca5_6bcc_fadf_d5abd37833a1["testWriterIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 2524cfc4_eca5_6bcc_fadf_d5abd37833a1
  6302e225_7f9a_b306_5c0d_6979f5980c69["testAllIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 6302e225_7f9a_b306_5c0d_6979f5980c69
  13551606_9cf0_6ceb_85f9_d637333fc038["anyIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 13551606_9cf0_6ceb_85f9_d637333fc038
  9ce36c1e_e2fb_1863_27ec_a20ca7eff6f7["testResetReader()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 9ce36c1e_e2fb_1863_27ec_a20ca7eff6f7
  9df05e79_0f06_79c7_7d50_e308091775a6["testResetWriter()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 9df05e79_0f06_79c7_7d50_e308091775a6
  5bb1f696_1ee0_b304_b852_579f3a91a5ba["testReaderNotIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 5bb1f696_1ee0_b304_b852_579f3a91a5ba
  97a9191f_5aad_e60e_0845_ef3d3d3b16ba["testWriterNotIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 97a9191f_5aad_e60e_0845_ef3d3d3b16ba
  aeca092e_f735_2f22_7a48_f255e8d4cdbc["testAllNotIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| aeca092e_f735_2f22_7a48_f255e8d4cdbc
  1cc6fb30_92ac_540a_93b5_d0513d5059f6["anyNotIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 1cc6fb30_92ac_540a_93b5_d0513d5059f6
  986ff7c4_fdc7_a35d_fc1d_1ae708241887["testObserveWriterIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 986ff7c4_fdc7_a35d_fc1d_1ae708241887
  d04c6cb1_49ec_a2aa_cb19_67da01cf216b["testObserveAllIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| d04c6cb1_49ec_a2aa_cb19_67da01cf216b
  4603684a_0605_686e_f307_23319cb70e14["observeOutputIdle()"]
  f1a156c3_6366_afc7_6b64_9543e5f91ba9 -->|method| 4603684a_0605_686e_f307_23319cb70e14

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java lines 37–419

public class IdleStateHandlerTest {

    @Test
    public void testReaderIdle() throws Exception {
        IdleStateHandler idleStateHandler = new IdleStateHandler(
                false, 1L, 0L, 0L, TimeUnit.SECONDS);

        // We start with one FIRST_READER_IDLE_STATE_EVENT, followed by an infinite number of READER_IDLE_STATE_EVENTs
        anyIdle(idleStateHandler, IdleStateEvent.FIRST_READER_IDLE_STATE_EVENT,
                IdleStateEvent.READER_IDLE_STATE_EVENT, IdleStateEvent.READER_IDLE_STATE_EVENT);
    }

    @Test
    public void testWriterIdle() throws Exception {
        IdleStateHandler idleStateHandler = new IdleStateHandler(
                false, 0L, 1L, 0L, TimeUnit.SECONDS);

        anyIdle(idleStateHandler, IdleStateEvent.FIRST_WRITER_IDLE_STATE_EVENT,
                IdleStateEvent.WRITER_IDLE_STATE_EVENT, IdleStateEvent.WRITER_IDLE_STATE_EVENT);
    }

    @Test
    public void testAllIdle() throws Exception {
        IdleStateHandler idleStateHandler = new IdleStateHandler(
                false, 0L, 0L, 1L, TimeUnit.SECONDS);

        anyIdle(idleStateHandler, IdleStateEvent.FIRST_ALL_IDLE_STATE_EVENT,
                IdleStateEvent.ALL_IDLE_STATE_EVENT, IdleStateEvent.ALL_IDLE_STATE_EVENT);
    }

    private static void anyIdle(IdleStateHandler idleStateHandler, Object... expected) throws Exception {
        assertThat(expected.length).isGreaterThanOrEqualTo(1);

        final List<Object> events = new ArrayList<Object>();
        ChannelInboundHandlerAdapter handler = new ChannelInboundHandlerAdapter() {
            @Override
            public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                events.add(evt);
            }
        };

        EmbeddedChannel channel = new EmbeddedChannel(idleStateHandler, handler);
        channel.freezeTime();
        try {
            // For each expected event advance the ticker and run() the task. Each
            // step should yield in an IdleStateEvent because we haven't written
            // or read anything from the channel.
            for (int i = 0; i < expected.length; i++) {
                channel.advanceTimeBy(1, TimeUnit.SECONDS);
                channel.runPendingTasks();
            }

            assertEquals(expected.length, events.size());

            // Compare the expected with the actual IdleStateEvents
            for (int i = 0; i < expected.length; i++) {
                Object evt = events.get(i);
                assertSame(expected[i], evt, "Element " + i + " is not matching");
            }
        } finally {
            channel.finishAndReleaseAll();
        }
    }

    @Test
    public void testResetReader() throws Exception {
        final IdleStateHandler idleStateHandler = new IdleStateHandler(
                false, 1L, 0L, 0L, TimeUnit.SECONDS);

        Action action = new Action() {
            @Override
            public void run(EmbeddedChannel channel) throws Exception {
                idleStateHandler.resetReadTimeout();
            }
        };

        anyNotIdle(idleStateHandler, action, IdleStateEvent.FIRST_READER_IDLE_STATE_EVENT);
    }

    @Test
    public void testResetWriter() throws Exception {

Frequently Asked Questions

What is the IdleStateHandlerTest class?
IdleStateHandlerTest is a class in the netty codebase, defined in handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java.
Where is IdleStateHandlerTest defined?
IdleStateHandlerTest is defined in handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java at line 37.

Analyze Your Own Codebase

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

Try Supermodel Free