Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Test a record having an avro-date

  • Loading branch information...
commit 9bc9fa646b62f4d19d8eddf72831c956b19a6136 1 parent bf9cf3f
ghosthack authored April 26, 2012

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. 41  test/simple_avro/avro_date_tests.clj
41  test/simple_avro/avro_date_tests.clj
... ...
@@ -0,0 +1,41 @@
  1
+(ns simple-avro.avro-date-tests
  2
+  (:use (simple-avro api schema utils)
  3
+        (clojure test)))
  4
+
  5
+(defavro-record Test
  6
+  "field1" avro-string
  7
+  "field2" avro-int
  8
+  "field3" avro-date
  9
+  )
  10
+
  11
+(def test-records
  12
+  [{"field1" "record1" "field2" 10 "field3" (java.util.Date. )}
  13
+   {"field1" "record2" "field2" 20 "field3" (java.util.Date. )}
  14
+   {"field1" "record3" "field2" 30 "field3" (java.util.Date. )}
  15
+   {"field1" "record4" "field2" 40 "field3" (java.util.Date. )}])
  16
+
  17
+
  18
+;
  19
+; Reader/writer example
  20
+;
  21
+
  22
+(defn write-read-data
  23
+  []
  24
+  (let [tmp-file (.getAbsolutePath (java.io.File/createTempFile "test" ".avro"))]
  25
+    (let [writer   (avro-writer tmp-file Test)]
  26
+      (println "Creating temp file " tmp-file)
  27
+      (doseq [rec (apply concat (repeat 1000 test-records))]
  28
+        (write writer rec))
  29
+      (close writer))
  30
+    (println "Reading " tmp-file)
  31
+    (let [reader (avro-reader tmp-file)]
  32
+      (loop [nx (has-next reader)]
  33
+        (when nx
  34
+          (println "Read     " (read-next reader))
  35
+          (println "Position " (position reader))
  36
+          (recur (has-next reader))))
  37
+      (close reader))
  38
+    (println "Deleting " tmp-file)
  39
+    (.delete (java.io.File. tmp-file))))
  40
+
  41
+(deftest writer-reader-test  (write-read-data))

0 notes on commit 9bc9fa6

Please sign in to comment.
Something went wrong with that request. Please try again.