You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-32Lines changed: 38 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,52 +20,56 @@ scalatest-embedded-kafka is available on Bintray and Maven Central, compiled for
20
20
* In your `build.sbt` file add the following dependency: `"net.manub" %% "scalatest-embedded-kafka" % "0.9.0" % "test"`
21
21
* Have your `Spec` extend the `EmbeddedKafka` trait.
22
22
* Enclose the code that needs a running instance of Kafka within the `withRunningKafka` closure.
23
+
```scala
24
+
classMySpecextendsWordSpecwithEmbeddedKafka {
23
25
24
-
class MySpec extends WordSpec with EmbeddedKafka {
25
-
26
-
"runs with embedded kafka" should {
26
+
"runs with embedded kafka" should {
27
27
28
-
withRunningKafka {
29
-
// ... code goes here
30
-
}
31
-
32
-
}
28
+
withRunningKafka {
29
+
// ... code goes here
30
+
}
33
31
32
+
}
33
+
```
34
34
*In-memory Zookeeper and Kafka will be instantiated respectively on port 6000 and 6001 and automatically shutdown at the end of the test.
35
35
36
36
###Use without the `withRunningKafka` method
37
37
38
38
A `EmbeddedKafka` companion objectis provided for usage without the `EmbeddedKafka` trait. Zookeeper and Kafka can be started an stopped in a programmatic way.
39
39
40
-
class MySpec extends WordSpec {
40
+
```scala
41
+
classMySpecextendsWordSpec {
41
42
42
-
"runs with embedded kafka" should {
43
-
44
-
EmbeddedKafka.start()
45
-
46
-
// ... code goes here
47
-
48
-
EmbeddedKafka.stop()
49
-
50
-
}
43
+
"runs with embedded kafka" should {
44
+
45
+
EmbeddedKafka.start()
46
+
47
+
// ... code goes here
48
+
49
+
EmbeddedKafka.stop()
50
+
51
+
}
52
+
```
51
53
52
54
Please note that in order to avoid Kafka instances not shutting down properly, it's recommended to call `EmbeddedKafka.stop()` in a `after` block or in a similar teardown logic.
53
55
54
56
##Configuration
55
57
56
58
It's possible to change the ports on which Zookeeper and Kafka are started by providing an implicit `EmbeddedKafkaConfig`
57
59
58
-
class MySpec extends WordSpec with EmbeddedKafka {
59
-
60
-
"runs with embedded kafka on a specific port" should {
60
+
```scala
61
+
classMySpecextendsWordSpecwithEmbeddedKafka {
61
62
62
-
implicit val config = EmbeddedKafkaConfig(kafkaPort = 12345)
63
+
"runs with embedded kafka on a specific port" should {
This works for both `withRunningKafka` and `EmbeddedKafka.start()`
71
75
@@ -79,12 +83,14 @@ are.
79
83
80
84
The `EmbeddedKafka` traitprovides also some utility methods to interact with the embedded kafka, in order to set preconditions or verifications in your specs:
81
85
82
-
def publishToKafka(topic: String, message: String): Unit
0 commit comments