Skip to content

Commit

Permalink
seq exec read txs
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Oct 31, 2024
1 parent 000a11d commit 188794e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
5 changes: 1 addition & 4 deletions scalardb/src/scalardb/transfer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@
[test n]
(scalar/check-transaction-connection! test)
(scalar/check-storage-connection! test)
(try
(doall (pmap #(read-record-with-retry test %) (range n)))
;; unwrap the exception
(catch java.util.concurrent.ExecutionException e (throw (.getCause e)))))
(doall (map #(read-record-with-retry test %) (range n))))

(defrecord TransferClient [initialized? n initial-balance max-txs]
client/Client
Expand Down
18 changes: 5 additions & 13 deletions scalardb/test/scalardb/transfer_2pc_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,18 @@
scalar/prepare-transaction-service! (spy/spy)
scalar/prepare-storage-service! (spy/spy)
scalar/start-transaction (spy/stub mock-transaction-throws-exception)]
(let [num-accounts 5
client (client/open! (transfer-2pc/->TransferClient (atom false)
num-accounts
100 1)
nil nil)
retries-reconnection (* num-accounts
(+ (quot scalar/RETRIES
scalar/RETRIES_FOR_RECONNECTION)
1))]
(let [client (client/open! (transfer-2pc/->TransferClient (atom false) 5 100 1)
nil nil)]
(is (thrown? clojure.lang.ExceptionInfo
(client/invoke! client {:db mock-db
:storage (ref mock-storage)}
(#'transfer/get-all {:client client}
nil))))
(is (spy/called-n-times? scalar/exponential-backoff
(* scalar/RETRIES num-accounts)))
(is (spy/called-n-times? scalar/exponential-backoff scalar/RETRIES))
(is (spy/called-n-times? scalar/prepare-transaction-service!
retries-reconnection))
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1)))
(is (spy/called-n-times? scalar/prepare-storage-service!
retries-reconnection)))))
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1))))))

(deftest transfer-client-check-tx-test
(with-redefs [scalar/check-transaction-states (spy/stub 1)]
Expand Down
17 changes: 5 additions & 12 deletions scalardb/test/scalardb/transfer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,18 @@
scalar/prepare-transaction-service! (spy/spy)
scalar/prepare-storage-service! (spy/spy)
scalar/start-transaction (spy/stub mock-transaction-throws-exception)]
(let [num-accounts 5
client (client/open! (transfer/->TransferClient (atom false)
num-accounts 100 1)
nil nil)
retries-reconnection (* num-accounts
(+ (quot scalar/RETRIES
scalar/RETRIES_FOR_RECONNECTION)
1))]
(let [client (client/open! (transfer/->TransferClient (atom false) 5 100 1)
nil nil)]
(is (thrown? clojure.lang.ExceptionInfo
(client/invoke! client {:db mock-db
:storage (ref mock-storage)}
(#'transfer/get-all {:client client}
nil))))
(is (spy/called-n-times? scalar/exponential-backoff
(* scalar/RETRIES num-accounts)))
(is (spy/called-n-times? scalar/exponential-backoff scalar/RETRIES))
(is (spy/called-n-times? scalar/prepare-transaction-service!
retries-reconnection))
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1)))
(is (spy/called-n-times? scalar/prepare-storage-service!
retries-reconnection)))))
(+ (quot scalar/RETRIES scalar/RETRIES_FOR_RECONNECTION) 1))))))

(deftest transfer-client-check-tx-test
(with-redefs [scalar/check-transaction-states (spy/stub 1)]
Expand Down

0 comments on commit 188794e

Please sign in to comment.