test: read fewer keys in txn_write_million to satisfy grpc message size limit

Signed-off-by: ekexium <ekexium@gmail.com>
This commit is contained in:
ekexium 2021-04-07 16:16:28 +08:00
parent 4120b76455
commit 6f6834a428
1 changed files with 40 additions and 40 deletions

View File

@ -218,8 +218,8 @@ async fn raw_bank_transfer() -> Result<()> {
#[tokio::test]
#[serial]
async fn txn_write_million() -> Result<()> {
const NUM_BITS_TXN: u32 = 12;
const NUM_BITS_KEY_PER_TXN: u32 = 5;
const NUM_BITS_TXN: u32 = 13;
const NUM_BITS_KEY_PER_TXN: u32 = 4;
let interval = 2u32.pow(32 - NUM_BITS_TXN - NUM_BITS_KEY_PER_TXN);
let value = "large_value".repeat(10);
@ -235,7 +235,7 @@ async fn txn_write_million() -> Result<()> {
})
.map(|u| u.to_be_bytes().to_vec())
.take(2usize.pow(NUM_BITS_KEY_PER_TXN))
.collect::<Vec<_>>(); // each txn puts 2 ^ 12 keys. 12 = 25 - 13
.collect::<Vec<_>>();
let mut txn = client.begin_optimistic().await?;
for (k, v) in keys.iter().zip(iter::repeat(value.clone())) {
txn.put(k.clone(), v).await?;
@ -247,50 +247,50 @@ async fn txn_write_million() -> Result<()> {
assert_eq!(res.count(), 2usize.pow(NUM_BITS_KEY_PER_TXN));
txn.commit().await?;
}
/* FIXME: scan all keys will make the message size exceed its limit
// test scan
let limit = 2u32.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN + 2); // large enough
let snapshot = client.snapshot(
client.current_timestamp().await?,
TransactionOptions::default(),
);
let res = snapshot.scan(vec![].., limit).await?;
assert_eq!(res.count(), 2usize.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN));
// test scan
let limit = 2u32.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN + 2); // large enough
let snapshot = client.snapshot(
client.current_timestamp().await?,
TransactionOptions::default(),
);
let res = snapshot.scan(vec![].., limit).await?;
assert_eq!(res.count(), 2usize.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN));
// scan by small range and combine them
let mut rng = thread_rng();
let mut keys = gen_u32_keys(200, &mut rng)
.iter()
.cloned()
.collect::<Vec<_>>();
keys.sort();
// scan by small range and combine them
let mut rng = thread_rng();
let mut keys = gen_u32_keys(10, &mut rng)
.iter()
.cloned()
.collect::<Vec<_>>();
keys.sort();
let mut sum = 0;
let mut sum = 0;
// empty key to key[0]
let snapshot = client.snapshot(
client.current_timestamp().await?,
TransactionOptions::default(),
);
let res = snapshot.scan(vec![]..keys[0].clone(), limit).await?;
sum += res.count();
// empty key to key[0]
let snapshot = client.snapshot(
client.current_timestamp().await?,
TransactionOptions::default(),
);
let res = snapshot.scan(vec![]..keys[0].clone(), limit).await?;
sum += res.count();
// key[i] .. key[i+1]
for i in 0..keys.len() - 1 {
let res = snapshot
.scan(keys[i].clone()..keys[i + 1].clone(), limit)
.await?;
sum += res.count();
}
// key[i] .. key[i+1]
for i in 0..keys.len() - 1 {
let res = snapshot
.scan(keys[i].clone()..keys[i + 1].clone(), limit)
.await?;
sum += res.count();
}
// keys[last] to unbounded
let res = snapshot.scan(keys[keys.len() - 1].clone().., limit).await?;
sum += res.count();
assert_eq!(sum, 2usize.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN));
// keys[last] to unbounded
let res = snapshot.scan(keys[keys.len() - 1].clone().., limit).await?;
sum += res.count();
assert_eq!(sum, 2usize.pow(NUM_BITS_KEY_PER_TXN + NUM_BITS_TXN));
*/
// test batch_get and batch_get_for_update
const SKIP_BITS: u32 = 7; // do not retrive all because there's a limit of message size
const SKIP_BITS: u32 = 12; // do not retrieve all because there's a limit of message size
let mut cur = 0u32;
let keys = iter::repeat_with(|| {
let v = cur;