Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate Index #218

Merged
merged 5 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
:ns-default build}

:dev
{:extra-paths ["dev" "test" "src-cljs" "src-nodejs" "src-docs"]
{:extra-paths ["dev" "test" "dev-resources" "src-cljs" "src-nodejs" "src-docs"]
:extra-deps {org.clojure/tools.namespace {:mvn/version "1.3.0"}
figwheel-sidecar/figwheel-sidecar {:mvn/version "0.5.20"}
thheller/shadow-cljs {:mvn/version "2.20.7"}}}

:cljtest
{:extra-paths ["test"]
{:extra-paths ["test" "dev-resources"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}
org.clojure/test.check {:mvn/version "1.1.1"}}
:main-opts ["-m" "kaocha.runner"]}
Expand Down
10 changes: 10 additions & 0 deletions dev-resources/default-context.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:id "@id"
:type "@type"
:xsd "http://www.w3.org/2001/XMLSchema#"
:rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
:rdfs "http://www.w3.org/2000/01/rdf-schema#"
:sh "http://www.w3.org/ns/shacl#"
:schema "http://schema.org/"
:skos "http://www.w3.org/2008/05/skos#"
:wiki "https://www.wikidata.org/wiki/"
:f "https://ns.flur.ee/ledger#"}
1 change: 1 addition & 0 deletions dev-resources/default-dev-private-key.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"8ce4eca704d653dec594703c81a84c403c39f262e54ed014ed857438933a2e1c"
13 changes: 13 additions & 0 deletions dev-resources/movies.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{"@context" "https://schema.org",
"id" "https://www.wikidata.org/wiki/Q836821",
"type" ["Movie"],
"name" "The Hitchhiker's Guide to the Galaxy",
"disambiguatingDescription" "2005 British-American comic science fiction film directed by Garth Jennings",
"titleEIDR" "10.5240/B752-5B47-DBBE-E5D4-5A3F-N",
"isBasedOn" {"id" "https://www.wikidata.org/wiki/Q3107329",
"type" "Book",
"name" "The Hitchhiker's Guide to the Galaxy",
"isbn" "0-330-25864-8",
"author" {"@id" "https://www.wikidata.org/wiki/Q42"
"@type" "Person"
"name" "Douglas Adams"}}}
26 changes: 0 additions & 26 deletions src/fluree/db/ledger/json_ld.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,6 @@
(recur r db**))
db*))))

;; TODO - below is just an event handler for indexing service, ultimately pass message to any listeners for the ledger
(defn update-index
"When indexing is complete, updates index market for DB/ledger"
[ledger {:keys [t port] :as event-meta}]
(async/go
(let [indexed-db (async/<! port)
{:keys [stats commit]} indexed-db]
(log/warn "update-index - meta: " event-meta)

)

)
)

(defn register-index-watcher
[indexer {:keys [id address] :as ledger}]
(let [f (fn [{:keys [event] :as event-meta}]
(log/debug "Indexing event for ledger" address ":" event)
(case event
:index-start :TODO
:index-end (update-index ledger event-meta)
;; else
(log/warn "Other index event: " event-meta)))]
(idx-proto/-add-watch indexer id f)))

(defn create
"Creates a new ledger, optionally bootstraps it as permissioned or with default context."
[conn ledger-alias opts]
Expand Down Expand Up @@ -227,7 +202,6 @@
db (if bootstrap?
(<? (bootstrap/bootstrap blank-db context* (:id did*)))
(bootstrap/blank-db blank-db))]
(register-index-watcher indexer ledger)
;; place initial 'blank' DB into ledger.
(ledger-proto/-db-update ledger db)
(when include
Expand Down
217 changes: 103 additions & 114 deletions test/fluree/db/query/json_ld_basic_test.clj

Large diffs are not rendered by default.

21 changes: 3 additions & 18 deletions test/fluree/db/query/json_ld_compound_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
(:require
[clojure.string :as str]
[clojure.test :refer :all]
[fluree.db.test-fixtures :as test]
[fluree.db.test-utils :as test-utils]
[fluree.db.json-ld.api :as fluree]
[fluree.db.util.log :as log]))


(use-fixtures :once test/test-system)

