Skip to content

Implement withRunningKafkaOnFoundPort #76

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

Merged
merged 4 commits into from
Jun 27, 2017

Conversation

mikemintz
Copy link
Contributor

This implements withRunningKafkaOnFoundPort, which allows users to run zookeeper/kafka on arbitrary available ports instead of having to hard-code specific ports. This is useful to make tests more reliable, especially when running tests in parallel or on machines where other tests or services may be running with port numbers you can't control.

I'm happy to refactor this however you like. It might be cleaner to just change the implementation of withRunningKafka to take body: EmbeddedKafkaConfig => T instead of body: => T, since that only requires a single implementation. But that breaks backwards compatibility, so I didn't go that direction for now.

Copy link
Owner

@manub manub left a comment

Choose a reason for hiding this comment

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

This looks good to me - but apart from a small change in code could you also please update the README.md? I think the 0 port setting is important enough to get it mentioned on the README

consumeFirstStringMessageFrom("topic")(actualConfig2) shouldBe "message2"
val allConfigs = Seq(userDefinedConfig, actualConfig1, actualConfig2)
// Confirm both actual configs are running on separate non-zero ports, but otherwise equal
allConfigs.map(_.kafkaPort).distinct.size shouldBe 3
Copy link
Owner

Choose a reason for hiding this comment

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

can you please use .distinct should have size 3? here and wherever you use to check sizes

@mikemintz mikemintz force-pushed the run-kafka-on-available-port branch 3 times, most recently from d92d200 to 6f82e90 Compare June 26, 2017 03:54
This is useful for writing tests that configure kafka/zookeeper to
listen on port 0, i.e. listen on an arbitrary available port.
@mikemintz mikemintz force-pushed the run-kafka-on-available-port branch from 6f82e90 to 3508fe0 Compare June 26, 2017 17:34
@mikemintz
Copy link
Contributor Author

Thanks for reviewing this. I updated the README and test syntax, let me know if there's anything else I should change.

@manub manub merged commit 53e88e4 into manub:master Jun 27, 2017
@manub
Copy link
Owner

manub commented Jun 27, 2017

Thanks! Releasing tonight.

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.

2 participants