Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-12] Add ability to set broker properties. #13

Merged
merged 20 commits into from
May 17, 2018
Merged

[issue-12] Add ability to set broker properties. #13

merged 20 commits into from
May 17, 2018

Conversation

Crim
Copy link
Collaborator

@Crim Crim commented May 16, 2018

for #12

  • Issue-12 Added ability to pass broker properties to be used by test kafka service instance.

  • Added helper method getAdminClient() on KafkaTestServer to get a configured AdminClient instance.

  • Deprecated Kafka-JUnit5 @ExtendWith annotation implementations. This has been replaced in favor of @RegisterExtension annotation. Review README.md for more information on updated usage instructions.

  • Deprecated KafkaTestServer constructor: public KafkaTestServer(final String localHostname)

    This constructor was replaced with the constructor KafkaTestServer(final Properties overrideBrokerProperties) where overrideBrokerProperties should contain the property host.name set to the hostname or IP address Kafka should use.

@Crim Crim requested a review from stanlemon May 16, 2018 02:59
/**
* Defines overridden broker properties.
*/
private final Properties overrideBrokerProperties = new Properties();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just call this brokerProperties?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was more descriptive, since you do not have provide a complete configuration, just whatever properties you want to set with a fall back to the libraries defaults.

Thoughts?

* @param localHostname What IP or hostname to advertise services on.
* @param overrideBrokerProperties Define Kafka broker properties.
*/
public KafkaTestServer(final String localHostname, final Properties overrideBrokerProperties) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of feel like you should pull hostname from the supplied properties rather than take this in as a parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! To avoid breaking backwards compatibility I've left this constructor, but marked it deprecated.

kafkaProperties.setProperty("advertised.listeners", "PLAINTEXT://" + localHostname + ":" + kafkaPort);
kafkaProperties.setProperty("listeners", "PLAINTEXT://" + localHostname + ":" + kafkaPort);
setPropertyIfNotSet(brokerProperties, "host.name", localHostname);
setPropertyIfNotSet(brokerProperties, "advertised.host.name", localHostname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you should get the hostname property you set one lime above for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

setPropertyIfNotSet(brokerProperties, "listeners", "PLAINTEXT://" + localHostname + ":" + kafkaPort);

// Set other defaults if not defined.
setPropertyIfNotSet(brokerProperties, "auto.create.topics.enable", "true");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ewww, is this legit? Never notices that before. Ditto the numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm? what ya mean?

final Properties overrideProperties = new Properties();
overrideProperties.put("broker.id", expectedBrokerId);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@@ -6,4 +6,4 @@
.settings/
target/
README.md.bak

*.versionsBackup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maven plugin that updates release versions creates backups of POM files with this extension. Just avoiding having those checked in by accident.

Copy link
Contributor

@stanlemon stanlemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This grew fast! I like the changes though :shipit:

Copy link

@Cs4r Cs4r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from minor comments, it looks very good to me.

@@ -84,7 +84,7 @@ Include this library in your project's POM with test scope. **You'll also need
<dependency>
<groupId>com.salesforce.kafka.test</groupId>
<artifactId>kafka-junit4</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be 2.3.0? since your change isn't a bugfix but a backwards-compatible functionality

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call.

@@ -32,13 +32,13 @@
<parent>
<artifactId>kafka-junit</artifactId>
<groupId>com.salesforce.kafka.test</groupId>
<version>2.2.0</version>
<version>2.2.1</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment related to versioning.

logger.info("Shutting down zookeeper test server");

// If we don't have an instance
if (zookeeperTestServer == null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably have chosen and if-else statement plus a try-catch-finally

}

// null out reference
zookeeperTestServer = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely. As the code stands we start the instance when we create the instance by telling the constructor to start. We could re-use the instance and just call start on it if it exists.

@Crim
Copy link
Collaborator Author

Crim commented May 17, 2018

OK, I feel good about this. I could probably spend more time DRY'ing out all these duplicated tests and what not, but I'll save that for another day.

Thanks for your help reviewing!

@Crim Crim merged commit 2a5f8d9 into master May 17, 2018
@Crim Crim deleted the sp/ISSUE-12 branch May 17, 2018 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants