Skip to content

Commit 7ce8cf3

Browse files
Alexey RagaAlexey Raga
Alexey Raga
authored and
Alexey Raga
committed
Dev env and how to run tests
1 parent 057f6e6 commit 7ce8cf3

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Icon
2323
### Haskell ###
2424
dist
2525
dist-newstyle
26+
dist-docs*
2627
cabal-dev
2728
*.o
2829
*.hi

README.md

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -215,44 +215,22 @@ _Note:_ this is a semi-naive solution as this waits forever (or until
215215
librdkafka times out). You should make sure that your configuration reflects
216216
the behavior you want out of this functionality.
217217

218-
# Installation
218+
## Running integration tests locally
219219

220-
## Installing librdkafka
220+
[shell.nix](./shell.nix) can be used to provide a working environment that is enough to build and test `hw-kafka-client`.
221221

222-
Although `librdkafka` is available on many platforms, most of
223-
the distribution packages are too old to support `kafka-client`.
224-
As such, we suggest you install from the source:
222+
To be able to run tests locally, `$KAFKA_TEST_BROKER` environment variable is expected to be set (use [shell.nix](./shell.nix) or export manually).
225223

226-
```bash
227-
git clone https://github.com/edenhill/librdkafka
228-
cd librdkafka
229-
./configure
230-
make && make install
231-
```
224+
`$KAFKA_TEST_BROKER` should contain an IP address of an accessible Kafka broker that will be used to run integration tests against.
232225

233-
Sometimes it is helpful to specify openssl includes explicitly:
226+
With [Docker Compose](./docker-compose.yml) this variable is used to configure Kafka broker to listen on this address:
234227

235228
```
236-
LDFLAGS=-L/usr/local/opt/openssl/lib CPPFLAGS=-I/usr/local/opt/openssl/include ./configure
229+
$ docker-compose up
237230
```
238231

239-
If you are using Stack with Nix, don't forget to declare `rdkafka` as extra package:
232+
After that, tests can be run as usual:
240233

241-
```yaml
242-
# stack.yaml
243-
nix:
244-
enable: true
245-
packages:
246-
- rdkafka
247234
```
248-
249-
## Installing Kafka
250-
251-
The full Kafka guide is at http://kafka.apache.org/documentation.html#quickstart
252-
253-
Alternatively `docker-compose` can be used to run Kafka locally inside a Docker container.
254-
To run Kafka inside Docker:
255-
256-
```bash
257-
$ docker-compose up
235+
$ cabal test --test-show-details=direct
258236
```

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ kafka:
1616
- zookeeper:zookeeper
1717
environment:
1818
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
19-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://$DOCKER_IP:9092"
19+
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://$KAFKA_TEST_BROKER:9092"
2020
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
2121
KAFKA_CREATE_TOPICS:

shell.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
with import <nixpkgs> {};
2+
3+
pkgs.mkShell {
4+
buildInputs = with pkgs; [
5+
zlib
6+
rdkafka
7+
];
8+
9+
shellHook = ''
10+
PATH=~/.cabal/bin:$PATH
11+
LD_LIBRARY_PATH=${pkgs.zlib}/lib:$LD_LIBRARY_PATH
12+
export LIBRARY_PATH=${pkgs.rdkafka}/lib
13+
export C_INCLUDE_PATH=${pkgs.rdkafka}/include
14+
15+
export KAFKA_TEST_BROKER=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n 1)
16+
'';
17+
}

0 commit comments

Comments
 (0)