Permalink
Browse files

Update set-config to accept a map argument. Add default-config functi…

…on to get the default configuration as a map. Update unit tests.
  • Loading branch information...
1 parent 43c8d86 commit 3db93c7f1ef95373dd2512a6fe6245445d8cfa9f @davidsantiago committed Mar 5, 2012
Showing with 33 additions and 23 deletions.
  1. +19 −12 src/clojure_hbase/core.clj
  2. +14 −11 test/clojure_hbase/core_test.clj
@@ -20,21 +20,28 @@
(def ^{:dynamic true :private true} *db*
(atom nil))
+;; There doesn't appear to be, as far as I can tell, a way to get the current
+;; HBaseConfiguration being used by an HTablePool. Unfortunately, this means
+;; you need to remember and keep track of this yourself, if you want to be
+;; switching them around.
+(defn default-config
+ "Returns the default HBaseConfiguration as a map."
+ []
+ (into {} (HBaseConfiguration/create)))
+
(defn set-config
- "resets the *db* atom, so that subsequent calls to htable-pool
+ "Resets the *db* atom, so that subsequent calls to htable-pool
use the new configuration.
- example: (set-config
- \"hbase.zookeeper.dns.interface\" \"lo\"
- \"hbase.zookeeper.quorum\" \"127.0.0.1\")"
- ([k v & kvs]
- (let [config-obj (HBaseConfiguration/create)
- kvs (concat [k v] kvs)]
- (assert (even? (count kvs)))
- (doseq [[k v] (partition 2 kvs)]
- (.set config-obj (name k) v))
- (swap! *db* (fn [_]
- (HTablePool. config-obj Integer/MAX_VALUE))))))
+ Example: (set-config
+ {\"hbase.zookeeper.dns.interface\" \"lo\"
+ :hbase.zookeeper.quorum \"127.0.0.1\"})"
+ [config-map]
+ (let [config-obj (HBaseConfiguration/create)]
+ (doseq [[k v] (seq config-map)]
+ (.set config-obj (name k) (name v)))
+ (swap! *db* (fn [_]
+ (HTablePool. config-obj Integer/MAX_VALUE)))))
(defn- ^HTablePool htable-pool
[]
@@ -118,14 +118,17 @@
"latest-as-map works.")))))
(deftest test-set-config
- (as-test
- (is
- (try (set-config "hbase.zookeeper.quorum" "asdsa") ;<- not valid
- (table test-tbl-name) ;<- should raise exception
- false #_"<- fail if we got here, it should have thrown"
- (catch Exception e
- true)))
- (is
- (do
- (set-config "hbase.zookeeper.quorum" "127.0.0.1") ;<- valid
- (table test-tbl-name)))))
+ (try
+ (as-test
+ (is
+ (try (set-config {"hbase.zookeeper.quorum" "asdsa"}) ;<- not valid
+ (table test-tbl-name) ;<- should raise exception
+ false #_"<- fail if we got here, it should have thrown"
+ (catch Exception e
+ true)))
+ (is
+ (do
+ (set-config {"hbase.zookeeper.quorum" "127.0.0.1"}) ;<- valid
+ (table test-tbl-name))))
+ (finally
+ (set-config (default-config)))))

0 comments on commit 3db93c7

Please sign in to comment.