MINOR: Add test brokers to list as they are created to ensure cleanup
Author: Rajini Sivaram
Reviewers: Apurva Mehta Ismael Juma
Closes from rajinisivaram/MINOR-shutdown-brokers
@@ -28,7 +28,7 @@ import org.apache.kafka.common.protocol.SecurityProtocol
import org.apache.kafka.common.security.auth.KafkaPrincipal
import org.junit.{After, Before}
-import scala.collection.mutable.Buffer
+import scala.collection.mutable.{ArrayBuffer, Buffer}
import java.util.Properties
import org.apache.kafka.common.network.ListenerName
@@ -38,7 +38,7 @@ import org.apache.kafka.common.network.ListenerName
*/
abstract class KafkaServerTestHarness extends ZooKeeperTestHarness {
var instanceConfigs: Seq[KafkaConfig] = null
- var servers: Buffer[KafkaServer] = null
+ var servers: Buffer[KafkaServer] = new ArrayBuffer
var brokerList: String = null
var alive: Array[Boolean] = null
val kafkaPrincipalType = KafkaPrincipal.USER_TYPE
@@ -88,7 +88,10 @@ abstract class KafkaServerTestHarness extends ZooKeeperTestHarness {
// default implementation is a no-op, it is overridden by subclasses if required
configureSecurityBeforeServersStart()
- servers = configs.map(TestUtils.createServer(_)).toBuffer
+ // Add each broker to `servers` buffer as soon as it is created to ensure that brokers
+ // are shutdown cleanly in tearDown even if a subsequent broker fails to start
+ for (config <- configs)
+ servers += TestUtils.createServer(config)
brokerList = TestUtils.bootstrapServers(servers, listenerName)
alive = new Array[Boolean](servers.length)
Arrays.fill(alive, true)