(deftest simple-compound-queries
(deftest ^:integration simple-compound-queries
(testing "Simple compound queries."
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "query/compounda")
db @(fluree/stage
ledger
Expand Down Expand Up @@ -152,17 +149,6 @@



; using sum aggregate function on multicardinality value
;(is (= @(fluree/query db {:context {:ex "http://example.org/ns/"}
; :select ['?name '(sum ?favNums)]
; :where [['?s :schema/name '?name]
; ['?s :ex/favNums '?favNums]]
; :group-by '?name})
; [["Alice" 127]
; ["Brian" 7]
; ["Cam" 15]])
; "Sums of favNums by person are not accurate.")

;; checking s, p, o values all pulled correctly and all IRIs are resolved from sid integer & compacted
(is (= @(fluree/query db
{:context {:ex "http://example.org/ns/"}
Expand All @@ -179,4 +165,3 @@
[:ex/cam :ex/friend :ex/brian]
[:ex/cam :ex/friend :ex/alice]])
"IRIs are resolved from subj ids, whether s, p, or o vals."))))

10 changes: 4 additions & 6 deletions test/fluree/db/query/subclass_test.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(ns fluree.db.query.subclass-test
(:require [clojure.test :refer :all]
[fluree.db.test-fixtures :as test]
[fluree.db.test-utils :as test-utils]
[fluree.db.json-ld.api :as fluree]
[fluree.db.util.log :as log]))

(use-fixtures :once test/test-system)

(deftest subclass-test
(deftest ^:integration subclass-test
(testing "Subclass queries work."
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "query/subclass")
db1 @(fluree/stage
ledger
Expand Down Expand Up @@ -61,4 +59,4 @@
:schema/name "The Hitchhiker's Guide to the Galaxy",
:schema/isbn "0-330-25864-8",
:schema/author {:id :wiki/Q42}}])
"CreativeWork query should return both Book and Movie"))))
"CreativeWork query should return both Book and Movie"))))
23 changes: 10 additions & 13 deletions test/fluree/db/shacl/shacl_basic_test.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
(ns fluree.db.shacl.shacl-basic-test
(:require [clojure.test :refer :all]
[fluree.db.test-fixtures :as test]
[fluree.db.test-utils :as test-utils]
[fluree.db.json-ld.api :as fluree]
[fluree.db.util.log :as log]
[fluree.db.util.core :as util]
[clojure.string :as str]))


(use-fixtures :once test/test-system)

(deftest using-pre-defined-types-as-classes
(deftest ^:integration using-pre-defined-types-as-classes
(testing "Class not used as class initially can still be used as one."
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "class/testing")
db1 @(fluree/stage
ledger
Expand All @@ -33,9 +30,9 @@
:schema/description "Now a new subject uses MyClass as a Class"}])))))


(deftest shacl-cardinality-constraints
(deftest ^:integration shacl-cardinality-constraints
(testing "shacl minimum and maximum cardinality"
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "shacl/a")
user-query {:context {:ex "http://example.org/ns/"}
:select {'?s [:*]}
Expand Down Expand Up @@ -91,9 +88,9 @@
"basic rdf:type query response not correct"))))


(deftest shacl-datatype-constraings
(deftest ^:integration shacl-datatype-constraings
(testing "shacl datatype errors"
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "shacl/b")
user-query {:context {:ex "http://example.org/ns/"}
:select {'?s [:*]}
Expand Down Expand Up @@ -144,9 +141,9 @@
"basic rdf:type query response not correct"))))


(deftest shacl-closed-shape
(deftest ^:integration shacl-closed-shape
(testing "shacl closed shape"
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "shacl/c")
user-query {:context {:ex "http://example.org/ns/"}
:select {'?s [:*]}
Expand Down Expand Up @@ -186,4 +183,4 @@
[{:id :ex/john,
:rdf/type [:ex/User],
:schema/name "John"}])
"basic rdf:type query response not correct"))))
"basic rdf:type query response not correct"))))
85 changes: 0 additions & 85 deletions test/fluree/db/test_fixtures.clj

This file was deleted.

33 changes: 33 additions & 0 deletions test/fluree/db/test_utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ns fluree.db.test-utils
(:require [clojure.test :refer :all]
[clojure.edn :as edn]
[clojure.java.io :as io]
[fluree.db.did :as did]
[fluree.db.json-ld.api :as fluree]
[fluree.db.util.log :as log])
(:import (java.io PushbackReader)))

(defn load-edn-resource
[resource-path]
(with-open [r (-> resource-path io/resource io/reader PushbackReader.)]
(edn/read r)))

(defn create-conn
([]
(create-conn {}))
([{:keys [context did]
:or {context (load-edn-resource "default-context.edn")
did (-> "default-dev-private-key.edn"
load-edn-resource
did/private->did-map)}}]
@(fluree/connect-memory {:defaults {:context context
:did did}})))

(defn load-movies
[conn]
(let [ledger @(fluree/create conn "test/movies")
movies (load-edn-resource "movies.edn")
stage1-db @(fluree/stage ledger movies)
commit1 @(fluree/commit! stage1-db {:message "First commit!"
:push? true})]
ledger))
8 changes: 3 additions & 5 deletions test/fluree/db/transact/retraction_test.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(ns fluree.db.transact.retraction-test
(:require [clojure.test :refer :all]
[fluree.db.test-fixtures :as test]
[fluree.db.test-utils :as test-utils]
[fluree.db.json-ld.api :as fluree]
[fluree.db.util.log :as log]))

(use-fixtures :once test/test-system)

(deftest retracting-data
(deftest ^:integration retracting-data
(testing "Retractions of individual properties and entire subjects."
(let [conn test/memory-conn
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "tx/retract")
db @(fluree/stage
ledger
Expand Down