Move Record test into stress data
This commit is contained in:
parent
5c48ba8e26
commit
c58bf97af7
3 changed files with 11 additions and 8 deletions
|
|
@ -88,7 +88,9 @@ nippy/stress-data
|
||||||
|
|
||||||
:ratio 22/7
|
:ratio 22/7
|
||||||
:uuid (java.util.UUID/randomUUID)
|
:uuid (java.util.UUID/randomUUID)
|
||||||
:date (java.util.Date.)}
|
:date (java.util.Date.)
|
||||||
|
|
||||||
|
:stress-record (->StressRecord "data")}
|
||||||
```
|
```
|
||||||
|
|
||||||
Serialize it:
|
Serialize it:
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@
|
||||||
(freezer-coll LazySeq id-seq)
|
(freezer-coll LazySeq id-seq)
|
||||||
|
|
||||||
(freezer IRecord id-record
|
(freezer IRecord id-record
|
||||||
(write-utf8 s (.getName (class x)))
|
(write-utf8 s (.getName (class x))) ; Reflect
|
||||||
(freeze-to-stream s (into {} x)))
|
(freeze-to-stream s (into {} x)))
|
||||||
|
|
||||||
(freezer Byte id-byte (.writeByte s x))
|
(freezer Byte id-byte (.writeByte s x))
|
||||||
|
|
@ -419,6 +419,7 @@
|
||||||
|
|
||||||
;;;; Stress data
|
;;;; Stress data
|
||||||
|
|
||||||
|
(defrecord StressRecord [data])
|
||||||
(def stress-data "Reference data used for tests & benchmarks."
|
(def stress-data "Reference data used for tests & benchmarks."
|
||||||
(let []
|
(let []
|
||||||
{:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
{:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
||||||
|
|
@ -461,7 +462,9 @@
|
||||||
|
|
||||||
:ratio 22/7
|
:ratio 22/7
|
||||||
:uuid (java.util.UUID/randomUUID)
|
:uuid (java.util.UUID/randomUUID)
|
||||||
:date (java.util.Date.)}))
|
:date (java.util.Date.)
|
||||||
|
|
||||||
|
:stress-record (->StressRecord "data")}))
|
||||||
|
|
||||||
;;;; Deprecated API
|
;;;; Deprecated API
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,18 +39,16 @@
|
||||||
(thaw (org.iq80.snappy.Snappy/uncompress iq80-ba 0 (alength 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))))))
|
(thaw (org.iq80.snappy.Snappy/uncompress xerial-ba 0 (alength xerial-ba))))))
|
||||||
|
|
||||||
;;; Records (reflecting)
|
|
||||||
(defrecord MyRec [data])
|
|
||||||
(expect (let [rec (->MyRec "val")] (= rec (thaw (freeze rec)))))
|
|
||||||
|
|
||||||
;;; Custom types
|
;;; Extend to custom Type
|
||||||
(defrecord MyType [data])
|
(defrecord MyType [data])
|
||||||
(nippy/extend-freeze MyType 1 [x s] (.writeUTF s (:data x)))
|
(nippy/extend-freeze MyType 1 [x s] (.writeUTF s (:data x)))
|
||||||
(expect Exception (thaw (freeze (->MyType "val"))))
|
(expect Exception (thaw (freeze (->MyType "val"))))
|
||||||
(expect (do (nippy/extend-thaw 1 [s] (->MyType (.readUTF s)))
|
(expect (do (nippy/extend-thaw 1 [s] (->MyType (.readUTF s)))
|
||||||
(let [type (->MyType "val")] (= type (thaw (freeze type))))))
|
(let [type (->MyType "val")] (= type (thaw (freeze type))))))
|
||||||
|
|
||||||
;;; Records (extend)
|
;;; Extend to custom Record
|
||||||
|
(defrecord MyRec [data])
|
||||||
(expect (do (nippy/extend-freeze MyRec 2 [x s] (.writeUTF s (str "fast-" (:data x))))
|
(expect (do (nippy/extend-freeze MyRec 2 [x s] (.writeUTF s (str "fast-" (:data x))))
|
||||||
(nippy/extend-thaw 2 [s] (->MyRec (.readUTF s)))
|
(nippy/extend-thaw 2 [s] (->MyRec (.readUTF s)))
|
||||||
(= (->MyRec "fast-val") (thaw (freeze (->MyRec "val"))))))
|
(= (->MyRec "fast-val") (thaw (freeze (->MyRec "val"))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue