diff --git a/lib/src/kvs/tests/mod.rs b/lib/src/kvs/tests/mod.rs index 66ae3c5d..3782bdec 100644 --- a/lib/src/kvs/tests/mod.rs +++ b/lib/src/kvs/tests/mod.rs @@ -38,7 +38,8 @@ mod rocksdb { include!("raw.rs"); include!("snapshot.rs"); include!("multireader.rs"); - include!("multiwriter.rs"); + include!("multiwriter_different_keys.rs"); + include!("multiwriter_same_keys_conflict.rs"); } #[cfg(feature = "kv-speedb")] @@ -61,7 +62,8 @@ mod speedb { include!("raw.rs"); include!("snapshot.rs"); include!("multireader.rs"); - include!("multiwriter.rs"); + include!("multiwriter_different_keys.rs"); + include!("multiwriter_same_keys_conflict.rs"); } #[cfg(feature = "kv-tikv")] @@ -88,7 +90,8 @@ mod tikv { include!("raw.rs"); include!("snapshot.rs"); include!("multireader.rs"); - include!("multiwriter.rs"); + include!("multiwriter_different_keys.rs"); + include!("multiwriter_same_keys_conflict.rs"); } #[cfg(feature = "kv-fdb")] @@ -115,5 +118,6 @@ mod fdb { include!("raw.rs"); include!("snapshot.rs"); include!("multireader.rs"); - include!("multiwriter.rs"); + include!("multiwriter_different_keys.rs"); + include!("multiwriter_same_keys_allow.rs"); } diff --git a/lib/src/kvs/tests/multiwriter.rs b/lib/src/kvs/tests/multiwriter.rs deleted file mode 100644 index da4f073e..00000000 --- a/lib/src/kvs/tests/multiwriter.rs +++ /dev/null @@ -1,72 +0,0 @@ -#[tokio::test] -#[serial] -async fn multiwriter_same_key() { - // Create a new datastore - let ds = new_ds().await; - // Insert an initial key - let mut tx = ds.transaction(true, false).await.unwrap(); - tx.set("test", "some text").await.unwrap(); - tx.commit().await.unwrap(); - // Create a writeable transaction - let mut tx1 = ds.transaction(true, false).await.unwrap(); - tx1.set("test", "other text").await.unwrap(); - // Create a writeable transaction - let mut tx2 = ds.transaction(true, false).await.unwrap(); - tx2.set("test", "other text").await.unwrap(); - // Create a writeable transaction - let mut tx3 = ds.transaction(true, false).await.unwrap(); - tx3.set("test", "other text").await.unwrap(); - // Cancel both writeable transactions - assert!(tx1.commit().await.is_ok()); - assert!(tx2.commit().await.is_err()); - assert!(tx3.commit().await.is_err()); - // Check that the key was updated ok - let mut tx = ds.transaction(false, false).await.unwrap(); - let val = tx.get("test").await.unwrap().unwrap(); - assert_eq!(val, b"other text"); - tx.cancel().await.unwrap(); - // Create a writeable transaction - let mut tx = ds.transaction(true, false).await.unwrap(); - tx.set("test", "original text").await.unwrap(); - tx.commit().await.unwrap(); - // Check that the key was updated ok - let mut tx = ds.transaction(false, false).await.unwrap(); - let val = tx.get("test").await.unwrap().unwrap(); - assert_eq!(val, b"original text"); - tx.cancel().await.unwrap(); -} - -#[tokio::test] -#[serial] -async fn multiwriter_different_keys() { - // Create a new datastore - let ds = new_ds().await; - // Insert an initial key - let mut tx = ds.transaction(true, false).await.unwrap(); - tx.set("test", "some text").await.unwrap(); - tx.commit().await.unwrap(); - // Create a writeable transaction - let mut tx1 = ds.transaction(true, false).await.unwrap(); - tx1.set("test1", "other text 1").await.unwrap(); - // Create a writeable transaction - let mut tx2 = ds.transaction(true, false).await.unwrap(); - tx2.set("test2", "other text 2").await.unwrap(); - // Create a writeable transaction - let mut tx3 = ds.transaction(true, false).await.unwrap(); - tx3.set("test3", "other text 3").await.unwrap(); - // Cancel both writeable transactions - tx1.commit().await.unwrap(); - tx2.commit().await.unwrap(); - tx3.commit().await.unwrap(); - // Check that the key was updated ok - let mut tx = ds.transaction(false, false).await.unwrap(); - let val = tx.get("test").await.unwrap().unwrap(); - assert_eq!(val, b"some text"); - let val = tx.get("test1").await.unwrap().unwrap(); - assert_eq!(val, b"other text 1"); - let val = tx.get("test2").await.unwrap().unwrap(); - assert_eq!(val, b"other text 2"); - let val = tx.get("test3").await.unwrap().unwrap(); - assert_eq!(val, b"other text 3"); - tx.cancel().await.unwrap(); -} diff --git a/lib/src/kvs/tests/multiwriter_different_keys.rs b/lib/src/kvs/tests/multiwriter_different_keys.rs new file mode 100644 index 00000000..b0430750 --- /dev/null +++ b/lib/src/kvs/tests/multiwriter_different_keys.rs @@ -0,0 +1,34 @@ +#[tokio::test] +#[serial] +async fn multiwriter_different_keys() { + // Create a new datastore + let ds = new_ds().await; + // Insert an initial key + let mut tx = ds.transaction(true, false).await.unwrap(); + tx.set("test", "some text").await.unwrap(); + tx.commit().await.unwrap(); + // Create a writeable transaction + let mut tx1 = ds.transaction(true, false).await.unwrap(); + tx1.set("test1", "other text 1").await.unwrap(); + // Create a writeable transaction + let mut tx2 = ds.transaction(true, false).await.unwrap(); + tx2.set("test2", "other text 2").await.unwrap(); + // Create a writeable transaction + let mut tx3 = ds.transaction(true, false).await.unwrap(); + tx3.set("test3", "other text 3").await.unwrap(); + // Cancel both writeable transactions + tx1.commit().await.unwrap(); + tx2.commit().await.unwrap(); + tx3.commit().await.unwrap(); + // Check that the key was updated ok + let mut tx = ds.transaction(false, false).await.unwrap(); + let val = tx.get("test").await.unwrap().unwrap(); + assert_eq!(val, b"some text"); + let val = tx.get("test1").await.unwrap().unwrap(); + assert_eq!(val, b"other text 1"); + let val = tx.get("test2").await.unwrap().unwrap(); + assert_eq!(val, b"other text 2"); + let val = tx.get("test3").await.unwrap().unwrap(); + assert_eq!(val, b"other text 3"); + tx.cancel().await.unwrap(); +} diff --git a/lib/src/kvs/tests/multiwriter_same_keys_allow.rs b/lib/src/kvs/tests/multiwriter_same_keys_allow.rs new file mode 100644 index 00000000..b262f738 --- /dev/null +++ b/lib/src/kvs/tests/multiwriter_same_keys_allow.rs @@ -0,0 +1,37 @@ +#[tokio::test] +#[serial] +async fn multiwriter_same_keys_allow() { + // Create a new datastore + let ds = new_ds().await; + // Insert an initial key + let mut tx = ds.transaction(true, false).await.unwrap(); + tx.set("test", "some text").await.unwrap(); + tx.commit().await.unwrap(); + // Create a writeable transaction + let mut tx1 = ds.transaction(true, false).await.unwrap(); + tx1.set("test", "other text 1").await.unwrap(); + // Create a writeable transaction + let mut tx2 = ds.transaction(true, false).await.unwrap(); + tx2.set("test", "other text 2").await.unwrap(); + // Create a writeable transaction + let mut tx3 = ds.transaction(true, false).await.unwrap(); + tx3.set("test", "other text 3").await.unwrap(); + // Cancel both writeable transactions + assert!(tx1.commit().await.is_ok()); + assert!(tx2.commit().await.is_ok()); + assert!(tx3.commit().await.is_ok()); + // Check that the key was updated ok + let mut tx = ds.transaction(false, false).await.unwrap(); + let val = tx.get("test").await.unwrap().unwrap(); + assert_eq!(val, b"other text 3"); + tx.cancel().await.unwrap(); + // Create a writeable transaction + let mut tx = ds.transaction(true, false).await.unwrap(); + tx.set("test", "original text").await.unwrap(); + tx.commit().await.unwrap(); + // Check that the key was updated ok + let mut tx = ds.transaction(false, false).await.unwrap(); + let val = tx.get("test").await.unwrap().unwrap(); + assert_eq!(val, b"original text"); + tx.cancel().await.unwrap(); +} diff --git a/lib/src/kvs/tests/multiwriter_same_keys_conflict.rs b/lib/src/kvs/tests/multiwriter_same_keys_conflict.rs new file mode 100644 index 00000000..e197e9df --- /dev/null +++ b/lib/src/kvs/tests/multiwriter_same_keys_conflict.rs @@ -0,0 +1,37 @@ +#[tokio::test] +#[serial] +async fn multiwriter_same_keys_conflict() { + // Create a new datastore + let ds = new_ds().await; + // Insert an initial key + let mut tx = ds.transaction(true, false).await.unwrap(); + tx.set("test", "some text").await.unwrap(); + tx.commit().await.unwrap(); + // Create a writeable transaction + let mut tx1 = ds.transaction(true, false).await.unwrap(); + tx1.set("test", "other text 1").await.unwrap(); + // Create a writeable transaction + let mut tx2 = ds.transaction(true, false).await.unwrap(); + tx2.set("test", "other text 2").await.unwrap(); + // Create a writeable transaction + let mut tx3 = ds.transaction(true, false).await.unwrap(); + tx3.set("test", "other text 3").await.unwrap(); + // Cancel both writeable transactions + assert!(tx1.commit().await.is_ok()); + assert!(tx2.commit().await.is_err()); + assert!(tx3.commit().await.is_err()); + // Check that the key was updated ok + let mut tx = ds.transaction(false, false).await.unwrap(); + let val = tx.get("test").await.unwrap().unwrap(); + assert_eq!(val, b"other text 1"); + tx.cancel().await.unwrap(); + // Create a writeable transaction + let mut tx = ds.transaction(true, false).await.unwrap(); + tx.set("test", "original text").await.unwrap(); + tx.commit().await.unwrap(); + // Check that the key was updated ok + let mut tx = ds.transaction(false, false).await.unwrap(); + let val = tx.get("test").await.unwrap().unwrap(); + assert_eq!(val, b"original text"); + tx.cancel().await.unwrap(); +}