From 14a52718a1c58c1b722e542ab7431d60b917f54a Mon Sep 17 00:00:00 2001 From: Dan Midwood Date: Fri, 8 Jun 2018 11:12:52 +0100 Subject: [PATCH] Fix: NPE reading optional results from cache We were seeing null pointer exceptions reading results from the disk that used OPTIONAL in the query. Grafter has been updated in grafter/#130 to handle nulls safely, which prevents the exception, but does put nils in our result sets. Meaning that the same query can have different results from the db (no nils) or the disk (w/ nils). I've added a test on the graph loading time to ensure everything returns as it should. That's an OPTIONAL using query so a great example. This resolves #264 --- project.clj | 2 +- test/drafter/stasher_test.clj | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 0475d4242..02e3710d7 100644 --- a/project.clj +++ b/project.clj @@ -60,7 +60,7 @@ [com.sun.mail/javax.mail "1.6.0"] ;;[com.taoensso/tower "2.0.2"] - [grafter "0.11.0-drafter-rdf4j-261-SNAPSHOT"] + [grafter "0.11.0.2-drafter-rdf4j-SNAPSHOT"] [grafter/url "0.2.5"] ;[grafter/vocabularies "0.1.3"] diff --git a/test/drafter/stasher_test.clj b/test/drafter/stasher_test.clj index d738ae498..c6670d08b 100644 --- a/test/drafter/stasher_test.clj +++ b/test/drafter/stasher_test.clj @@ -328,12 +328,31 @@ (deftest-system fetch-modified-state-test - ;; Here we're just testing the underlying modified time queries, so we do - ;; so on a standard RDF4j repo, not a stasher/caching one. [{repo :drafter.stasher/repo} "drafter/stasher-test/drafter-state-1.edn"] (t/is (some? repo) "No repo!") (with-open [conn (.getConnection repo)] + (t/testing "Fetching draftset modified times" + (t/is (= ds-1-most-recently-modified + (sut/fetch-modified-state conn {:named-graphs ds-1 :default-graphs ds-1}))) + + (t/is (= ds-2-most-recently-modified + (sut/fetch-modified-state conn {:named-graphs ds-2 :default-graphs ds-2})))) + + (t/testing "Fetching live graph modified times" + (t/is (= liveset-most-recently-modified + (sut/fetch-modified-state conn {:named-graphs [live-graph-1 live-graph-only] :default-graphs [live-graph-1 live-graph-only]})))) + + (t/testing "Fetching draftsets with union-with-live set" + ;; Union with live is at this low level equivalent to merging the + ;; set of live graphs in to :named-graphs and :default-graphs. + (let [ds-1-union-with-live (conj ds-1 live-graph-1 live-graph-only) + dataset {:named-graphs ds-1-union-with-live :default-graphs ds-1-union-with-live}] + (t/is (= (merge liveset-most-recently-modified + ds-1-most-recently-modified) + (sut/fetch-modified-state conn dataset)))))) + (with-open [conn (.getConnection repo)] + (t/testing "Fetching draftset modified times" (t/is (= ds-1-most-recently-modified (sut/fetch-modified-state conn {:named-graphs ds-1 :default-graphs ds-1})))