PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/test/clj_diogok_sandbox/storage_test.clj

https://github.com/diogok/clj-diogok-sandbox
Clojure | 50 lines | 44 code | 6 blank | 0 comment | 10 complexity | 9abe65e09d6c796174e417fb788d364d MD5 | raw file
  1. (ns clj-diogok-sandbox.storage-test
  2. (:use [clj-diogok-sandbox.storage] :reload-all)
  3. (:use clj-diogok-sandbox.serializer)
  4. (:use [clojure.test]))
  5. (deftest mk-tuple
  6. (let [foo (tuple "foo" "bar")]
  7. (is (= "foo" (:key foo)))
  8. (is (= "bar" (:value foo)))
  9. ))
  10. (deftest do-put-get
  11. (let [buck (bucket "foo/bar")
  12. t1 (put! buck (tuple "diogok" "diogok@me.com"))
  13. t2 (put! buck (tuple "diogoh" "diogoh@me.com"))
  14. t22 (put! buck (tuple "diogoh" "diogho@me.com"))
  15. t3 (put! buck (tuple "diogog" "diogog@me.com"))]
  16. (is (= t1 (get! buck "diogok")))
  17. (is (= t22 (get! buck "diogoh")))
  18. (is (= (list t3 t22 t1) (get! buck)))
  19. ))
  20. (deftest do-put-get-consistency
  21. (let [buck (bucket "foo/bar2")
  22. t1 (put! buck (tuple "diogok" "diogok@me.com"))]
  23. (let [buck2 (bucket "foo/bar2")]
  24. (is (= t1 (get! buck2 "diogok"))))
  25. ))
  26. (deftest do-put-get-concurrency-consistency
  27. (let [ buck (bucket "foo/bar3")
  28. t1 (future (dotimes [n 100] (let [obj (tuple (str "a" n) (str "a" n))]
  29. (put! buck obj))))
  30. t2 (future (dotimes [n 100] (let [obj (tuple (str "b" n) (str "b" n))]
  31. (put! buck obj)))) ]
  32. [@t1 @t2]
  33. (is (= "a99" (:value (get! buck "a99"))))
  34. (is (= "b98" (:value (get! buck "b98"))))
  35. (let [buck2 (bucket "foo/bar3")]
  36. (is (= "a88" (:value (get! buck2 "a88"))))
  37. (is (= "b89" (:value (get! buck2 "b89")))))
  38. ))
  39. (.deleteOnExit (java.io.File. "foo/bar.idx"))
  40. (.deleteOnExit (java.io.File. "foo/bar.db"))
  41. (.deleteOnExit (java.io.File. "foo/bar2.idx"))
  42. (.deleteOnExit (java.io.File. "foo/bar2.db"))
  43. (.deleteOnExit (java.io.File. "foo/bar3.idx"))
  44. (.deleteOnExit (java.io.File. "foo/bar3.db"))