You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by jg...@apache.org on 2022/07/01 17:28:47 UTC

[kafka] branch trunk updated: MINOR: Remove unused code from BrokerEndPoint (#12368)

This is an automated email from the ASF dual-hosted git repository.

jgus pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new c12348ac98 MINOR: Remove unused code from BrokerEndPoint (#12368)
c12348ac98 is described below

commit c12348ac982378b755e104e95d7e1b2cba4c2948
Author: Nikolay <ni...@apache.org>
AuthorDate: Fri Jul 1 20:28:37 2022 +0300

    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 <de...@gmail.com>, Luke Chen <sh...@gmail.com>, Jason Gustafson <ja...@confluent.io>
---
 .../main/scala/kafka/cluster/BrokerEndPoint.scala  | 37 ----------------------
 .../unit/kafka/cluster/BrokerEndPointTest.scala    | 28 ----------------
 2 files changed, 65 deletions(-)

diff --git a/core/src/main/scala/kafka/cluster/BrokerEndPoint.scala b/core/src/main/scala/kafka/cluster/BrokerEndPoint.scala
index b2b36af09d..0137b6926f 100644
--- a/core/src/main/scala/kafka/cluster/BrokerEndPoint.scala
+++ b/core/src/main/scala/kafka/cluster/BrokerEndPoint.scala
@@ -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)"
   }
diff --git a/core/src/test/scala/unit/kafka/cluster/BrokerEndPointTest.scala b/core/src/test/scala/unit/kafka/cluster/BrokerEndPointTest.scala
index f36ce9b406..9dbb00d184 100644
--- a/core/src/test/scala/unit/kafka/cluster/BrokerEndPointTest.scala
+++ b/core/src/test/scala/unit/kafka/cluster/BrokerEndPointTest.scala
@@ -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"