@SneakyThrows(NoSuchAlgorithmException.class)
    @Override
    public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
        if (msg instanceof MySQLHandshakePacket) {
            MySQLHandshakePacket handshake = (MySQLHandshakePacket) msg;
            MySQLHandshakeResponse41Packet handshakeResponsePacket = new MySQLHandshakeResponse41Packet(MAX_PACKET_SIZE, CHARACTER_SET, username);
            handshakeResponsePacket.setAuthResponse(generateAuthResponse(handshake.getAuthPluginData().getAuthenticationPluginData()));
            handshakeResponsePacket.setCapabilityFlags(generateClientCapability());
            handshakeResponsePacket.setAuthPluginName(MySQLAuthenticationMethod.NATIVE);
            ctx.channel().writeAndFlush(handshakeResponsePacket);
            serverVersion = new MySQLServerVersion(handshake.getServerVersion());
            return;
        }
        if (msg instanceof MySQLAuthSwitchRequestPacket) {
            MySQLAuthSwitchRequestPacket authSwitchRequest = (MySQLAuthSwitchRequestPacket) msg;
            ctx.channel().writeAndFlush(new MySQLAuthSwitchResponsePacket(getAuthPluginResponse(authSwitchRequest)));
            seed = authSwitchRequest.getAuthPluginData().getAuthenticationPluginData();
            return;
        }
        if (msg instanceof MySQLAuthMoreDataPacket) {
            MySQLAuthMoreDataPacket authMoreData = (MySQLAuthMoreDataPacket) msg;
            handleCachingSha2Auth(ctx, authMoreData);
            return;
        }
        if (msg instanceof MySQLOKPacket) {
            ctx.channel().pipeline().remove(this);
            authResultCallback.setSuccess(serverVersion);
            return;
        }
        MySQLErrPacket error = (MySQLErrPacket) msg;
        ctx.channel().close();
        throw new PipelineInternalException(error.getErrorMessage());
    }
@Test
    void assertChannelReadHandshakeInitPacket() throws ReflectiveOperationException {
        MySQLHandshakePacket handshakePacket = new MySQLHandshakePacket(0, false, new MySQLAuthenticationPluginData(new byte[8], new byte[12]));
        handshakePacket.setAuthPluginName(MySQLAuthenticationMethod.NATIVE);
        mysqlNegotiateHandler.channelRead(channelHandlerContext, handshakePacket);
        verify(channel).writeAndFlush(ArgumentMatchers.any(MySQLHandshakeResponse41Packet.class));
        MySQLServerVersion serverVersion = (MySQLServerVersion) Plugins.getMemberAccessor().get(MySQLNegotiateHandler.class.getDeclaredField("serverVersion"), mysqlNegotiateHandler);
        assertThat(Plugins.getMemberAccessor().get(MySQLServerVersion.class.getDeclaredField("major"), serverVersion), is(5));
        assertThat(Plugins.getMemberAccessor().get(MySQLServerVersion.class.getDeclaredField("minor"), serverVersion), is(7));
        assertThat(Plugins.getMemberAccessor().get(MySQLServerVersion.class.getDeclaredField("series"), serverVersion), is(22));
    }