Class TestUtils
java.lang.Object
org.apache.kafka.common.network.netty.TestUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic io.netty.handler.ssl.SslContextBuild a server SSL context to use for testing.static NettyNioEchoServercreateNettyEchoServer(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) static NettyNioEchoServercreateNettyEchoServer(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) static NettyNioEchoServercreateNettyEchoServer(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.Channelstatic <T extends org.apache.kafka.common.network.netty.NettyRawBytesStream>
TmockNettyStream(Class<T> classToMock) Create mock NettyStream either mocking NettyRawBytesStream or NettyHttp2Stream with properly mocked measureEventLoopTimestatic ByteBufferReturn a fully complete serialized response that can then be processed.static io.netty.handler.codec.http2.Http2HeadersstreamCreationHeaders(Integer brokerId) Create HTTP/2 headers for stream creation for testing purposes.static io.netty.handler.codec.http2.Http2HeadersstreamCreationHeaders(String physicalClusterId, Integer brokerId) Creates Http2Headers to be used for creating netty stream.static io.netty.handler.ssl.SslContextCreate a client SSL context that trusts all certificates.static io.netty.handler.ssl.SslContexttrustAllCertsSSlContext(boolean addApn) Create a client SSL context that trusts all certificates.static io.netty.handler.ssl.SslContexttrustAllCertsSSlContext(boolean addApn, List<String> protocols) Create a client SSL context that trusts all certificates.static io.netty.handler.ssl.SslContexttrustAllCertsSSlContext(boolean addApn, List<String> ciphers, List<String> protocols) Create a client SSL context that trusts all certificates.static io.netty.handler.ssl.SslContexttrustAllCertsSSlContext(List<String> protocols) Create a client SSL context that trusts all certificates.
-
Field Details
-
ONE_MB
public static final int ONE_MB- See Also:
-
PHYSICAL_CLUSTER_ID
- See Also:
-
INVALID_BROKER_ID
-
-
Method Details
-
buildServerSslContext
-
trustAllCertsSSlContext
public static io.netty.handler.ssl.SslContext trustAllCertsSSlContext()Create a client SSL context that trusts all certificates. -
trustAllCertsSSlContext
-
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 contextprotocols- 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 contextciphers- list of ciphers to use, or null to use default ciphersprotocols- list of protocols to use, or null to use default protocols, valid values are "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"
-
handlers
Return list of handlers in the pipeline of the given channel. -
streamCreationHeaders
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 headersbrokerId- 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
Http2StreamChannelthat 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
Return a fully complete serialized response that can then be processed. The method arbitrarily picks AlterConfigsResponse for this purpose.- Throws:
IOException
-