(ns blocks.store.replica-test
  (:require
    (blocks.store
      [memory :refer [memory-store]]
      [replica :refer [replica-store]]
      [tests :refer [test-block-store]])
    [clojure.test :refer :all]))


; TODO: test that writes actually populate all backing stores.
; TODO: test that removing blocks from one store still returns all blocks.
; TODO: test that listing provides merged block list.


(deftest ^:integration test-replica-store
  (let [store (replica-store [(memory-store) (memory-store)])]
    (test-block-store
      "replica-store" store
      :max-size 1024
      :blocks 25)))

(ns blocks.store.replica-test
  (:require
    [blocks.core :as block]
    (blocks.store
      [memory :refer [memory-store]]
      [replica :refer [replica-store]]
      [tests :refer [test-block-store]])
    [clojure.test :refer :all]))


(deftest replica-behavior
  (let [replica-1 (memory-store)
        replica-2 (memory-store)
        store (replica-store [replica-1 replica-2])
        a (block/read! "foo bar baz")
        b (block/read! "abracadabra")
        c (block/read! "123 xyz")]
    (block/put! store a)
    (block/put! store b)
    (block/put! store c)
    (is (= 3 (count (block/list replica-1))))
    (is (every? (partial block/get replica-1)
                (map :id [a b c]))
        "all blocks are stored in replica-1")
    (is (= 3 (count (block/list replica-2))))
    (is (every? (partial block/get replica-2)
                (map :id [a b c]))
        "all blocks are stored in replica-2")
    (is (= 3 (count (block/list store))))
    (block/delete! replica-1 (:id a))
    (block/delete! replica-2 (:id c))
    (is (= 3 (count (block/list store)))
        "replica lists all available blocks")))


(deftest ^:integration test-replica-store
  (let [store (replica-store [(memory-store) (memory-store)])]
    (test-block-store
      "replica-store" store
      :max-size 1024
      :blocks 25)))

Add tests for replication behavior.
Add tests for replication behavior.

greglook/blocks,greglook/blobble,greglook/blobble