mirror of https://github.com/apache/jclouds.git
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:
parent
85d0474068
commit
3459df3653
|
@ -380,19 +380,24 @@ example:
|
|||
([^String name option-map]
|
||||
(blob2 name option-map *blobstore*))
|
||||
([^String name
|
||||
{:keys [payload content-type content-length content-md5
|
||||
content-disposition content-encoding content-language metadata]
|
||||
:or {for-signing false}}
|
||||
{:keys [payload content-type content-length content-md5 calculate-md5
|
||||
content-disposition content-encoding content-language metadata]}
|
||||
^BlobStore blobstore]
|
||||
{:pre [(not (and content-md5 calculate-md5))
|
||||
(not (and (nil? payload) calculate-md5))]}
|
||||
(let [blob-builder (if payload
|
||||
(.payload (.blobBuilder blobstore name) payload)
|
||||
(.forSigning (.blobBuilder blobstore name)))
|
||||
blob-builder (if content-length ;; Special case, arg is prim.
|
||||
(.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
|
||||
(.contentType content-type)
|
||||
(.contentMD5 content-md5)
|
||||
(.contentDisposition content-disposition)
|
||||
(.contentEncoding content-encoding)
|
||||
(.contentLanguage content-language)
|
||||
|
@ -405,7 +410,7 @@ note that this implies rebuffering, if the blob's payload isn't repeatable"
|
|||
([#^Blob blob]
|
||||
(Payloads/calculateMD5 blob))
|
||||
([#^String name payload]
|
||||
(blob2 name {:payload payload} *blobstore*))
|
||||
(md5-blob name payload *blobstore*))
|
||||
([#^String name payload #^BlobStore blobstore]
|
||||
(md5-blob (blob2 name {:payload payload} blobstore))))
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
(:use [org.jclouds.blobstore] :reload-all)
|
||||
(:use [clojure.test])
|
||||
(:import [org.jclouds.blobstore BlobStoreContextFactory]
|
||||
[org.jclouds.crypto CryptoStreams]
|
||||
[java.io ByteArrayOutputStream]
|
||||
[org.jclouds.util Strings2]))
|
||||
|
||||
|
@ -180,6 +181,12 @@
|
|||
(is (= "http://localhost/container/path" (str (.getEndpoint 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
|
||||
|
||||
(deftest corruption-hunt
|
||||
|
|
Loading…
Reference in New Issue