2012-07-06 12:53:02 +00:00
|
|
|
(ns test-nippy.main
|
2012-07-06 19:12:59 +00:00
|
|
|
(:use [clojure.test])
|
2013-01-20 12:37:08 +00:00
|
|
|
(:require [taoensso.nippy :as nippy]
|
|
|
|
|
[taoensso.nippy.benchmarks :as benchmarks]))
|
2012-07-06 12:53:02 +00:00
|
|
|
|
2012-07-06 19:12:59 +00:00
|
|
|
;; Remove stuff from stress-data that breaks roundtrip equality
|
|
|
|
|
(def test-data (dissoc nippy/stress-data :bytes))
|
|
|
|
|
|
|
|
|
|
(def roundtrip (comp nippy/thaw-from-bytes nippy/freeze-to-bytes))
|
|
|
|
|
|
2013-01-20 12:37:08 +00:00
|
|
|
(deftest test-roundtrip (is (= test-data (roundtrip test-data))))
|
|
|
|
|
|
|
|
|
|
(println "Benchmarking roundtrips (x3)")
|
|
|
|
|
(println "----------------------------")
|
|
|
|
|
(println (benchmarks/autobench))
|
|
|
|
|
(println (benchmarks/autobench))
|
|
|
|
|
(println (benchmarks/autobench))
|
2013-02-05 13:41:26 +00:00
|
|
|
|
|
|
|
|
(deftest test-snappy-library-compatibility
|
|
|
|
|
(let [thaw #(nippy/thaw-from-bytes % :compressed? false)
|
|
|
|
|
^bytes raw-ba (nippy/freeze-to-bytes test-data :compress? false)
|
|
|
|
|
^bytes xerial-ba (org.xerial.snappy.Snappy/compress raw-ba)
|
|
|
|
|
^bytes iq80-ba (org.iq80.snappy.Snappy/compress raw-ba)]
|
|
|
|
|
(is (= (thaw raw-ba)
|
|
|
|
|
(thaw (org.xerial.snappy.Snappy/uncompress xerial-ba))
|
|
|
|
|
(thaw (org.xerial.snappy.Snappy/uncompress iq80-ba))
|
|
|
|
|
(thaw (org.iq80.snappy.Snappy/uncompress iq80-ba 0 (alength iq80-ba)))
|
|
|
|
|
(thaw (org.iq80.snappy.Snappy/uncompress xerial-ba 0 (alength xerial-ba)))))))
|