Permalink
Browse files

Add a null layer

  • Loading branch information...
1 parent 2708c83 commit 335398426cd9160ce57dda27cebfd024bccdb94d @amalloy amalloy committed Jul 26, 2012
Showing with 65 additions and 2 deletions.
  1. +3 −2 src/jiraph/core.clj
  2. +45 −0 src/jiraph/null_layer.clj
  3. +17 −0 test/jiraph/core_test.clj
View
@@ -171,8 +171,9 @@
(catch [:type ::abort-multiple :name abort-key#] _#)))))
(letfn [(all-revisions [layers]
- (or (seq (map retro/max-revision
- (vals (as-layer-map layers))))
+ (or (seq (remove #{Double/POSITIVE_INFINITY}
+ (map retro/max-revision
+ (vals (as-layer-map layers)))))
[0]))]
(defn current-revision
"The minimum revision on all specified layers, or all layers if none are specified."
View
@@ -0,0 +1,45 @@
+(ns jiraph.null-layer
+ (:use jiraph.layer retro.core))
+
+;; a layer object like /dev/null - it ignores all writes, and returns nil for all reads
+(defrecord NullLayer []
+ SortedEnumerate
+ (node-id-subseq [this cmp start] ())
+ (node-subseq [this cmp start] ())
+
+ Basic
+ (get-node [this id not-found] not-found)
+ (assoc-node! [this id attrs] nil)
+ (dissoc-node! [this id] nil)
+
+ Layer
+ (open [this] nil)
+ (close [this] nil)
+ (sync! [this] nil)
+ (optimize! [this] nil)
+ (truncate! [this] nil)
+
+ Schema
+ (schema [this id] nil)
+ (verify-node [this id attrs] nil)
+
+ ChangeLog
+ (get-revisions [this id] nil)
+ (get-changed-ids [this rev] nil)
+
+ Transactional
+ (txn-begin! [this] nil)
+ (txn-commit! [this] nil)
+ (txn-rollback! [this] nil)
+
+ OrderedRevisions
+ (max-revision [this] Double/POSITIVE_INFINITY)
+ (touch [this] nil)
+
+ Preferences
+ (manage-changelog? [this] false)
+ (manage-incoming? [this] false)
+ (single-edge? [this] false))
+
+(defn make []
+ (NullLayer.))
View
@@ -4,6 +4,7 @@
[retro.core :as retro :only [dotxn]])
(:require [jiraph.stm-layer :as stm]
[jiraph.layer :as layer]
+ [jiraph.null-layer :as null]
[jiraph.masai-layer :as masai]
[jiraph.masai-sorted-layer :as sorted]))
@@ -273,6 +274,22 @@
(get-node layer "x"))
:masai :sorted))))
+(deftest null-layer-revisions
+ (with-graph (assoc (make-graph)
+ :null (null/make))
+ (is (= 0 (current-revision) (uncommitted-revision)))
+
+ (at-revision 100
+ (with-each-layer []
+ (assoc-node! layer-name :foo {:blah 1})))
+
+ (is (= 100 (current-revision) (uncommitted-revision)))
+
+ (with-each-layer [:masai :sorted]
+ (is (= {:blah 1} (get-node layer-name :foo))))
+
+ (is (= 432 (get-node :null :foo 432)))))
+
(comment
(deftest compact-node
(with-graph (make-graph)

0 comments on commit 3353984

Please sign in to comment.