Skip to content

Commit 260bcd7

Browse files
committed
test: test multi-region batch_get_for_update
Signed-off-by: ekexium <ekexium@gmail.com>
1 parent 555981e commit 260bcd7

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

tests/integration_tests.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,15 @@ async fn raw_bank_transfer() -> Result<()> {
225225
/// Tests transactional API when there are multiple regions.
226226
/// Write large volumes of data to enforce region splitting.
227227
/// In order to test `scan`, data is uniformly inserted.
228+
// FIXME: this test is stupid. We should use pd-ctl or config files to make
229+
// multiple regions, instead of bulk writing.
228230
#[tokio::test]
229231
#[serial]
230232
async fn txn_write_million() -> Result<()> {
231-
const NUM_BITS_TXN: u32 = 7;
232-
const NUM_BITS_KEY_PER_TXN: u32 = 3;
233+
const NUM_BITS_TXN: u32 = 12;
234+
const NUM_BITS_KEY_PER_TXN: u32 = 5;
233235
let interval = 2u32.pow(32 - NUM_BITS_TXN - NUM_BITS_KEY_PER_TXN);
236+
let value = "large_value".repeat(10);
234237

235238
clear_tikv().await;
236239
let client = TransactionClient::new(pd_addrs()).await?;
@@ -246,7 +249,7 @@ async fn txn_write_million() -> Result<()> {
246249
.take(2usize.pow(NUM_BITS_KEY_PER_TXN))
247250
.collect::<Vec<_>>(); // each txn puts 2 ^ 12 keys. 12 = 25 - 13
248251
let mut txn = client.begin_optimistic().await?;
249-
for (k, v) in keys.iter().zip(iter::repeat(1u32.to_be_bytes().to_vec())) {
252+
for (k, v) in keys.iter().zip(iter::repeat(value.clone())) {
250253
txn.put(k.clone(), v).await?;
251254
}
252255
txn.commit().await?;
@@ -298,6 +301,29 @@ async fn txn_write_million() -> Result<()> {
298301

299302
assert_eq!(sum, 2usize.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN));
300303

304+
// test batch_get and batch_get_for_update
305+
const SKIP_BITS: u32 = 6; // do not retrive all because there's a limit of message size
306+
let mut cur = 0u32;
307+
let keys = iter::repeat_with(|| {
308+
let v = cur;
309+
cur = cur.overflowing_add(interval * 2u32.pow(SKIP_BITS)).0;
310+
v
311+
})
312+
.map(|u| u.to_be_bytes().to_vec())
313+
.take(2usize.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN - SKIP_BITS))
314+
.collect::<Vec<_>>();
315+
316+
let mut txn = client.begin_pessimistic().await?;
317+
let res = txn.batch_get(keys.clone()).await?.collect::<Vec<_>>();
318+
assert_eq!(res.len(), keys.len());
319+
320+
let res = txn
321+
.batch_get_for_update(keys.clone())
322+
.await?
323+
.collect::<Vec<_>>();
324+
assert_eq!(res.len(), keys.len());
325+
326+
txn.commit().await?;
301327
Ok(())
302328
}
303329

0 commit comments

Comments
 (0)