Skip to content

Commit

Permalink
[hotfix][kafka,test] Make brokers list final and avoid potential null…
Browse files Browse the repository at this point in the history
… pointer exceptions
  • Loading branch information
pnowojski committed May 7, 2019
1 parent 5b49f17 commit 3b1976a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
public class KafkaTestEnvironmentImpl extends KafkaTestEnvironment {

protected static final Logger LOG = LoggerFactory.getLogger(KafkaTestEnvironmentImpl.class);
private final List<KafkaServer> brokers = new ArrayList<>();
private File tmpZkDir;
private File tmpKafkaParent;
private List<File> tmpKafkaDirs;
private List<KafkaServer> brokers;
private TestingServer zookeeper;
private String zookeeperConnectionString;
private String brokerConnectionString = "";
Expand Down Expand Up @@ -258,14 +258,13 @@ public void prepare(Config config) throws Exception {
}

zookeeper = null;
brokers = null;
brokers.clear();

zookeeper = new TestingServer(-1, tmpZkDir);
zookeeperConnectionString = zookeeper.getConnectString();
LOG.info("Starting Zookeeper with zookeeperConnectionString: {}", zookeeperConnectionString);

LOG.info("Starting KafkaServer");
brokers = new ArrayList<>(config.getKafkaServersNumber());

ListenerName listenerName = ListenerName.forSecurityProtocol(config.isSecureMode() ? SecurityProtocol.SASL_PLAINTEXT : SecurityProtocol.PLAINTEXT);
for (int i = 0; i < config.getKafkaServersNumber(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
public class KafkaTestEnvironmentImpl extends KafkaTestEnvironment {

protected static final Logger LOG = LoggerFactory.getLogger(KafkaTestEnvironmentImpl.class);
private final List<KafkaServer> brokers = new ArrayList<>();
private File tmpZkDir;
private File tmpKafkaParent;
private List<File> tmpKafkaDirs;
private List<KafkaServer> brokers;
private TestingServer zookeeper;
private String zookeeperConnectionString;
private String brokerConnectionString = "";
Expand Down Expand Up @@ -117,14 +117,13 @@ public void prepare(Config config) throws Exception {
}

zookeeper = null;
brokers = null;
brokers.clear();

zookeeper = new TestingServer(-1, tmpZkDir);
zookeeperConnectionString = zookeeper.getConnectString();
LOG.info("Starting Zookeeper with zookeeperConnectionString: {}", zookeeperConnectionString);

LOG.info("Starting KafkaServer");
brokers = new ArrayList<>(config.getKafkaServersNumber());

ListenerName listenerName = ListenerName.forSecurityProtocol(config.isSecureMode() ? SecurityProtocol.SASL_PLAINTEXT : SecurityProtocol.PLAINTEXT);
for (int i = 0; i < config.getKafkaServersNumber(); i++) {
Expand Down

0 comments on commit 3b1976a

Please sign in to comment.