|
8 | 8 | [scalardb.transfer-2pc :as transfer-2pc] |
9 | 9 | [spy.core :as spy]) |
10 | 10 | (:import (com.scalar.db.api DistributedTransaction |
11 | | - DistributedStorage |
12 | 11 | TwoPhaseCommitTransaction |
13 | 12 | Get |
14 | 13 | Put |
|
63 | 62 | (^void put [_ ^Put p] (mock-put p)) |
64 | 63 | (^void commit [_] (swap! commit-count inc)))) |
65 | 64 |
|
66 | | -(def mock-storage |
67 | | - (reify |
68 | | - DistributedStorage |
69 | | - (^Optional get [_ ^Get g] (mock-get g)) |
70 | | - (^void put [_ ^Put p] (mock-put p)))) |
71 | | - |
72 | 65 | (def mock-transaction-throws-exception |
73 | 66 | (reify |
74 | 67 | DistributedTransaction |
|
206 | 199 | (deftest transfer-client-get-all-test |
207 | 200 | (binding [test-records (atom {0 1000 1 100 2 10 3 1 4 0})] |
208 | 201 | (with-redefs [scalar/check-transaction-connection! (spy/spy) |
209 | | - scalar/check-storage-connection! (spy/spy) |
210 | 202 | scalar/start-transaction (spy/stub mock-transaction)] |
211 | 203 | (let [client (client/open! (transfer-2pc/->TransferClient (atom false) 5 100 1) |
212 | 204 | nil nil) |
213 | | - result (client/invoke! client {:db mock-db |
214 | | - :storage (ref mock-storage)} |
| 205 | + result (client/invoke! client {:db mock-db} |
215 | 206 | (#'transfer/get-all {:client client} |
216 | 207 | nil))] |
217 | 208 | (is (spy/called-once? scalar/check-transaction-connection!)) |
218 | | - (is (spy/called-once? scalar/check-storage-connection!)) |
219 | 209 | (is (= :ok (:type result))) |
220 | 210 | (is (= [1000 100 10 1 0] (get-in result [:value :balance]))) |
221 | 211 | (is (= [1000 100 10 1 0] (get-in result [:value :version]))))))) |
222 | 212 |
|
223 | 213 | (deftest transfer-client-get-all-fail-test |
224 | 214 | (with-redefs [scalar/exponential-backoff (spy/spy) |
225 | 215 | scalar/check-transaction-connection! (spy/spy) |
226 | | - scalar/check-storage-connection! (spy/spy) |
227 | 216 | scalar/prepare-transaction-service! (spy/spy) |
228 | | - scalar/prepare-storage-service! (spy/spy) |
229 | 217 | scalar/start-transaction (spy/stub mock-transaction-throws-exception)] |
230 | 218 | (let [client (client/open! (transfer-2pc/->TransferClient (atom false) 5 100 1) |
231 | 219 | nil nil)] |
232 | 220 | (is (thrown? clojure.lang.ExceptionInfo |
233 | | - (client/invoke! client {:db mock-db |
234 | | - :storage (ref mock-storage)} |
| 221 | + (client/invoke! client {:db mock-db} |
235 | 222 | (#'transfer/get-all {:client client} |
236 | 223 | nil)))) |
237 | 224 | (is (spy/called-n-times? scalar/exponential-backoff scalar/RETRIES)) |
238 | 225 | (is (spy/called-n-times? scalar/prepare-transaction-service! |
239 | | - (+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1))) |
240 | | - (is (spy/called-n-times? scalar/prepare-storage-service! |
241 | 226 | (+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1)))))) |
242 | 227 |
|
243 | 228 | (deftest transfer-client-check-tx-test |
|
0 commit comments