#![cfg(feature = "kv-tikv")]
use uuid::Uuid;
use super::CreateDs;
use crate::kvs::LockType::*;
use crate::kvs::TransactionType::*;
pub async fn multiwriter_same_keys_allow(new_ds: impl CreateDs) {
let node_id = Uuid::parse_str("a19cf00d-f95b-42c6-95e5-7b310162d570").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(Write, Optimistic).await.unwrap();
tx1.set(&"test", &"other text 1".as_bytes().to_vec()).await.unwrap();
let tx2 = ds.transaction(Write, Optimistic).await.unwrap();
tx2.set(&"test", &"other text 2".as_bytes().to_vec()).await.unwrap();
let tx3 = ds.transaction(Write, Optimistic).await.unwrap();
tx3.set(&"test", &"other text 3".as_bytes().to_vec()).await.unwrap();
tx1.commit().await.unwrap();
tx2.commit().await.unwrap();
tx3.commit().await.unwrap();
let tx = ds.transaction(Read, Optimistic).await.unwrap();
let val = tx.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"other text 3");
tx.cancel().await.unwrap();
let tx = ds.transaction(Write, Optimistic).await.unwrap();
tx.set(&"test", &"original text".as_bytes().to_vec()).await.unwrap();
tx.commit().await.unwrap();
let tx = ds.transaction(Read, Optimistic).await.unwrap();
let val = tx.get(&"test", None).await.unwrap().unwrap();
assert_eq!(val, b"original text");
tx.cancel().await.unwrap();
}
macro_rules! define_tests {
($new_ds:ident) => {
#[tokio::test]
#[serial_test::serial]
async fn multiwriter_same_keys_allow() {
super::multiwriter_same_keys_allow::multiwriter_same_keys_allow($new_ds).await;
}
};
}
pub(crate) use define_tests;