Skip to content

Commit

Permalink
Fixed update-store function and tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paula Gearon committed Jan 13, 2021
1 parent d06c6b9 commit 76375e4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
## [Unreleased]
Nothing yet.

## [0.3.9] - 2021-01-12
### Fixed
- The `update-store` API was erroneously change in the last release, and also contained a consistency bug.
Also added a new test for this function, as it never had one before.

## [0.3.8] - 2021-01-11
### Added
- The `update-store` operation had been removed due to lack of support in Asami,
Expand Down Expand Up @@ -53,7 +58,8 @@ Nothing yet.
### Changed
- Shifted data management to Zuko

[Unreleased]: https://github.com/threatgrid/naga/compare/0.3.8...HEAD
[Unreleased]: https://github.com/threatgrid/naga/compare/0.3.9...HEAD
[0.3.9]: https://github.com/threatgrid/naga/compare/0.3.8...0.3.9
[0.3.8]: https://github.com/threatgrid/naga/compare/0.3.7...0.3.8
[0.3.7]: https://github.com/threatgrid/naga/compare/0.3.6...0.3.7
[0.3.6]: https://github.com/threatgrid/naga/compare/0.3.5...0.3.6
Expand Down
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.clojars.quoll/naga "0.3.8"
(defproject org.clojars.quoll/naga "0.3.9"
:description "Forward Chaining Rule Engine"
:url "http://github.com/threatgrid/naga"
:license {:name "Eclipse Public License"
Expand All @@ -12,7 +12,7 @@
[cheshire "5.10.0"]
[org.clojars.quoll/naga-store "0.5.0"]
[org.clojars.quoll/zuko "0.3.3"]
[org.clojars.quoll/asami "1.2.10"]
[org.clojars.quoll/asami "1.2.11"]
[org.clojars.quoll/qtest "0.1.1"]
; [com.datomic/datomic-pro "0.9.5697" :exclusions [com.google.guava/guava] ; uncomment for Datomic Pro
[com.datomic/datomic-free "0.9.5697" :exclusions [com.google.guava/guava]]
Expand Down
5 changes: 3 additions & 2 deletions src/naga/storage/asami/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@
(defn update-store
"Note: This is currently employed by legacy code that is unaware of transaction IDs.
Consider using the Asami API directly."
[{:keys [connection]} f & args]
(apply ->AsamiStore connection (asami/transact connection {:update-fn (fn [g tx] (apply f g args))})))
[{:keys [connection before-graph]} f & args]
(let [{:keys [db-after]} @(asami/transact connection {:update-fn (fn [g tx] (apply f g args))})]
(->AsamiStore connection before-graph (asami/graph db-after))))

(s/defn create-store :- StorageType
"Factory function to create a store"
Expand Down
41 changes: 39 additions & 2 deletions test/naga/storage/test_asami.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns naga.storage.test-asami
#?(:clj (:require [naga.store :refer [assert-data resolve-pattern count-pattern query start-tx commit-tx deltas]]
[naga.storage.asami.core :refer [create-store]]
[naga.storage.asami.core :refer [create-store update-store]]
[asami.graph :as graph]
[clojure.test :as t :refer [testing is run-tests]]
[clojure.edn :as edn]
[schema.test :as st :refer [deftest]])
:cljs (:require [naga.store :refer [assert-data resolve-pattern count-pattern query start-tx commit-tx deltas]]
[naga.storage.asami.core :refer [create-store]]
[naga.storage.asami.core :refer [create-store update-store]]
[asami.graph :as graph]
[clojure.test :as t :refer-macros [testing is run-tests]]
[schema.test :as st :refer-macros [deftest]]))
#?(:clj (:import [java.time ZonedDateTime])))
Expand Down Expand Up @@ -60,6 +62,41 @@
[:b :x]
[:d :z]} r9))))

(deftest test-update
(let [s (assert-data (create-store) data)
r1 (unordered-resolve s '[:a ?a ?b])
r2 (unordered-resolve s '[?a :p2 ?b])
r3 (unordered-resolve s '[:a :p1 ?a])
r4 (unordered-resolve s '[?a :p2 :z])
r5 (unordered-resolve s '[:a ?a :x])
r6 (unordered-resolve s '[:a :p4 ?a])
r7 (unordered-resolve s '[:c :p4 :t])
s' (update-store s (fn [g s1 s2] (reduce (partial apply graph/graph-add) g [s1 s2]))
[:d :p2 :z] [:a :p4 :y])
r8 (unordered-resolve s' '[:a ?a ?b])
r9 (unordered-resolve s' '[?a :p2 ?b])]
(is (= #{[:p1 :x]
[:p1 :y]
[:p2 :z]
[:p3 :x]} r1))
(is (= #{[:a :z]
[:b :x]} r2))
(is (= #{[:x]
[:y]} r3))
(is (= #{[:a]} r4))
(is (= #{[:p1]
[:p3]} r5))
(is (empty? r6))
(is (= #{[]} r7))
(is (= #{[:p1 :x]
[:p1 :y]
[:p2 :z]
[:p3 :x]
[:p4 :y]} r8))
(is (= #{[:a :z]
[:b :x]
[:d :z]} r9))))

(deftest test-count
(let [s (assert-data (create-store) data)
r1 (count-pattern s '[:a ?a ?b])
Expand Down

0 comments on commit 76375e4

Please sign in to comment.