(ns ring.middleware.multipart-params.test.temp-file
  (:use clojure.test
        [ring.util.io :only (string-input-stream)]
        ring.middleware.multipart-params.temp-file))

(deftest test-temp-file-store
  (let [store  (temp-file-store)
        result (store
                {:filename "foo.txt"
                 :content-type "text/plain"
                 :stream (string-input-stream "foo")})]
    (is (= (:filename result) "foo.txt"))
    (is (= (:content-type result) "text/plain"))
    (is (= (:size result) 3))
    (is (instance? java.io.File (:tempfile result)))
    (is (.exists (:tempfile result)))
    (is (= (slurp (:tempfile result)) "foo"))))

(deftest test-temp-file-expiry
  (let [store  (temp-file-store {:expires-in 2})
        result (store
                {:filename "foo.txt"
                 :content-type "text/plain"
                 :stream (string-input-stream "foo")})]
    (is (.exists (:tempfile result)))
    (Thread/sleep 2500)
    (is (not (.exists (:tempfile result))))))

(ns ring.middleware.multipart-params.test.temp-file
  (:use clojure.test
        [ring.util.io :only (string-input-stream)]
        ring.middleware.multipart-params.temp-file))

(deftest test-temp-file-store
  (let [store  (temp-file-store)
        result (store
                {:filename "foo.txt"
                 :content-type "text/plain"
                 :stream (string-input-stream "foo")})]
    (is (= (:filename result) "foo.txt"))
    (is (= (:content-type result) "text/plain"))
    (is (= (:size result) 3))
    (is (instance? java.io.File (:tempfile result)))
    (is (.exists (:tempfile result)))
    (is (= (slurp (:tempfile result)) "foo"))))

(deftest test-temp-file-expiry
  (let [store  (temp-file-store {:expires-in 2})
        result (store
                {:filename "foo.txt"
                 :content-type "text/plain"
                 :stream (string-input-stream "foo")})]
    (is (.exists (:tempfile result)))
    (Thread/sleep 2500)
    (is (not (.exists (:tempfile result))))))

(defn all-threads []
  (.keySet (Thread/getAllStackTraces)))

(deftest test-temp-file-threads
  (let [store (temp-file-store)]
    (dotimes [_ 200]
      (store {:filename "foo.txt"
              :content-type "text/plain"
              :stream (string-input-stream "foo")}))
    (is (< (count (all-threads))
           100))))

Test to check for excessive temp-file-store threads
Test to check for excessive temp-file-store threads

ring-clojure/ring,tchagnon/ring,suligap/ring,ring-clojure/ring,meowcakes/ring,ieure/ring,kirasystems/ring,povloid/ring