mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 13:39:12 +00:00
test: fuzz use transaction
This commit is contained in:
parent
4652d839ec
commit
d2fa09cd00
5 changed files with 60 additions and 102 deletions
|
@ -71,18 +71,14 @@ impl ListContainer {
|
|||
let (value, maybe_container) = value.convert_value()?;
|
||||
if let Some(prelim) = maybe_container {
|
||||
let idx = txn.next_container_idx();
|
||||
let type_ = value.into_container().unwrap();
|
||||
txn.push(
|
||||
TransactionOp::insert_list_container(
|
||||
self.idx,
|
||||
pos,
|
||||
value.into_container().unwrap(),
|
||||
idx,
|
||||
),
|
||||
TransactionOp::insert_list_container(self.idx, pos, type_, idx),
|
||||
Some(idx),
|
||||
)?;
|
||||
prelim.integrate(txn, idx)?;
|
||||
// TODO: return container
|
||||
Ok(None)
|
||||
Ok(Some(TransactionalContainer::new(idx, type_)))
|
||||
} else {
|
||||
let value = value.into_value().unwrap();
|
||||
txn.push(TransactionOp::insert_list_value(self.idx, pos, value), None)?;
|
||||
|
|
|
@ -79,17 +79,13 @@ impl MapContainer {
|
|||
let (value, maybe_container) = value.convert_value()?;
|
||||
if let Some(prelim) = maybe_container {
|
||||
let idx = txn.next_container_idx();
|
||||
let type_ = value.into_container().unwrap();
|
||||
txn.push(
|
||||
TransactionOp::insert_map_container(
|
||||
self.idx,
|
||||
key,
|
||||
value.into_container().unwrap(),
|
||||
idx,
|
||||
),
|
||||
TransactionOp::insert_map_container(self.idx, key, type_, idx),
|
||||
Some(idx),
|
||||
)?;
|
||||
prelim.integrate(txn, idx)?;
|
||||
Ok(None)
|
||||
Ok(Some(TransactionalContainer::new(idx, type_)))
|
||||
} else {
|
||||
let value = value.into_value().unwrap();
|
||||
txn.push(TransactionOp::insert_map_value(self.idx, key, value), None)?;
|
||||
|
|
|
@ -11,11 +11,12 @@ use tabled::{TableIteratorExt, Tabled};
|
|||
|
||||
use crate::{
|
||||
array_mut_ref,
|
||||
container::ContainerID,
|
||||
container::{registry::ContainerIdx, ContainerID},
|
||||
delta::DeltaItem,
|
||||
event::{Diff, Observer},
|
||||
id::ClientID,
|
||||
log_store::EncodeConfig,
|
||||
transaction::container::TransactionalContainer,
|
||||
ContainerType, List, LoroCore, LoroValue, Map, Text, Transact,
|
||||
};
|
||||
|
||||
|
@ -261,11 +262,22 @@ trait Actionable {
|
|||
}
|
||||
|
||||
impl Actor {
|
||||
fn add_new_container(&mut self, new: ContainerID) {
|
||||
match new.container_type() {
|
||||
ContainerType::Text => self.text_containers.push(self.loro.get_text(new)),
|
||||
ContainerType::Map => self.map_containers.push(self.loro.get_map(new)),
|
||||
ContainerType::List => self.list_containers.push(self.loro.get_list(new)),
|
||||
fn add_new_container(&mut self, container: TransactionalContainer) {
|
||||
let new = container.idx;
|
||||
let type_ = container.type_;
|
||||
let store = self.loro.log_store.try_read().unwrap();
|
||||
let client_id = store.this_client_id;
|
||||
let instance = store.get_container_by_idx(&new).unwrap();
|
||||
match type_ {
|
||||
ContainerType::Text => self
|
||||
.text_containers
|
||||
.push(Text::from_instance(instance, client_id)),
|
||||
ContainerType::Map => self
|
||||
.map_containers
|
||||
.push(Map::from_instance(instance, client_id)),
|
||||
ContainerType::List => self
|
||||
.list_containers
|
||||
.push(List::from_instance(instance, client_id)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -470,26 +482,27 @@ impl Actionable for Vec<Actor> {
|
|||
actor.map_containers.push(map);
|
||||
&mut actor.map_containers[0]
|
||||
};
|
||||
let mut txn = actor.loro.transact();
|
||||
match value {
|
||||
let txn = actor.loro.transact();
|
||||
let container = match value {
|
||||
FuzzValue::Null => {
|
||||
container.delete(&mut txn, &key.to_string()).unwrap();
|
||||
container.delete(&txn, &key.to_string()).unwrap();
|
||||
None
|
||||
}
|
||||
FuzzValue::I32(i) => {
|
||||
container.insert(&mut txn, &key.to_string(), *i).unwrap();
|
||||
container.insert(&txn, &key.to_string(), *i).unwrap();
|
||||
None
|
||||
}
|
||||
FuzzValue::Container(c) => {
|
||||
let new = container
|
||||
.insert(&mut txn, &key.to_string(), *c)
|
||||
FuzzValue::Container(c) => Some(
|
||||
container
|
||||
.insert(&txn, &key.to_string(), *c)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
// actor.add_new_container(new);
|
||||
// TODO convert to idx
|
||||
// FIXME
|
||||
actor.add_new_container(ContainerID::new_root("name", *c))
|
||||
}
|
||||
}
|
||||
.unwrap(),
|
||||
),
|
||||
};
|
||||
drop(txn);
|
||||
if let Some(container) = container {
|
||||
actor.add_new_container(container);
|
||||
}
|
||||
}
|
||||
Action::List {
|
||||
site,
|
||||
|
@ -507,25 +520,24 @@ impl Actionable for Vec<Actor> {
|
|||
#[allow(clippy::unnecessary_unwrap)]
|
||||
container.unwrap()
|
||||
};
|
||||
let mut txn = actor.loro.transact();
|
||||
match value {
|
||||
let txn = actor.loro.transact();
|
||||
let container = match value {
|
||||
FuzzValue::Null => {
|
||||
container.delete(&mut txn, *key as usize, 1).unwrap();
|
||||
container.delete(&txn, *key as usize, 1).unwrap();
|
||||
None
|
||||
}
|
||||
FuzzValue::I32(i) => {
|
||||
container.insert(&mut txn, *key as usize, *i).unwrap();
|
||||
container.insert(&txn, *key as usize, *i).unwrap();
|
||||
None
|
||||
}
|
||||
FuzzValue::Container(c) => {
|
||||
let new = container
|
||||
.insert(&mut txn, *key as usize, *c)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
// TODO convert to idx
|
||||
// FIXME
|
||||
actor.add_new_container(ContainerID::new_root("name", *c))
|
||||
Some(container.insert(&txn, *key as usize, *c).unwrap().unwrap())
|
||||
}
|
||||
}
|
||||
};
|
||||
drop(txn);
|
||||
if let Some(container) = container {
|
||||
actor.add_new_container(container);
|
||||
}
|
||||
}
|
||||
Action::Text {
|
||||
site,
|
||||
|
@ -543,14 +555,14 @@ impl Actionable for Vec<Actor> {
|
|||
actor.text_containers.push(text);
|
||||
&mut actor.text_containers[0]
|
||||
};
|
||||
let mut txn = actor.loro.transact();
|
||||
let txn = actor.loro.transact();
|
||||
if *is_del {
|
||||
container
|
||||
.delete(&mut txn, *pos as usize, *value as usize)
|
||||
.delete(&txn, *pos as usize, *value as usize)
|
||||
.unwrap();
|
||||
} else {
|
||||
container
|
||||
.insert(&mut txn, *pos as usize, &(format!("[{}]", value)))
|
||||
.insert(&txn, *pos as usize, &(format!("[{}]", value)))
|
||||
.unwrap();
|
||||
}
|
||||
drop(txn);
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
use std::{
|
||||
collections::BTreeMap,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::{Arc, Mutex, RwLock, Weak},
|
||||
};
|
||||
|
||||
use fxhash::{FxHashMap, FxHashSet};
|
||||
use rle::RleVec;
|
||||
|
||||
use crate::{
|
||||
container::{registry::ContainerIdx, Container, ContainerID},
|
||||
delta::{DeltaItem, SeqDelta},
|
||||
event::{Diff, RawEvent},
|
||||
hierarchy::Hierarchy,
|
||||
id::{ClientID, ID},
|
||||
id::ClientID,
|
||||
transaction::op::Value,
|
||||
ContainerType, LogStore, LoroCore, LoroError, LoroValue, Map,
|
||||
};
|
||||
|
|
|
@ -1,56 +1,13 @@
|
|||
use crate::{container::registry::ContainerIdx, ContainerType, LoroError, Prelim};
|
||||
use crate::{container::registry::ContainerIdx, ContainerType};
|
||||
|
||||
use super::{op::TransactionOp, Transaction};
|
||||
|
||||
pub enum TransactionalContainer {
|
||||
List(TransactionalList),
|
||||
pub struct TransactionalContainer {
|
||||
pub idx: ContainerIdx,
|
||||
pub type_: ContainerType,
|
||||
}
|
||||
|
||||
impl TransactionalContainer {
|
||||
pub fn idx(&self) -> ContainerIdx {
|
||||
match &self {
|
||||
Self::List(list) => list.idx(),
|
||||
}
|
||||
pub fn new(idx: ContainerIdx, type_: ContainerType) -> Self {
|
||||
Self { idx, type_ }
|
||||
}
|
||||
}
|
||||
|
||||
impl TransactionalContainer {
|
||||
pub(super) fn new(type_: ContainerType, idx: ContainerIdx) -> Self {
|
||||
match type_ {
|
||||
ContainerType::List => Self::List(TransactionalList(idx)),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TransactionalList(ContainerIdx);
|
||||
|
||||
impl TransactionalList {
|
||||
pub fn idx(&self) -> ContainerIdx {
|
||||
self.0
|
||||
}
|
||||
|
||||
// pub fn insert<P: Prelim>(
|
||||
// &self,
|
||||
// txn: &mut Transaction,
|
||||
// pos: usize,
|
||||
// value: P,
|
||||
// ) -> Result<Option<TransactionalContainer>, LoroError> {
|
||||
// let (value, maybe_container) = value.convert_value()?;
|
||||
// if let Some(prelim) = maybe_container {
|
||||
// let container = txn
|
||||
// .push(TransactionOp::insert_list_container(
|
||||
// self.0,
|
||||
// pos,
|
||||
// value.into_container().unwrap(),
|
||||
// ))?
|
||||
// .unwrap();
|
||||
// prelim.integrate(txn, container.idx());
|
||||
// Ok(Some(container))
|
||||
// } else {
|
||||
// let value = value.into_value().unwrap();
|
||||
// txn.push(TransactionOp::insert_list_value(self.0, pos, value))?;
|
||||
// Ok(None)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue