Additional refinements to blobstore.clj updates.

* Added an option to conditionally call calculateMD5() in blob2.
* Fixed a bug in md5-blob (which predated these changes).
* Added a direct test for blob2 and calculateMD5.
This commit is contained in:
David Santiago 2011-04-02 02:26:45 -05:00
parent 85d0474068
commit 3459df3653
2 changed files with 18 additions and 6 deletions

View File

@ -380,19 +380,24 @@ example:
([^String name option-map] ([^String name option-map]
(blob2 name option-map *blobstore*)) (blob2 name option-map *blobstore*))
([^String name ([^String name
{:keys [payload content-type content-length content-md5 {:keys [payload content-type content-length content-md5 calculate-md5
content-disposition content-encoding content-language metadata] content-disposition content-encoding content-language metadata]}
:or {for-signing false}}
^BlobStore blobstore] ^BlobStore blobstore]
{:pre [(not (and content-md5 calculate-md5))
(not (and (nil? payload) calculate-md5))]}
(let [blob-builder (if payload (let [blob-builder (if payload
(.payload (.blobBuilder blobstore name) payload) (.payload (.blobBuilder blobstore name) payload)
(.forSigning (.blobBuilder blobstore name))) (.forSigning (.blobBuilder blobstore name)))
blob-builder (if content-length ;; Special case, arg is prim. blob-builder (if content-length ;; Special case, arg is prim.
(.contentLength blob-builder content-length) (.contentLength blob-builder content-length)
blob-builder)] blob-builder)
blob-builder (if calculate-md5 ;; Only do calculateMD5 OR contentMD5.
(.calculateMD5 blob-builder)
(if content-md5
(.contentMD5 blob-builder content-md5)
blob-builder))]
(doto blob-builder (doto blob-builder
(.contentType content-type) (.contentType content-type)
(.contentMD5 content-md5)
(.contentDisposition content-disposition) (.contentDisposition content-disposition)
(.contentEncoding content-encoding) (.contentEncoding content-encoding)
(.contentLanguage content-language) (.contentLanguage content-language)
@ -405,7 +410,7 @@ note that this implies rebuffering, if the blob's payload isn't repeatable"
([#^Blob blob] ([#^Blob blob]
(Payloads/calculateMD5 blob)) (Payloads/calculateMD5 blob))
([#^String name payload] ([#^String name payload]
(blob2 name {:payload payload} *blobstore*)) (md5-blob name payload *blobstore*))
([#^String name payload #^BlobStore blobstore] ([#^String name payload #^BlobStore blobstore]
(md5-blob (blob2 name {:payload payload} blobstore)))) (md5-blob (blob2 name {:payload payload} blobstore))))

View File

@ -21,6 +21,7 @@
(:use [org.jclouds.blobstore] :reload-all) (:use [org.jclouds.blobstore] :reload-all)
(:use [clojure.test]) (:use [clojure.test])
(:import [org.jclouds.blobstore BlobStoreContextFactory] (:import [org.jclouds.blobstore BlobStoreContextFactory]
[org.jclouds.crypto CryptoStreams]
[java.io ByteArrayOutputStream] [java.io ByteArrayOutputStream]
[org.jclouds.util Strings2])) [org.jclouds.util Strings2]))
@ -180,6 +181,12 @@
(is (= "http://localhost/container/path" (str (.getEndpoint request)))) (is (= "http://localhost/container/path" (str (.getEndpoint request))))
(is (= "DELETE" (.getMethod request))))) (is (= "DELETE" (.getMethod request)))))
(deftest blob2-test
(let [a-blob (blob2 "test-name" {:payload (.getBytes "test-payload")
:calculate-md5 true})]
(is (= (seq (.. a-blob (getPayload) (getContentMetadata) (getContentMD5)))
(seq (CryptoStreams/md5 (.getBytes "test-payload")))))))
;; TODO: more tests involving blob-specific functions ;; TODO: more tests involving blob-specific functions
(deftest corruption-hunt (deftest corruption-hunt