Permalink
Browse files

eliminate clojure-contrib and (temporarily) watch support

  • Loading branch information...
1 parent 12bba6a commit 3d3f2430464f7d37a1677a2588eb8a849b057f68 @cemerick cemerick committed Apr 27, 2012
Showing with 32 additions and 37 deletions.
  1. +0 −1 project.clj
  2. +13 −19 src/com/ashafa/clutch.clj
  3. +0 −1 src/com/ashafa/clutch/utils.clj
  4. +19 −16 test/test_clutch.clj
View
@@ -2,7 +2,6 @@
:description "A Clojure library for Apache CouchDB."
:url "http://github.com/ashafa/clutch"
:dependencies [[org.clojure/clojure "1.3.0"]
- [org.clojure/clojure-contrib "1.2.0"]
[org.clojure/tools.logging "0.1.2"]
View
@@ -29,11 +29,9 @@
(:require [com.ashafa.clutch [utils :as utils]]
[cheshire.core :as json]
[clojure.java.io :as io]
- [clojure.contrib.http.agent :as h]
[cemerick.url :as url]
clojure.string)
- (:use com.ashafa.clutch.http-client
- (clojure.contrib core def))
+ (:use com.ashafa.clutch.http-client)
(:import (java.io File FileInputStream BufferedInputStream InputStream ByteArrayOutputStream)
(java.net URL))
(:refer-clojure :exclude (conj! assoc! dissoc!)))
@@ -47,7 +45,7 @@
; now officially documented at http://wiki.apache.org/couchdb/View_collation
wildcard-collation-string (str (char highest-supported-charcode)))
-(def ^{:private true} watched-databases (ref {}))
+#_(def ^{:private true} watched-databases (ref {}))
(def ^{:dynamic true :private true} *database* nil)
@@ -88,7 +86,8 @@
(defdbop database-info
[db]
- (when-let [info (couchdb-request :get db)]
+ (couchdb-request :get db)
+ #_(when-let [info (couchdb-request :get db)]
(merge info
(when-let [watchers (@watched-databases (str db))]
{:watchers (keys watchers)}))))
@@ -118,7 +117,7 @@
:data {:source (str srcdb)
:target (str tgtdb)}))
-(defn- watch-changes-handler
+#_(defn- watch-changes-handler
[url-str watch-key uid agnt]
(if (h/success? agnt)
(loop [lines (utils/read-lines (h/stream agnt))]
@@ -137,7 +136,7 @@
{:exception e :time (java.util.Date.) :data line}))))))))
(recur (rest lines)))))))
-(defdbop watch-changes
+#_(defdbop watch-changes
"Provided a database (database meta <map>, url <string>, or database name <string>) and a callback, watches
for changes to the database and executes the given callback (takes one argument) on every change
to a document in the given database, using the meta of the changed document as the only
@@ -163,7 +162,7 @@
(alter watched-databases assoc db-url-key {watch-key watcher}))))
db)))
-(defdbop changes-error
+#_(defdbop changes-error
"If the provided database is being watched for changes (see: 'watch-changes'), returns a map
containing the last exception, the time (java.util.Date) of the exception, and the argument
supplied to the callback, if an exception occured during execution of the callback."
@@ -172,7 +171,7 @@
(if watched-database
(:last-error (watched-database watch-key)))))
-(defdbop stop-changes
+#_(defdbop stop-changes
"If the provided database changes are being watched (see: 'watch-changes'), stops the execution
of the callback on every change to the watched database."
[db & [watch-key]]
@@ -218,14 +217,9 @@
(if (= byte-array-class (class input))
input
; make sure streams are closed so we don't hold locks on files on Windows
- (with-open [^InputStream input input]
- (let [barr (make-array Byte/TYPE 1024)
- out (ByteArrayOutputStream.)]
- (loop []
- (let [size (.read input barr)]
- (when (pos? size)
- (do (.write out barr 0 size)
- (recur)))))
+ (with-open [^InputStream input (io/input-stream input)]
+ (let [out (ByteArrayOutputStream.)]
+ (io/copy input out)
(.toByteArray out)))))
(defdbop put-document
@@ -365,7 +359,7 @@
(apply save-design-document db :views args))
(defdbop save-filter
- "Create a filter for use with CouchDB change notifications API via 'watch-changes'."
+ "Create a filter for use with CouchDB change notifications API."
[db & args]
(apply save-design-document db :filters args))
@@ -456,7 +450,7 @@
attachment-name (if (keyword? attachment-name)
(name attachment-name)
attachment-name)]
- (when (-?> doc :_attachments (get (keyword attachment-name)))
+ (when (-> doc :_attachments (get (keyword attachment-name)))
(couchdb-request :get
(-> (document-url db doc)
(utils/url attachment-name)
@@ -27,7 +27,6 @@
com.ashafa.clutch.utils
(:require [clojure.java.io :as io]
[cemerick.url :as url])
- (:use clojure.contrib.core)
(:import java.net.URLEncoder
java.lang.Class
[java.io File]))
View
@@ -4,13 +4,13 @@
[http-client :as http-client]
[utils :as utils]
[view-server :as view-server])
- [clojure.contrib.str-utils :as str]
- [clojure.contrib.io :as io])
+ [clojure.string :as str]
+ [clojure.java.io :as io])
(:use com.ashafa.clutch
[cemerick.url :only (url)]
clojure.set
clojure.test)
- (:import (java.io File ByteArrayInputStream FileInputStream)
+ (:import (java.io File ByteArrayInputStream FileInputStream ByteArrayOutputStream)
(java.net URL))
(:refer-clojure :exclude (conj! assoc! dissoc!)))
@@ -22,7 +22,7 @@
(def test-host (or (System/getenv "clutch_url") "http://localhost:5984"))
(println "Testing using Clojure" *clojure-version*
- "=>>" (-> test-host url (merge {:username nil :password nil}) str))
+ "=>>" (-> test-host url (assoc :username nil :password nil) str))
(def resources-path "test")
@@ -42,6 +42,8 @@
:email "sarah.parker@example.com"
:score 59})
+(def ^{:private true} to-byte-array @#'com.ashafa.clutch/to-byte-array)
+
(declare ^{:dynamic true} *clj-view-svr-config*
^{:dynamic true} *test-database*)
@@ -67,7 +69,7 @@
(defn test-database-name
[test-name]
- (str "test-db-" (str/re-sub #"[^$]+\$([^@]+)@.*" "$1" (str test-name))))
+ (str "test-db-" (str/replace (str test-name) #"[^$]+\$([^@]+)@.*" "$1")))
(defn test-database-url
[db-name]
@@ -231,7 +233,8 @@
(let [copy (get-document "dest")
copied-attachment (get-attachment copy :image)]
(is (= (dissoc-meta doc) (dissoc-meta copy)))
- (is (= (-> file io/to-byte-array seq) (-> copied-attachment io/to-byte-array seq))))))
+ (is (= (-> file to-byte-array seq)
+ (-> copied-attachment to-byte-array seq))))))
(defdbtest copy-document-fail-overwrite
(put-document test-document-1 :id "src")
@@ -413,7 +416,7 @@
bytes-filename :couchdbbytes.png
created-document (put-document test-document-4
:attachments [clojure-img-file
- {:data (#'com.ashafa.clutch/to-byte-array (FileInputStream. couchdb-img-file))
+ {:data (to-byte-array (FileInputStream. couchdb-img-file))
:filename bytes-filename :mime-type "image/png"}
{:data (FileInputStream. couchdb-img-file)
:filename couch-filename :mime-type "image/png"}])
@@ -441,7 +444,7 @@
updated-document-meta (put-attachment (assoc document :_rev (:rev updated-document-meta))
(FileInputStream. path) :filename filename-with-space :mime-type "image/png")
updated-document-meta (put-attachment (assoc document :_rev (:rev updated-document-meta))
- (#'com.ashafa.clutch/to-byte-array (FileInputStream. path))
+ (to-byte-array (FileInputStream. path))
:filename :bytes-image :mime-type "image/png")
document-with-attachments (get-document (updated-document-meta :id) :attachments true)]
(is (= #{:couchdb-image filename-with-space :bytes-image} (set (keys (:_attachments document-with-attachments)))))
@@ -461,9 +464,9 @@
:filename :couchdb-image
:mime-type "other/mimetype")
document-with-attachments (get-document (updated-document-meta :id) :attachments true)
- data (io/to-byte-array (java.io.File. (str resources-path "/couchdb.png")))]
+ data (to-byte-array (java.io.File. (str resources-path "/couchdb.png")))]
(is (= "other/mimetype" (-> document-with-attachments :_attachments :couchdb-image :content_type)))
- (is (= (seq data) (-> (get-attachment document-with-attachments :couchdb-image) io/to-byte-array seq)))))
+ (is (= (seq data) (-> (get-attachment document-with-attachments :couchdb-image) to-byte-array seq)))))
(deftest replicate-a-database
(try
@@ -505,11 +508,11 @@
(is (= (:id change-meta) "target-id"))
(is (= (:seq change-meta) 5)))))
-(defdbtest watch-for-change
+#_(defdbtest watch-for-change
(watch-changes :check-id (partial check-id-changes-test "Watch database"))
(put-document test-document-2 :id "target-id"))
-(defdbtest ensure-stop-changes
+#_(defdbtest ensure-stop-changes
(watch-changes :foo println)
(letfn [(tracking-changes? [] (-> @@#'com.ashafa.clutch/watched-databases
(get (str *test-database*))
@@ -518,21 +521,21 @@
(stop-changes :foo)
(is (not (tracking-changes?)))))
-(defdbtest multiple-watchers-for-change
+#_(defdbtest multiple-watchers-for-change
(watch-changes :check-id (partial check-id-changes-test "Multiple watchers - id"))
(watch-changes :check-seq (partial check-seq-changes-test "Multiple watchers - seq"))
(is (= #{:check-id :check-seq} (set (:watchers (database-info)))))
(put-document test-document-2 :id "target-id"))
-(defdbtest multiple-changes
+#_(defdbtest multiple-changes
(watch-changes :check-delete (partial check-delete-changes-test "Multiple changes"))
(let [document-1 (put-document test-document-1 :id "not-target-id")
document-2 (put-document test-document-2 :id "target-id")
document-3 (put-document test-document-3 :id "another-random-id")]
(update-document document-1 {:score 0})
(delete-document document-2)))
-(defdbtest changes-filter
+#_(defdbtest changes-filter
(save-filter "scores"
(view-server-fns view-server-name
{:less-than-50 (fn [document request] (if (< (:score document) 50) true false))}))
@@ -541,7 +544,7 @@
(put-document {:name "tester 1" :score 22} :id "target-id")
(put-document {:name "tester 2" :score 79} :id "not-target-id"))
-(defdbtest changes-filter-with-query-params
+#_(defdbtest changes-filter-with-query-params
(save-filter "scores"
(view-server-fns view-server-name
{:more-than-50-from-a-user (fn [document request]

0 comments on commit 3d3f243

Please sign in to comment.