-
Notifications
You must be signed in to change notification settings - Fork 133
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
Write zio-kafka-testkit
documentation
#846
Conversation
ae20ca3
to
8f775d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! We really need something like this.
Would you like me to pick up a part of the work? For example, I could write some examples for testing zio-kafka consumers.
``` | ||
|
||
Let's study some simple examples of tests you can write with the `zio-kafka-testkit` and `zio-test`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two important techniques for testing zio-kafka apps. One is to produce test data so that we can test a consumer, two is to consume from a topic so that we can test a producer. I would love to see that described in the introduction here.
zio-kafka-example/src/test/scala/zio/kafka/example/ProducerSpec.scala
Outdated
Show resolved
Hide resolved
zio-kafka-testkit/src/main/scala/zio/kafka/testkit/embedded/Kafka.scala
Outdated
Show resolved
Hide resolved
zio-kafka-testkit/src/main/scala/zio/kafka/testkit/embedded/Kafka.scala
Outdated
Show resolved
Hide resolved
zio-kafka-testkit/src/main/scala/zio/kafka/testkit/embedded/Kafka.scala
Outdated
Show resolved
Hide resolved
zio-kafka-testkit/src/main/scala/zio/kafka/testkit/embedded/Kafka.scala
Outdated
Show resolved
Hide resolved
89cb239
to
61c8b6a
Compare
val producer: ZLayer[Kafka, Throwable, Producer] = | ||
(ZLayer.fromZIO(producerSettings) ++ ZLayer.succeed(Serde.string: Serializer[Any, String])) >>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ZLayer.succeed(Serde.string: Serializer[Any, String])
was useless
(ZLayer.fromZIO(transactionalProducerSettings) ++ ZLayer.succeed( | ||
Serde.string: Serializer[Any, String] | ||
)) >>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ZLayer.succeed(Serde.string: Serializer[Any, String])
was useless
c8a80ff
to
d319dc2
Compare
c0397a4
to
99b3989
Compare
3c1a2e8
to
2e72287
Compare
f8a2597
to
8e9ece8
Compare
2e72287
to
6bc6ace
Compare
6bc6ace
to
e1613c4
Compare
1bc7ae4
to
3b08395
Compare
40bb465
to
95e9fa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Some small remarks but nothing exciting.
The `sequential` aspect from zio-test is used to specify that the tests in the suite must be run sequentially. This is necessary because Kafka is a shared resource. | ||
We don't want tests to interfere with each other. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to write your tests such that they do not interfere with each other. Therefore I propose to weaken the text a bit to:
The `sequential` aspect from zio-test is used to specify that the tests in the suite must be run sequentially. This is necessary because Kafka is a shared resource. | |
We don't want tests to interfere with each other. | |
The `sequential` aspect from zio-test is used to specify that the tests in the suite must be run sequentially instead of concurrently. Kafka is shared between the tests so running them sequentially prevents tests to influence each other. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're saying the same thing but differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original text uses the word 'necessary'. This is strictly not correct because there are other ways to achieve the same goal.
Finally, we annotate the suite with the `timeout` and `sequential` aspects. | ||
The `timeout` aspect from zio-test is used to specify a timeout for the entire suite. If the suite takes more than 5 minutes to run, it will fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose that we split the paragraph in 2 (add a newline after it will fail
):
Finally, we annotate the suite with the `timeout` and `sequential` aspects. | |
The `timeout` aspect from zio-test is used to specify a timeout for the entire suite. If the suite takes more than 5 minutes to run, it will fail. | |
Finally, we annotate the suite with the `timeout` and `sequential` aspects. | |
The `timeout` aspect from zio-test is used to specify a timeout for the entire suite. If the suite takes more than 5 minutes to run, it will fail. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep these things grouped.
The paragraph is structured in 3 parts:
- Introduction to the concept we'll study in this paragraph: "Finally, we annotate the suite with the
timeout
andsequential
aspects." - The first concept: "The
timeout
aspect from zio-test ..." - The second concept: "The
sequential
aspect from zio-test ..."
|
||
Finally, we use the `KafkaRandom` trait from zio-kafka-testkit and its methods to generate random values for the Consumer client ID, the Consumer group ID and the topic name. | ||
More details about this `KafkaRandom` trait [later in this page](#kafkarandom-trait). | ||
Using random values for these parameters is important to avoid conflicts between tests as we share one Kafka instance between all the tests of the suite. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying we share a Kafka instance is enough, how is less important for this paragraph.
Also, as I have said before, I am not in favor of using random values. I prefer my test parameters to be the same for each run. (With a big exception for property based testing.)
Also, since this text is important, IMHO it should be a new paragraph.
Using random values for these parameters is important to avoid conflicts between tests as we share one Kafka instance between all the tests of the suite. | |
Using different values for these parameters is important to avoid conflicts between tests as we share one Kafka instance between the tests. Using random values is a convenient way to make sure they are different. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That answer disappoints me a bit. I'd have preferred you tell me where I am wrong.
zio-kafka-bench/src/main/scala/zio/kafka/bench/ConsumersComparisonBenchmark.scala
Show resolved
Hide resolved
…ke it more explicit that it's something that can be used by zio-kafka users Also, change the base namespace of this module from `zio.kafka` to `zio.kafka.testkit` to make things more explicit
Co-authored-by: Erik van Oosten <e.vanoosten@grons.nl>
Related to #845
The doc can be read here: https://github.com/zio/zio-kafka/blob/testing_doc/docs/writing-tests.md
TODO:
ZIOSpecWithKafka
doc