Permalink
Browse files

Add transport client test.

  • Loading branch information...
1 parent 73b578e commit 163011b7c5ede40670f13512df4586ed4400fed8 @drewr drewr committed Sep 26, 2011
Showing with 53 additions and 4 deletions.
  1. +4 −2 src/esperanto/client.clj
  2. +7 −0 src/esperanto/node.clj
  3. +36 −0 test/esperanto/test/client.clj
  4. +1 −2 test/esperanto/test/search.clj
  5. +5 −0 test/log4j.properties
View
6 src/esperanto/client.clj
@@ -1,12 +1,14 @@
(ns esperanto.client
+ (:use [clojure.walk :only [stringify-keys]])
(:import (org.elasticsearch.common.settings ImmutableSettings)
(org.elasticsearch.common.transport InetSocketTransportAddress)
(org.elasticsearch.client.transport TransportClient)))
(defn make-transport-client [{:keys [host port cluster] :as settings}]
(let [s (doto (ImmutableSettings/settingsBuilder)
(.put "cluster.name" cluster)
- (.put (or settings {})))]
+ (.put (or (stringify-keys settings) {})))]
(doto (TransportClient. s)
- (.addTransportAddress (InetSocketTransportAddress. host port)))))
+ (.addTransportAddress
+ (InetSocketTransportAddress. host (Integer. port))))))
View
7 src/esperanto/node.clj
@@ -25,6 +25,13 @@
"cluster.name" (rand-cluster-name)}
settings)))
+(defn make-test-tcp-node [settings]
+ (make-node (merge
+ {"index.store.type" "ram"
+ "transport.host" "localhost"
+ "cluster.name" (rand-cluster-name)}
+ settings)))
+
(defn node-fixture [node]
(fn [f]
(try
View
36 test/esperanto/test/client.clj
@@ -0,0 +1,36 @@
+(ns esperanto.test.client
+ (:use [esperanto.client] :reload)
+ (:use [clojure.test]
+ [esperanto.node :only [make-test-tcp-node node-fixture
+ rand-cluster-name]]
+ [esperanto.admin.indices :only [refresh index-fixture create]]
+ [esperanto.admin.cluster :only [wait-for-green status]]
+ [esperanto.index :only [index-doc]]))
+
+(def cluster (rand-cluster-name))
+(def index "foo")
+(def port (str (+ 40000 (rand-int 1000))))
+
+(deftest t-transport
+ (let [doc {:foo 1 :type "test"}
+ master (doto (make-test-tcp-node {"transport.tcp.port" port
+ "cluster.name" cluster})
+ (.start))
+ masterwait (wait-for-green (.client master) [] 5000)
+ client (make-transport-client {:cluster cluster
+ :host "localhost"
+ :port port})]
+ (try
+ (is (not (.isTimedOut masterwait)))
+ (is (not (.isTimedOut (wait-for-green client [] 5000))))
+ (is
+ (.getAcknowledged
+ (create client index
+ (cheshire.core/generate-string
+ {:index.number_of_replicas "0"}))))
+ (is (not (.isTimedOut (wait-for-green client [index] 5000))))
+ (index-doc client index doc)
+ (refresh client index)
+ (is (not (.isTimedOut (wait-for-green client [index] 5000))))
+ (finally
+ (.stop master)))))
View
3 test/esperanto/test/search.clj
@@ -4,8 +4,7 @@
[esperanto.search] :reload)
(:use [clojure.test]
[esperanto.node :only [make-test-node node-fixture]]
- [esperanto.admin.indices :only [refresh index-fixture]]
- [esperanto.action :only [execute]]))
+ [esperanto.admin.indices :only [refresh index-fixture]]))
(def node (make-test-node {}))
View
5 test/log4j.properties
@@ -0,0 +1,5 @@
+log4j.rootLogger:WARN, console
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=[%d{ISO8601}][%-5p][%-25c] %m%n
+## log4j.logger.org.elasticsearch.node=TRACE

0 comments on commit 163011b

Please sign in to comment.