Clojure and Leiningen helper for running embedded Zookeeper instances for integration testing.
Clojure
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
.travis.yml
LICENSE
README.md
project.clj

README.md

zookem Build Status

A helper for running embedded Zookeeper instances for integration testing. Based on the curator-test TestingServer.

Usage

As a test helper

An example using Midje, just add [zookem "0.1.2"] to your project's dev dependencies then:

(ns (:require [zookem.core :refer [with-zk
                                   *zk-port* *zk-connect-string* *zk-client*]))

(fact "fn-that-uses-zookeeper can read data from zookeeper"
  (with-zk {:port 2181 ;; optional, default is random
            :nodes {"/some/path/with/data" "data"
                    "/some/path/without/data" nil}}
    *zk-port* => 2181
    *zk-connect-string* => "127.0.0.1:2181"
    (fn-that-uses-zookeeper *zk-client*) => ...)

The with-zk macro starts up an embedded instance of Zookeeper for testing, runs the body, then shuts down the Zookeeper instance. Inside the body of the macro, the dynamic vars *zk-port*, *zk-connect-string* and *zk-client* will be bound.

As a lein plugin

(defproject myproject "0.1.0"
  :plugins [[zookem "0.1.2"]]
  :zookeeper {:port 2181
              :nodes {"/some/path/with/data" "data"
                      "/some/path/without/data" nil}})
$ lein zookem midje

The zookem task starts an embedded instance of Zookeeper then runs the task given as an argument. Once the downstream task completes, the embedded instance of Zookeeper is terminated.

This library supports environ configuration, so you can also set the Zookeeper port using the 'env' key in your project.clj:

(defproject myproject "0.1.0"
  :env {:zookeeper-port "2181"})

or as an environment variable:

ZOOKEEPER_PORT=2181

or as a system property:

-Dzookeeper.port=2181

License

Copyright © 2013 Joe Littlejohn

Distributed under the Eclipse Public License, the same as Clojure.