-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented and tested saving to a flat file
- Loading branch information
Paula Gearon
committed
Sep 2, 2020
1 parent
dadbfe6
commit 2049df2
Showing
3 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(ns ^{:doc "Tests flat store functionality, saving and retrieving data" | ||
:author "Paula Gearon"} | ||
asami.durable.test-flat | ||
(:require [asami.durable.flat :refer [write-object! get-object force!]] | ||
#?(:clj [asami.durable.flat-file :as ff]) | ||
#?(:clj [clojure.java.io :as io]) | ||
[clojure.test :refer [deftest is]]) | ||
#?(:clj (:import [java.net URI]))) | ||
|
||
(def store-name "test-fstore") | ||
|
||
(defn uri [s] #?(:clj (URI. s) :cljs (goog/Uri. s))) | ||
|
||
(def data | ||
["Hello" | ||
"Goodbye" | ||
:the | ||
:quick | ||
(uri "http://brown.com/fox") | ||
"jumps over the lazy dog." | ||
1812 | ||
"It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.\n\nHowever little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered the rightful property of some one or other of their daughters.\n\n“My dear Mr. Bennet,” said his lady to him one day, “have you heard that Netherfield Park is let at last?”\n\nMr. Bennet replied that he had not.\n\n“But it is,” returned she; “for Mrs. Long has just been here, and she told me all about it.”\n\nMr. Bennet made no answer.\n\n“Do you not want to know who has taken it?” cried his wife impatiently.\n\n“You want to tell me, and I have no objection to hearing it.”\n\nThis was invitation enough."]) | ||
|
||
(deftest test-store | ||
(let [fmapped (volatile! nil)] | ||
(is (not (.exists (io/file store-name ff/file-name)))) | ||
(with-open [store (ff/flat-store store-name)] | ||
(vreset! fmapped (reduce-kv (fn [m k v] | ||
(let [id (write-object! store v)] | ||
(assoc m k id))) | ||
{} data)) | ||
(is (= (count data) (count @fmapped))) | ||
(doseq [[n id] @fmapped] | ||
(is (= (nth data n) (get-object store id)))) | ||
(doseq [[n id] (shuffle (seq @fmapped))] | ||
(is (= (nth data n) (get-object store id)))) | ||
(force! store)) | ||
|
||
(with-open [store (ff/flat-store store-name)] | ||
(doseq [[n id] @fmapped] | ||
(is (= (nth data n) (get-object store id)))) | ||
(doseq [[n id] (shuffle (seq @fmapped))] | ||
(is (= (nth data n) (get-object store id)))))) | ||
#?(:clj | ||
(let [f (io/file store-name ff/file-name) | ||
d (io/file store-name)] | ||
(is (.delete f)) | ||
(is (.delete d))))) |