Skip to content
代码片段 群组 项目
未验证 提交 c12348ac 编辑于 作者: Nikolay's avatar Nikolay 提交者: GitHub
浏览文件

MINOR: Remove unused code from BrokerEndPoint (#12368)

Removes unused methods from `BrokerEndPoint`:

* `createBrokerEndPoint(Int, String)`
* `readFrom(buffer: ByteBuffer)`
* `connectionString(): String`
* `writeTo(buffer: ByteBuffer)`
* `sizeInBytes: Int`

Reviewers: dengziming <dengziming1993@gmail.com>, Luke Chen <showuon@gmail.com>, Jason Gustafson <jason@confluent.io>
上级 6bf5bfc2
No related branches found
No related tags found
无相关合并请求
......@@ -16,12 +16,6 @@
*/
package kafka.cluster
import java.nio.ByteBuffer
import kafka.api.ApiUtils._
import org.apache.kafka.common.KafkaException
import org.apache.kafka.common.utils.Utils._
object BrokerEndPoint {
private val uriParseExp = """\[?([0-9a-zA-Z\-%._:]*)\]?:([0-9]+)""".r
......@@ -36,23 +30,6 @@ object BrokerEndPoint {
case _ => None
}
}
/**
* BrokerEndPoint URI is host:port or [ipv6_host]:port
* Note that unlike EndPoint (or listener) this URI has no security information.
*/
def createBrokerEndPoint(brokerId: Int, connectionString: String): BrokerEndPoint = {
parseHostPort(connectionString).map { case (host, port) => new BrokerEndPoint(brokerId, host, port) }.getOrElse {
throw new KafkaException("Unable to parse " + connectionString + " to a broker endpoint")
}
}
def readFrom(buffer: ByteBuffer): BrokerEndPoint = {
val brokerId = buffer.getInt()
val host = readShortString(buffer)
val port = buffer.getInt()
BrokerEndPoint(brokerId, host, port)
}
}
/**
......@@ -63,20 +40,6 @@ object BrokerEndPoint {
* This allows us to keep the wire protocol with the clients unchanged where the protocol is not needed.
*/
case class BrokerEndPoint(id: Int, host: String, port: Int) {
def connectionString(): String = formatAddress(host, port)
def writeTo(buffer: ByteBuffer): Unit = {
buffer.putInt(id)
writeShortString(buffer, host)
buffer.putInt(port)
}
def sizeInBytes: Int =
4 + /* broker Id */
4 + /* port */
shortStringLength(host)
override def toString: String = {
s"BrokerEndPoint(id=$id, host=$host:$port)"
}
......
......@@ -199,34 +199,6 @@ class BrokerEndPointTest {
broker.features)
}
@Test
def testBrokerEndpointFromUri(): Unit = {
var connectionString = "localhost:9092"
var endpoint = BrokerEndPoint.createBrokerEndPoint(1, connectionString)
assertEquals("localhost", endpoint.host)
assertEquals(9092, endpoint.port)
//KAFKA-3719
connectionString = "local_host:9092"
endpoint = BrokerEndPoint.createBrokerEndPoint(1, connectionString)
assertEquals("local_host", endpoint.host)
assertEquals(9092, endpoint.port)
// also test for ipv6
connectionString = "[::1]:9092"
endpoint = BrokerEndPoint.createBrokerEndPoint(1, connectionString)
assertEquals("::1", endpoint.host)
assertEquals(9092, endpoint.port)
// test for ipv6 with % character
connectionString = "[fe80::b1da:69ca:57f7:63d8%3]:9092"
endpoint = BrokerEndPoint.createBrokerEndPoint(1, connectionString)
assertEquals("fe80::b1da:69ca:57f7:63d8%3", endpoint.host)
assertEquals(9092, endpoint.port)
// add test for uppercase in hostname
connectionString = "MyHostname:9092"
endpoint = BrokerEndPoint.createBrokerEndPoint(1, connectionString)
assertEquals("MyHostname", endpoint.host)
assertEquals(9092, endpoint.port)
}
@Test
def testEndpointFromUri(): Unit = {
var connectionString = "PLAINTEXT://localhost:9092"
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册