Skip to content

Commit

Permalink
callback test
Browse files Browse the repository at this point in the history
  • Loading branch information
halfaleague committed May 5, 2012
1 parent b9f8aed commit fcb459b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/trickyhappyface/upload.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
(proxy [java.io.FileInputStream] [filename]
(read
([b off len]
(println "-read-callback")
(swap! cnt #(+ len %1))
(callback b off len @cnt length)
(proxy-super read b off len))))))
Expand Down
48 changes: 28 additions & 20 deletions test/trickyhappyface/test/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,36 @@ Honour the charge they made!")
(defn -size-pct [size total-size]
(int (* 100. (/ size (float total-size)))))

(defn -print-bar [pcnt]
(if (= (mod @pcnt 5) 0)
(print @pcnt)
(print "."))
(swap! pcnt inc))
(defn -print-bar-part [pcnt]
(if (= (mod pcnt 5) 0)
(print pcnt)
(print ".")))

(defn -callback [b off len
cnt file-length]
(let [
rpct 0
pct (atom rpct)
(defn -print-bar [start end]
(let [diff (- end start)
nums (range start end)
]
(doall (map -print-bar-part nums))))

(println "-callback" cnt @pct)
(if (= (-size-pct cnt file-length) @pct)
(-print-bar pct))
(defn -calc-pct [s t] (int (* 100. (/ s (float t)))))

(if (= @pct 100)
[(println) (reset! pct 0)]
)
(flush)
))
(defn -make-callback []
(let [
rlast-pct 0
last-pct (atom rlast-pct)
]
(fn -callback [b off len
cnt file-length]
(let [
pct (-calc-pct cnt file-length)
diff (- pct @last-pct)
]
(-print-bar @last-pct pct)
(reset! last-pct pct)
(flush)
))
)
)

(defn -verify-session [info]
(and (= (info :stat) OK)
Expand All @@ -60,8 +68,8 @@ Honour the charge they made!")

(fact (let [album (albums-create sid {:Title album-name})
aid (-> album :Album :id)
{length :length md5 :md5} (upload sid aid filename)
{length :length md5 :md5} (upload sid aid filename -callback)
;{length :length md5 :md5} (upload sid aid filename)
{length :length md5 :md5} (upload sid aid filename (-make-callback))
dresp (albums-delete sid {:AlbumID aid}) ]
(dresp :stat)) => OK)

Expand Down

0 comments on commit fcb459b

Please sign in to comment.