@Override
    public void run() {
        InternalThreadLocalMap internalThreadLocalMap = InternalThreadLocalMap.getAndRemove();
        try {
            if (state == ChannelState.RECEIVED) {
                try {
                    handler.received(channel, message);
                } catch (Exception e) {
                    logger.warn(
                            INTERNAL_ERROR,
                            "unknown error in remoting module",
                            "",
                            "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
                                    + ", message is " + message,
                            e);
                }
            } else {
                switch (state) {
                    case CONNECTED:
                        try {
                            handler.connected(channel);
                        } catch (Exception e) {
                            logger.warn(
                                    INTERNAL_ERROR,
                                    "unknown error in remoting module",
                                    "",
                                    "ChannelEventRunnable handle " + state + " operation error, channel is " + channel,
                                    e);
                        }
                        break;
                    case DISCONNECTED:
                        try {
                            handler.disconnected(channel);
                        } catch (Exception e) {
                            logger.warn(
                                    INTERNAL_ERROR,
                                    "unknown error in remoting module",
                                    "",
                                    "ChannelEventRunnable handle " + state + " operation error, channel is " + channel,
                                    e);
                        }
                        break;
                    case SENT:
                        try {
                            handler.sent(channel, message);
                        } catch (Exception e) {
                            logger.warn(
                                    INTERNAL_ERROR,
                                    "unknown error in remoting module",
                                    "",
                                    "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
                                            + ", message is " + message,
                                    e);
                        }
                        break;
                    case CAUGHT:
                        try {
                            handler.caught(channel, exception);
                        } catch (Exception e) {
                            logger.warn(
                                    INTERNAL_ERROR,
                                    "unknown error in remoting module",
                                    "",
                                    "ChannelEventRunnable handle " + state + " operation error, channel is " + channel
                                            + ", message is: " + message + ", exception is " + exception,
                                    e);
                        }
                        break;
                    default:
                        logger.warn(
                                INTERNAL_ERROR,
                                "unknown error in remoting module",
                                "",
                                "unknown state: " + state + ", message is " + message);
                }
            }
        } finally {
            InternalThreadLocalMap.set(internalThreadLocalMap);
        }
    }
@Test
    void test() throws Exception {
        ChannelEventRunnable.ChannelState[] values = ChannelEventRunnable.ChannelState.values();
        Assertions.assertEquals(Arrays.toString(values), "[CONNECTED, DISCONNECTED, SENT, RECEIVED, CAUGHT]");

        Channel channel = Mockito.mock(Channel.class);
        ChannelHandler handler = Mockito.mock(ChannelHandler.class);
        ChannelEventRunnable connectRunnable =
                new ChannelEventRunnable(channel, handler, ChannelEventRunnable.ChannelState.CONNECTED);
        ChannelEventRunnable disconnectRunnable =
                new ChannelEventRunnable(channel, handler, ChannelEventRunnable.ChannelState.DISCONNECTED);
        ChannelEventRunnable sentRunnable =
                new ChannelEventRunnable(channel, handler, ChannelEventRunnable.ChannelState.SENT);
        ChannelEventRunnable receivedRunnable =
                new ChannelEventRunnable(channel, handler, ChannelEventRunnable.ChannelState.RECEIVED, "");
        ChannelEventRunnable caughtRunnable = new ChannelEventRunnable(
                channel, handler, ChannelEventRunnable.ChannelState.CAUGHT, new RuntimeException());

        connectRunnable.run();
        disconnectRunnable.run();
        sentRunnable.run();
        receivedRunnable.run();
        caughtRunnable.run();

        ArgumentCaptor<Channel> channelArgumentCaptor = ArgumentCaptor.forClass(Channel.class);
        ArgumentCaptor<Throwable> throwableArgumentCaptor = ArgumentCaptor.forClass(Throwable.class);
        ArgumentCaptor<Object> objectArgumentCaptor = ArgumentCaptor.forClass(Object.class);
        Mockito.verify(handler, Mockito.times(1)).connected(channelArgumentCaptor.capture());
        Mockito.verify(handler, Mockito.times(1)).disconnected(channelArgumentCaptor.capture());
        Mockito.verify(handler, Mockito.times(1)).sent(channelArgumentCaptor.capture(), Mockito.any());
        Mockito.verify(handler, Mockito.times(1))
                .received(channelArgumentCaptor.capture(), objectArgumentCaptor.capture());
        Mockito.verify(handler, Mockito.times(1))
                .caught(channelArgumentCaptor.capture(), throwableArgumentCaptor.capture());
    }