Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@
(pr-str updated-collections))

;; Reindex the collections that were modified
(->> updated-collections
(meta-db/get-latest-concepts context)
;; wrap each concept in its own batch for bulk-index
(map vector)
(index-service/bulk-index context es-config/elastic-name)))))
(let [concept-batches (->> updated-collections
(meta-db/get-latest-concepts context)
;; wrap each concept in its own batch for bulk-index
(map vector))]
(index-service/bulk-index context concept-batches es-config/elastic-name)))))

;; There's no existing value so a full refresh is required.
(full-cache-refresh context))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
[clojure.test :refer :all]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :refer [for-all]]
[cmr.common.cache :as cache]
[cmr.common.cache.in-memory-cache :as in-memory-cache]
[cmr.common.test.test-check-ext :as ext-gen :refer [defspec]]
[cmr.common.util :as u]
[cmr.indexer.data.collection-granule-aggregation-cache :as cgac]))
[cmr.elastic-utils.config :as es-config]
[cmr.indexer.data.collection-granule-aggregation-cache :as cgac]
[cmr.indexer.services.index-service :as index-service]
[cmr.transmit.metadata-db :as meta-db]))

(def sample-response
{:took 7,
Expand Down Expand Up @@ -48,6 +53,73 @@
edn/read-string
(#'cgac/cached-value->coll-gran-aggregates)))))

(deftest partial-cache-refresh-reindexes-updated-collections-test
(testing "collections with updated temporal ranges are passed to bulk-index as proper concept
Comment thread
jaortega527 marked this conversation as resolved.
Resolved
batches (regression test for CMR-11401: bulk-index was previously called with its
concept-batches and es-cluster-name arguments swapped, causing bulk-index to reduce
over the cluster name string and pass individual Characters to prepare-batch, which
throws \"Don't know how to create ISeq from: java.lang.Character\")"
(let [cgac-cache (in-memory-cache/create-in-memory-cache)
context {:system {:caches {cgac/coll-gran-aggregate-cache-key cgac-cache}}}
;; Widen C1-PROV1's end date so it is detected as updated. Leave C2-PROV1 unchanged.
updated-granule-map {"C1-PROV1" {:granule-start-date (t/date-time 2003)
:granule-end-date (t/date-time 2010)}}
bulk-index-calls (atom [])
c1-concept {:concept-id "C1-PROV1" :revision-id 1}]
(cache/set-value cgac-cache
cgac/coll-gran-aggregate-cache-key
(#'cgac/coll-gran-aggregates->cachable-value sample-coll-gran-aggregates))
(with-redefs [cgac/fetch-coll-gran-aggregates-updated-in-last-n
(fn [_context _granules-updated-in-last-n] updated-granule-map)

meta-db/get-latest-concepts
(fn [_context concept-ids] (map #(assoc c1-concept :concept-id %) concept-ids))

index-service/bulk-index
(fn [_context concept-batches es-cluster-name]
(swap! bulk-index-calls conj {:concept-batches concept-batches
:es-cluster-name es-cluster-name}))]
(cgac/refresh-cache context 3900))

(testing "bulk-index is called exactly once"
(is (= 1 (count @bulk-index-calls))))

(let [{:keys [concept-batches es-cluster-name]} (first @bulk-index-calls)]
(testing "the elastic cluster name is passed as es-cluster-name, not as concept-batches"
(is (= es-config/elastic-name es-cluster-name)))

(testing "concept-batches is a seq of concept batches - not a seq of Characters from the
cluster name string"
(is (= [[(assoc c1-concept :concept-id "C1-PROV1")]]
concept-batches))))

(testing "the cache was updated with the widened temporal range"
(is (= (get-in sample-coll-gran-aggregates ["C1-PROV1" :granule-end-date])
Comment thread
jaortega527 marked this conversation as resolved.
Resolved
(t/date-time 2008)))
(is (= (t/date-time 2010)
(get-in (#'cgac/cached-value->coll-gran-aggregates
(cache/get-value cgac-cache cgac/coll-gran-aggregate-cache-key))
["C1-PROV1" :granule-end-date])))))))

(deftest partial-cache-refresh-no-updates-does-not-reindex-test
Comment thread
jaortega527 marked this conversation as resolved.
Resolved
(testing "bulk-index is not called when no collections have updated temporal ranges"
(let [cgac-cache (in-memory-cache/create-in-memory-cache)
context {:system {:caches {cgac/coll-gran-aggregate-cache-key cgac-cache}}}
bulk-index-calls (atom [])]
(cache/set-value cgac-cache
cgac/coll-gran-aggregate-cache-key
(#'cgac/coll-gran-aggregates->cachable-value sample-coll-gran-aggregates))
(with-redefs [cgac/fetch-coll-gran-aggregates-updated-in-last-n
(fn [_context _granules-updated-in-last-n] {})

index-service/bulk-index
(fn [_context concept-batches es-cluster-name]
(swap! bulk-index-calls conj {:concept-batches concept-batches
:es-cluster-name es-cluster-name}))]
(cgac/refresh-cache context 3900))

(is (empty? @bulk-index-calls)))))

(defn times->longs
"Converts all the times in a collection granule aggregate to long values. This makes it easier to
compare and construct for testing."
Expand Down
Loading