Add tests for buffered mutations

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
This commit is contained in:
Yilin Chen 2019-08-14 14:09:09 +08:00
parent a601c39c1f
commit 388f7cfaac
No known key found for this signature in database
GPG Key ID: 353E7ED34BF326E0
1 changed files with 45 additions and 0 deletions

View File

@ -399,3 +399,48 @@ impl Snapshot {
unimplemented!()
}
}
#[cfg(test)]
mod tests {
use super::*;
use futures::executor::block_on;
#[test]
fn set_and_get_from_buffer() {
let mut txn = mock_txn();
txn.set(b"key1".to_vec(), b"value1".to_vec());
txn.set(b"key2".to_vec(), b"value2".to_vec());
assert_eq!(
block_on(txn.get(b"key1".to_vec())).unwrap().unwrap(),
b"value1".to_vec().into()
);
txn.delete(b"key2".to_vec());
txn.set(b"key1".to_vec(), b"value".to_vec());
assert_eq!(
block_on(txn.batch_get(vec![b"key2".to_vec(), b"key1".to_vec()]))
.unwrap()
.collect::<Vec<_>>(),
vec![
(Key::from(b"key2".to_vec()), None),
(
Key::from(b"key1".to_vec()),
Some(Value::from(b"value".to_vec()))
),
]
);
}
fn mock_txn() -> Transaction {
let snapshot = Snapshot {
timestamp: Timestamp {
physical: 0,
logical: 0,
},
};
Transaction {
snapshot,
mutations: Default::default(),
}
}
}