|
27 | 27 |
|
28 | 28 | (setup! [this test node]
|
29 | 29 | (locking BankClientWithLua
|
30 |
| - (let [conn (cl/open node test)] |
| 30 | + (let [conn (cl/open node test) |
| 31 | + ; Distribute initial balances uniformly. |
| 32 | + initial-balance-per-account (/ (:total-amount test) |
| 33 | + (count (:accounts test)))] |
31 | 34 | (Thread/sleep 10000) ; wait for leader election and joining to a cluster
|
32 | 35 | (when (= node (first (db/primaries test)))
|
33 | 36 | (cl/with-conn-failure-retry conn
|
|
37 | 40 | balance INT NOT NULL)")])
|
38 | 41 | (doseq [a (:accounts test)]
|
39 | 42 | (info "Populating account")
|
40 |
| - (sql/insert! conn table-name {:id a |
41 |
| - :balance (if (= a (first (:accounts test))) |
42 |
| - (:total-amount test) |
43 |
| - 0)})))) |
| 43 | + (sql/insert! conn table-name |
| 44 | + {:id a |
| 45 | + :balance initial-balance-per-account})))) |
| 46 | + |
44 | 47 | (assoc this :conn conn :node node))))
|
45 | 48 |
|
46 | 49 | (invoke! [this test op]
|
|
79 | 82 |
|
80 | 83 | (setup! [this test node]
|
81 | 84 | (locking tbl-created?
|
82 |
| - (let [conn (cl/open node test)] |
| 85 | + (let [conn (cl/open node test) |
| 86 | + ; Distribute initial balances uniformly. |
| 87 | + initial-balance-per-account (/ (:total-amount test) |
| 88 | + (count (:accounts test)))] |
83 | 89 | (Thread/sleep 10000) ; wait for leader election and joining to a cluster
|
84 | 90 | (when (= node (first (db/primaries test)))
|
85 | 91 | (when (compare-and-set! tbl-created? false true)
|
|
92 | 98 | "balance INT NOT NULL)")])
|
93 | 99 | (info "Populating account" a)
|
94 | 100 | (sql/insert! conn (str table-name a)
|
95 |
| - {:id 0 |
96 |
| - :account_id a |
97 |
| - :balance 10}))))) |
| 101 | + {:id 0 |
| 102 | + :account_id a |
| 103 | + :balance initial-balance-per-account}))))) |
| 104 | + |
98 | 105 | (assoc this :conn conn :node node))))
|
99 | 106 |
|
100 | 107 | (invoke! [this test op]
|
|
147 | 154 |
|
148 | 155 | (setup! [this test node]
|
149 | 156 | (locking BankClient
|
150 |
| - (let [conn (cl/open node test)] |
| 157 | + (let [conn (cl/open node test) |
| 158 | + ; Distribute initial balances uniformly. |
| 159 | + initial-balance-per-account (/ (:total-amount test) |
| 160 | + (count (:accounts test)))] |
151 | 161 | (Thread/sleep 10000) ; wait for leader election and joining to a cluster
|
152 | 162 | (when (= node (first (db/primaries test)))
|
153 | 163 | (cl/with-conn-failure-retry conn
|
|
157 | 167 | balance INT NOT NULL)")])
|
158 | 168 | (doseq [a (:accounts test)]
|
159 | 169 | (info "Populating account")
|
160 |
| - (sql/insert! conn table-name {:id a |
161 |
| - :balance (if (= a (first (:accounts test))) |
162 |
| - (:total-amount test) |
163 |
| - 0)})))) |
| 170 | + (sql/insert! conn table-name |
| 171 | + {:id a |
| 172 | + :balance initial-balance-per-account})))) |
| 173 | + |
164 | 174 | (assoc this :conn conn :node node))))
|
165 | 175 |
|
166 | 176 | (invoke! [this test op]
|
|
209 | 219 |
|
210 | 220 | (setup! [this test node]
|
211 | 221 | (locking tbl-created?
|
212 |
| - (let [conn (cl/open node test)] |
| 222 | + (let [conn (cl/open node test) |
| 223 | + ; Distribute initial balances uniformly. |
| 224 | + initial-balance-per-account (/ (:total-amount test) |
| 225 | + (count (:accounts test)))] |
213 | 226 | (Thread/sleep 10000) ; wait for leader election and joining to a cluster
|
214 | 227 | (when (= node (first (db/primaries test)))
|
215 | 228 | (when (compare-and-set! tbl-created? false true)
|
|
221 | 234 | "balance INT NOT NULL)")])
|
222 | 235 | (info "Populating account" a)
|
223 | 236 | (sql/insert! conn (str table-name a)
|
224 |
| - {:id 0 |
225 |
| - :balance (if (= a (first (:accounts test))) |
226 |
| - (:total-amount test) |
227 |
| - 0)}))))) |
| 237 | + {:id 0 |
| 238 | + :balance initial-balance-per-account}))))) |
| 239 | + |
228 | 240 | (assoc this :conn conn :node node))))
|
229 | 241 |
|
230 | 242 | (invoke! [this test op]
|
|
0 commit comments