use uuid::Uuid;
use super::CreateDs;
use crate::kvs::LockType::*;
use crate::kvs::TransactionType::*;
pub async fn snapshot(new_ds: impl CreateDs) {
let node_id = Uuid::parse_str("056804f2-b379-4397-9ceb-af8ebd527beb").unwrap();
let (ds, _) = new_ds.create_ds(node_id).await;
let tx = ds.transaction(Write, Optimistic).await.unwrap();
tx.set(&"test", &"some text".as_bytes().to_vec()).await.unwrap();
tx.commit().await.unwrap();
let tx1 = ds.transaction(Read, Optimistic).await.unwrap();
let val = tx1.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"some text");
let txw = ds.transaction(Write, Optimistic).await.unwrap();
txw.set(&"test", &"other text".as_bytes().to_vec()).await.unwrap();
let tx2 = ds.transaction(Read, Optimistic).await.unwrap();
let val = tx2.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"some text");
let tx3 = ds.transaction(Read, Optimistic).await.unwrap();
let val = tx3.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"some text");
txw.set(&"test", &"extra text".as_bytes().to_vec()).await.unwrap();
let val = tx1.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"some text");
tx1.cancel().await.unwrap();
tx2.cancel().await.unwrap();
tx3.cancel().await.unwrap();
txw.commit().await.unwrap();
let tx = ds.transaction(Read, Optimistic).await.unwrap();
let val = tx.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"extra text");
tx.cancel().await.unwrap();
}
macro_rules! define_tests {
($new_ds:ident) => {
#[tokio::test]
#[serial_test::serial]
async fn snapshot() {
super::snapshot::snapshot($new_ds).await;
}
};
}
pub(crate) use define_tests;