Class TestUtils

java.lang.Object
org.apache.kafka.common.network.netty.TestUtils

public class TestUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Integer
     
    static final int
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.netty.handler.ssl.SslContext
    Build a server SSL context to use for testing.
    createNettyEchoServer(org.apache.kafka.common.network.ListenerName listenerName, org.apache.kafka.common.security.auth.SecurityProtocol securityProtocol, org.apache.kafka.common.config.AbstractConfig serverConfig, org.apache.kafka.common.security.authenticator.CredentialCache credentialCache, int failedAuthenticationDelayMs, org.apache.kafka.common.utils.Time time)
     
    createNettyEchoServer(org.apache.kafka.common.network.ListenerName listenerName, org.apache.kafka.common.security.auth.SecurityProtocol securityProtocol, org.apache.kafka.common.config.AbstractConfig serverConfig, org.apache.kafka.common.security.authenticator.CredentialCache credentialCache, int failedAuthenticationDelayMs, org.apache.kafka.common.utils.Time time, org.apache.kafka.common.security.token.delegation.internals.DelegationTokenCache tokenCache, org.apache.kafka.common.network.ProxyProtocolEngineFactory proxyProtocolEngineFactory)
     
    createNettyEchoServer(org.apache.kafka.common.network.ListenerName listenerName, org.apache.kafka.common.security.auth.SecurityProtocol securityProtocol, org.apache.kafka.common.config.AbstractConfig serverConfig, org.apache.kafka.common.security.authenticator.CredentialCache credentialCache, org.apache.kafka.common.utils.Time time)
     
    static List<io.netty.channel.ChannelHandler>
    handlers(io.netty.channel.Channel channel)
    Return list of handlers in the pipeline of the given channel.
    static io.netty.channel.Channel
     
    static <T extends org.apache.kafka.common.network.netty.NettyRawBytesStream>
    T
    mockNettyStream(Class<T> classToMock)
    Create mock NettyStream either mocking NettyRawBytesStream or NettyHttp2Stream with properly mocked measureEventLoopTime
    static ByteBuffer
    Return a fully complete serialized response that can then be processed.
    static io.netty.handler.codec.http2.Http2Headers
    Create HTTP/2 headers for stream creation for testing purposes.
    static io.netty.handler.codec.http2.Http2Headers
    streamCreationHeaders(String physicalClusterId, Integer brokerId)
    Creates Http2Headers to be used for creating netty stream.
    static io.netty.handler.ssl.SslContext
    Create a client SSL context that trusts all certificates.
    static io.netty.handler.ssl.SslContext
    trustAllCertsSSlContext(boolean addApn)
    Create a client SSL context that trusts all certificates.
    static io.netty.handler.ssl.SslContext
    trustAllCertsSSlContext(boolean addApn, List<String> protocols)
    Create a client SSL context that trusts all certificates.
    static io.netty.handler.ssl.SslContext
    trustAllCertsSSlContext(boolean addApn, List<String> ciphers, List<String> protocols)
    Create a client SSL context that trusts all certificates.
    static io.netty.handler.ssl.SslContext
    Create a client SSL context that trusts all certificates.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • buildServerSslContext

      public static io.netty.handler.ssl.SslContext buildServerSslContext() throws Exception
      Build a server SSL context to use for testing.
      Throws:
      Exception
    • trustAllCertsSSlContext

      public static io.netty.handler.ssl.SslContext trustAllCertsSSlContext()
      Create a client SSL context that trusts all certificates.
    • trustAllCertsSSlContext

      public static io.netty.handler.ssl.SslContext trustAllCertsSSlContext(List<String> protocols)
      Create a client SSL context that trusts all certificates.
      Parameters:
      protocols - list of protocols to use, or null to use default protocols, valid values are "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"
    • trustAllCertsSSlContext

      public static io.netty.handler.ssl.SslContext trustAllCertsSSlContext(boolean addApn)
      Create a client SSL context that trusts all certificates.
      Parameters:
      addApn - whether to add application protocol negotiation (APN) to the SSL context
    • trustAllCertsSSlContext

      public static io.netty.handler.ssl.SslContext trustAllCertsSSlContext(boolean addApn, List<String> protocols)
      Create a client SSL context that trusts all certificates.
      Parameters:
      addApn - whether to add application protocol negotiation (APN) to the SSL context
      protocols - list of protocols to use, or null to use default protocols, valid values are "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"
    • trustAllCertsSSlContext

      public static io.netty.handler.ssl.SslContext trustAllCertsSSlContext(boolean addApn, List<String> ciphers, List<String> protocols)
      Create a client SSL context that trusts all certificates.
      Parameters:
      addApn - whether to add application protocol negotiation (APN) to the SSL context
      ciphers - list of ciphers to use, or null to use default ciphers
      protocols - list of protocols to use, or null to use default protocols, valid values are "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"
    • handlers

      public static List<io.netty.channel.ChannelHandler> handlers(io.netty.channel.Channel channel)
      Return list of handlers in the pipeline of the given channel.
    • streamCreationHeaders

      public static io.netty.handler.codec.http2.Http2Headers streamCreationHeaders(Integer brokerId)
      Create HTTP/2 headers for stream creation for testing purposes. Use hardcoded physical cluster ID in the http/2 headers.
      Parameters:
      brokerId - the broker ID to use in the http/2 headers
    • streamCreationHeaders

      public static io.netty.handler.codec.http2.Http2Headers streamCreationHeaders(String physicalClusterId, Integer brokerId)
      Creates Http2Headers to be used for creating netty stream.
      Parameters:
      physicalClusterId - the physical cluster ID to use in the http/2 headers
      brokerId - the broker ID to use in the http/2 headers
    • mockConnectionChannel

      public static io.netty.channel.Channel mockConnectionChannel()
      Returns:
      a mock of parent channel of Http2StreamChannel that has an HTTP/2 frame codec and connection.
    • mockNettyStream

      public static <T extends org.apache.kafka.common.network.netty.NettyRawBytesStream> T mockNettyStream(Class<T> classToMock)
      Create mock NettyStream either mocking NettyRawBytesStream or NettyHttp2Stream with properly mocked measureEventLoopTime
      Type Parameters:
      T - the class to mock
      Parameters:
      classToMock - either NettyRawBytesStream.class or NettyHttp2Stream.class
      Returns:
      mock NettyStream
    • createNettyEchoServer

      public static NettyNioEchoServer createNettyEchoServer(org.apache.kafka.common.network.ListenerName listenerName, org.apache.kafka.common.security.auth.SecurityProtocol securityProtocol, org.apache.kafka.common.config.AbstractConfig serverConfig, org.apache.kafka.common.security.authenticator.CredentialCache credentialCache, org.apache.kafka.common.utils.Time time) throws Exception
      Throws:
      Exception
    • createNettyEchoServer

      public static NettyNioEchoServer createNettyEchoServer(org.apache.kafka.common.network.ListenerName listenerName, org.apache.kafka.common.security.auth.SecurityProtocol securityProtocol, org.apache.kafka.common.config.AbstractConfig serverConfig, org.apache.kafka.common.security.authenticator.CredentialCache credentialCache, int failedAuthenticationDelayMs, org.apache.kafka.common.utils.Time time) throws Exception
      Throws:
      Exception
    • createNettyEchoServer

      public static NettyNioEchoServer createNettyEchoServer(org.apache.kafka.common.network.ListenerName listenerName, org.apache.kafka.common.security.auth.SecurityProtocol securityProtocol, org.apache.kafka.common.config.AbstractConfig serverConfig, org.apache.kafka.common.security.authenticator.CredentialCache credentialCache, int failedAuthenticationDelayMs, org.apache.kafka.common.utils.Time time, org.apache.kafka.common.security.token.delegation.internals.DelegationTokenCache tokenCache, org.apache.kafka.common.network.ProxyProtocolEngineFactory proxyProtocolEngineFactory) throws Exception
      Throws:
      Exception
    • serializedResponse

      public static ByteBuffer serializedResponse() throws IOException
      Return a fully complete serialized response that can then be processed. The method arbitrarily picks AlterConfigsResponse for this purpose.
      Throws:
      IOException