Skip to content

Commit

Permalink
Merge branch 'embedded-daemon-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
pingles committed Dec 14, 2011
2 parents 7dffac9 + 36d7616 commit 7dc754b
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 383 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pom.xml
lib
classes
autodoc/**
.lein-*
.lein-*
tmp/
4 changes: 3 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(defproject org.clojars.paul/clj-hector "0.0.4"
:description "Wrapper for Hector Cassandra client"
:dev-dependencies [[org.slf4j/slf4j-nop "1.6.1"]]
:resources-path "test/resources"
:dev-dependencies [[org.slf4j/slf4j-simple "1.6.3"]
[org.apache.cassandra/cassandra-all "1.0.5"]]
:dependencies [[me.prettyprint/hector-core "1.0-1" :exclusions [org.slf4j/slf4j-log4j12]]
[org.slf4j/slf4j-api "1.6.1"]
[org.clojure/clojure "1.2.1"]
Expand Down
42 changes: 42 additions & 0 deletions test/clj_hector/test/cassandra_helper.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(ns clj-hector.test.cassandra-helper
(:import [org.apache.cassandra.service EmbeddedCassandraService]
[java.util UUID])
(:use [clojure.test]
[clj-hector.core :only (cluster keyspace)]
[clj-hector.ddl :only (add-keyspace drop-keyspace)]))

;; use an in-process cassandra daemon
;; make tests easier to specify and work
;; with isolated keyspaces

(defn create-daemon
[]
(doto (EmbeddedCassandraService. )
(.start)))

(defonce daemon (create-daemon))

(defn embedded-cluster
[]
(cluster "Embedded Test Cluster" "127.0.0.1" 9960))

(defmacro with-test-keyspace
"Creates a test keyspace which is dropped after the
tests are executed."
[name column-families & body]
`(let [ks-name# (.replace (str "ks" (UUID/randomUUID)) "-" "")
cluster# (embedded-cluster)]
(add-keyspace cluster# {:name ks-name#
:strategy :simple
:replication 1
:column-families ~column-families})
(let [~name (keyspace cluster# ks-name#)]
(try ~@body
(finally (drop-keyspace cluster# ks-name#))))))

(defmacro with-test-cluster
"Creates a connection to the embedded daemon and initializes
a cluster."
[name & body]
`(let [~name (embedded-cluster)]
~@body))
Loading

0 comments on commit 7dc754b

Please sign in to comment.