Class PreboundSocketFactoryManager
java.lang.Object
org.apache.kafka.common.test.PreboundSocketFactoryManager
- All Implemented Interfaces:
AutoCloseable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intgetOrCreatePortForListener(int nodeId, String listener) Get a specific port number.org.apache.kafka.server.ServerSocketFactorygetOrCreateSocketFactory(int nodeId) Get or create a socket factory object associated with a given node ID.getSocketForListenerAndMarkAsUsed(int nodeId, String listener) Get a socket from this manager, mark it as used, and return it.voidswapPortsForListener(int nodeId1, int nodeId2, String listener, int brokerPort1, int brokerPort2) Swap the port numbers assigned to two nodes.
-
Constructor Details
-
PreboundSocketFactoryManager
public PreboundSocketFactoryManager()
-
-
Method Details
-
getSocketForListenerAndMarkAsUsed
Get a socket from this manager, mark it as used, and return it.- Parameters:
nodeId- The ID of the node.listener- The listener for the socket.- Returns:
- null if the socket was not found; the socket, otherwise.
-
getOrCreateSocketFactory
public org.apache.kafka.server.ServerSocketFactory getOrCreateSocketFactory(int nodeId) Get or create a socket factory object associated with a given node ID.- Parameters:
nodeId- The ID of the node.- Returns:
- The socket factory.
-
getOrCreatePortForListener
Get a specific port number. The port will be created if it does not already exist.- Parameters:
nodeId- The ID of the node.listener- The listener for the socket.- Returns:
- The port number.
- Throws:
IOException
-
swapPortsForListener
public void swapPortsForListener(int nodeId1, int nodeId2, String listener, int brokerPort1, int brokerPort2) throws IOException Swap the port numbers assigned to two nodes. This is used to simulate a network routing anomaly, such as a misconfigured proxy.- Parameters:
nodeId1- The ID of the first node.nodeId2- The ID of the second node.listener- The listener for the socket.brokerPort1- The port number used by the first node, to be assigned to the second node.brokerPort2- The port number used by the second node, to be assigned to the first node.- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-