From c7efd24c2e18315aa9760bc1966c876fa4d18dd8 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 12 Aug 2023 09:54:57 +0800 Subject: [PATCH] chore: add device id --- Cargo.lock | 1 + appflowy-integrate/src/collab_builder.rs | 4 ++- collab-database/tests/database_test/helper.rs | 8 ++++-- collab-database/tests/user_test/helper.rs | 5 ++-- .../tests/blocks/block_test_core.rs | 4 ++- collab-document/tests/util.rs | 5 +++- collab-folder/tests/folder_test/util.rs | 3 ++ collab-plugins/Cargo.toml | 1 + .../src/cloud_storage/postgres/plugin.rs | 14 ++++++++-- .../src/cloud_storage/remote_collab.rs | 11 ++++++-- collab-plugins/src/snapshot/plugin.rs | 4 +-- collab-plugins/tests/disk/script.rs | 28 ++++++++++++++++--- collab-plugins/tests/util/client.rs | 2 +- collab-sync/src/server/broadcast.rs | 9 +----- collab/src/core/collab.rs | 14 ++++++---- collab/src/core/origin.rs | 17 ++++++----- collab/tests/collab_test/helper.rs | 2 ++ collab/tests/collab_test/insert_test.rs | 20 ++++++------- collab/tests/collab_test/restore_test.rs | 22 +++++++++++++-- 19 files changed, 121 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 438031260..5681ad6eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,6 +806,7 @@ dependencies = [ "tokio-util", "tracing", "tracing-subscriber", + "uuid", "y-sync", "yrs", ] diff --git a/appflowy-integrate/src/collab_builder.rs b/appflowy-integrate/src/collab_builder.rs index 3449d736e..9ddfc318f 100644 --- a/appflowy-integrate/src/collab_builder.rs +++ b/appflowy-integrate/src/collab_builder.rs @@ -138,6 +138,7 @@ impl AppFlowyCollabBuilder { collab_db.clone(), config.clone(), )) + .with_device_id(self.device_id.lock().clone()) .build()?, ); @@ -197,7 +198,8 @@ impl AppFlowyCollabBuilder { if let Some(snapshot_persistence) = &self.snapshot_persistence { if config.enable_snapshot { - let collab_object = CollabObject::new(uid, object_id.to_string(), object_type); + let collab_object = CollabObject::new(uid, object_id.to_string(), object_type) + .with_device_id(self.device_id.lock().clone()); let snapshot_plugin = CollabSnapshotPlugin::new( uid, collab_object, diff --git a/collab-database/tests/database_test/helper.rs b/collab-database/tests/database_test/helper.rs index bd14a9340..322970f5e 100644 --- a/collab-database/tests/database_test/helper.rs +++ b/collab-database/tests/database_test/helper.rs @@ -12,8 +12,8 @@ use collab_database::user::DatabaseCollabService; use collab_database::views::{CreateDatabaseParams, DatabaseLayout, LayoutSetting, LayoutSettings}; use collab_persistence::kv::rocks_kv::RocksCollabDB; use collab_plugins::cloud_storage::CollabType; - use collab_plugins::local_storage::CollabPersistenceConfig; + use tempfile::TempDir; pub use crate::helper::*; @@ -48,7 +48,10 @@ pub fn create_database(uid: i64, database_id: &str) -> DatabaseTest { let tempdir = TempDir::new().unwrap(); let path = tempdir.into_path(); let collab_db = Arc::new(RocksCollabDB::open(path).unwrap()); - let collab = CollabBuilder::new(uid, database_id).build().unwrap(); + let collab = CollabBuilder::new(uid, database_id) + .with_device_id("1") + .build() + .unwrap(); collab.lock().initialize(); let collab_builder = Arc::new(TestUserDatabaseCollabBuilderImpl()); let block = Block::new(uid, Arc::downgrade(&collab_db), collab_builder.clone()); @@ -178,6 +181,7 @@ impl DatabaseTestBuilder { let path = tempdir.into_path(); let collab_db = Arc::new(RocksCollabDB::open(path).unwrap()); let collab = CollabBuilder::new(self.uid, &self.database_id) + .with_device_id("1") .build() .unwrap(); collab.lock().initialize(); diff --git a/collab-database/tests/user_test/helper.rs b/collab-database/tests/user_test/helper.rs index 7939495e4..b622ecef2 100644 --- a/collab-database/tests/user_test/helper.rs +++ b/collab-database/tests/user_test/helper.rs @@ -17,11 +17,11 @@ use collab_database::user::{ use collab_database::views::{CreateDatabaseParams, DatabaseLayout}; use collab_persistence::kv::rocks_kv::RocksCollabDB; use collab_plugins::cloud_storage::CollabType; +use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; +use collab_plugins::local_storage::CollabPersistenceConfig; use parking_lot::Mutex; use tokio::sync::mpsc::{channel, Receiver}; -use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; -use collab_plugins::local_storage::CollabPersistenceConfig; use rand::Rng; use tempfile::TempDir; @@ -76,6 +76,7 @@ impl DatabaseCollabService for TestUserDatabaseCollabBuilderImpl { config: &CollabPersistenceConfig, ) -> Arc { let collab = CollabBuilder::new(uid, object_id) + .with_device_id("1") .with_raw_data(collab_raw_data) .with_plugin(RocksdbDiskPlugin::new_with_config( uid, diff --git a/collab-document/tests/blocks/block_test_core.rs b/collab-document/tests/blocks/block_test_core.rs index e05f4f189..6ac885b54 100644 --- a/collab-document/tests/blocks/block_test_core.rs +++ b/collab-document/tests/blocks/block_test_core.rs @@ -8,10 +8,11 @@ use collab_document::blocks::{ }; use collab_document::document::Document; use collab_persistence::kv::rocks_kv::RocksCollabDB; -use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; use nanoid::nanoid; use serde_json::json; +use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; + use crate::util::document_storage; pub const TEXT_BLOCK_TYPE: &str = "paragraph"; @@ -29,6 +30,7 @@ impl BlockTestCore { let disk_plugin = RocksdbDiskPlugin::new(1, Arc::downgrade(&db)); let collab = CollabBuilder::new(1, doc_id) .with_plugin(disk_plugin) + .with_device_id("1") .build() .unwrap(); collab.lock().initialize(); diff --git a/collab-document/tests/util.rs b/collab-document/tests/util.rs index 177197e9a..3bc8a2a57 100644 --- a/collab-document/tests/util.rs +++ b/collab-document/tests/util.rs @@ -12,9 +12,10 @@ use collab_document::blocks::{Block, BlockAction, DocumentData, DocumentMeta}; use collab_document::document::Document; use collab_document::error::DocumentError; use collab_persistence::kv::rocks_kv::RocksCollabDB; -use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; use nanoid::nanoid; use serde_json::{json, Value}; + +use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; use tempfile::TempDir; use tracing_subscriber::{fmt::Subscriber, util::SubscriberInitExt, EnvFilter}; use zip::ZipArchive; @@ -34,6 +35,7 @@ impl DocumentTest { let disk_plugin = RocksdbDiskPlugin::new(uid, Arc::downgrade(&db)); let collab = CollabBuilder::new(1, doc_id) .with_plugin(disk_plugin) + .with_device_id("1") .build() .unwrap(); collab.lock().initialize(); @@ -98,6 +100,7 @@ pub fn open_document_with_db(uid: i64, doc_id: &str, db: Arc) -> let disk_plugin = RocksdbDiskPlugin::new(uid, Arc::downgrade(&db)); let collab = CollabBuilder::new(uid, doc_id) .with_plugin(disk_plugin) + .with_device_id("1") .build() .unwrap(); collab.lock().initialize(); diff --git a/collab-folder/tests/folder_test/util.rs b/collab-folder/tests/folder_test/util.rs index 85bc16812..41e423b6b 100644 --- a/collab-folder/tests/folder_test/util.rs +++ b/collab-folder/tests/folder_test/util.rs @@ -8,6 +8,7 @@ use std::sync::{Arc, Once}; use collab::preclude::CollabBuilder; use collab_folder::core::*; use collab_persistence::kv::rocks_kv::RocksCollabDB; + use collab_plugins::local_storage::rocksdb::RocksdbDiskPlugin; use nanoid::nanoid; use tempfile::TempDir; @@ -51,6 +52,7 @@ pub fn create_folder_with_data(id: &str, folder_data: Option) -> Fol let collab = CollabBuilder::new(1, id) .with_plugin(disk_plugin) + .with_device_id("1") .build() .unwrap(); collab.lock().initialize(); @@ -77,6 +79,7 @@ pub fn open_folder_with_db(uid: i64, object_id: &str, db_path: PathBuf) -> Folde let cleaner: Cleaner = Cleaner::new(db_path); let collab = CollabBuilder::new(1, object_id) .with_plugin(disk_plugin) + .with_device_id("1") .build() .unwrap(); collab.lock().initialize(); diff --git a/collab-plugins/Cargo.toml b/collab-plugins/Cargo.toml index 32c4d0b09..5f6752aba 100644 --- a/collab-plugins/Cargo.toml +++ b/collab-plugins/Cargo.toml @@ -29,6 +29,7 @@ serde_json = "1.0" rand = { version = "0.8" } similar = { version = "2.2.1" } tokio-stream = { version = "0.1.14", features = ["sync"] } +uuid = { version = "1.3.3", features = ["v4"] } [dev-dependencies] collab-plugins = { path = ".", features = ["rocksdb_plugin", "disk_sled", "aws_storage_plugin"] } diff --git a/collab-plugins/src/cloud_storage/postgres/plugin.rs b/collab-plugins/src/cloud_storage/postgres/plugin.rs index e46c949c2..326b76564 100644 --- a/collab-plugins/src/cloud_storage/postgres/plugin.rs +++ b/collab-plugins/src/cloud_storage/postgres/plugin.rs @@ -162,7 +162,12 @@ fn create_snapshot_if_need( tracing::trace!("Create remote snapshot for {}", object.object_id); let cloned_object = object.clone(); if let Ok(Ok(doc_state)) = tokio::task::spawn_blocking(move || { - let local = Collab::new(uid, object.object_id.clone(), vec![]); + let local = Collab::new( + uid, + object.object_id.clone(), + object.get_device_id(), + vec![], + ); let mut txn = local.origin_transact_mut(); let _ = local_collab_storage .read_txn() @@ -171,7 +176,12 @@ fn create_snapshot_if_need( // Only sync with the remote if the remote update is not empty if !remote_update.is_empty() { - let remote = Collab::new(uid, object.object_id.clone(), vec![]); + let remote = Collab::new( + uid, + object.object_id.clone(), + object.get_device_id(), + vec![], + ); let mut txn = local.origin_transact_mut(); txn.try_apply_update(Update::decode_v1(&remote_update)?)?; drop(txn); diff --git a/collab-plugins/src/cloud_storage/remote_collab.rs b/collab-plugins/src/cloud_storage/remote_collab.rs index 76b9c17c7..3edb4b799 100644 --- a/collab-plugins/src/cloud_storage/remote_collab.rs +++ b/collab-plugins/src/cloud_storage/remote_collab.rs @@ -89,7 +89,6 @@ impl RemoteCollab { if let Ok(mut txn) = collab.try_transaction_mut() { match Update::decode_v1(&update) { Ok(update) => { - tracing::trace!("apply remote update: {:?}", update); if let Err(e) = txn.try_apply_update(update) { tracing::error!("apply remote update failed: {:?}", e); } @@ -656,8 +655,14 @@ impl CollabObject { self.meta.get("workspace_id").cloned() } - pub fn get_device_id(&self) -> Option { - self.meta.get("device_id").cloned() + pub fn get_device_id(&self) -> String { + match self.meta.get("device_id").cloned() { + None => { + tracing::error!("Unexpected empty device id"); + uuid::Uuid::new_v4().to_string() + }, + Some(device_id) => device_id, + } } } diff --git a/collab-plugins/src/snapshot/plugin.rs b/collab-plugins/src/snapshot/plugin.rs index 030a28f81..9aecb9a9d 100644 --- a/collab-plugins/src/snapshot/plugin.rs +++ b/collab-plugins/src/snapshot/plugin.rs @@ -110,7 +110,7 @@ impl CollabPlugin for CollabSnapshotPlugin { weak_collab_db.upgrade(), weak_snapshot_persistence.upgrade(), ) { - let snapshot_collab = Collab::new(uid, object.object_id.clone(), vec![]); + let snapshot_collab = Collab::new(uid, object.object_id.clone(), "1", vec![]); let mut txn = snapshot_collab.origin_transact_mut(); if let Err(e) = collab_db .read_txn() @@ -208,7 +208,7 @@ pub fn try_decode_snapshot( match { let mut wrapper = AssertUnwindSafe(&mut decoded_str); panic::catch_unwind(move || { - let collab = Collab::new(uid, object_id, vec![]); + let collab = Collab::new(uid, object_id, "1", vec![]); if let Ok(update) = Update::decode_v1(data) { let mut txn = collab.origin_transact_mut(); txn.apply_update(update); diff --git a/collab-plugins/tests/disk/script.rs b/collab-plugins/tests/disk/script.rs index c20fc2539..835701d59 100644 --- a/collab-plugins/tests/disk/script.rs +++ b/collab-plugins/tests/disk/script.rs @@ -125,7 +125,12 @@ impl CollabPersistenceTest { } pub async fn create_collab(&mut self, doc_id: String) { - let collab = Arc::new(CollabBuilder::new(1, &doc_id).build().unwrap()); + let collab = Arc::new( + CollabBuilder::new(1, &doc_id) + .with_device_id("1") + .build() + .unwrap(), + ); collab.lock().add_plugin(self.disk_plugin.clone()); let object_id = collab.lock().object_id.clone(); collab.lock().add_plugin(self.make_snapshot_plugin( @@ -160,7 +165,12 @@ impl CollabPersistenceTest { } pub async fn assert_collab(&mut self, id: &str, expected: JsonValue) { - let collab = Arc::new(CollabBuilder::new(1, id).build().unwrap()); + let collab = Arc::new( + CollabBuilder::new(1, id) + .with_device_id("1") + .build() + .unwrap(), + ); collab.lock().add_plugin(self.disk_plugin.clone()); collab.lock().add_plugin(self.make_snapshot_plugin( self.uid, @@ -201,6 +211,7 @@ impl CollabPersistenceTest { Script::CreateDocumentWithDiskPlugin { id, plugin } => { let collab = Arc::new( CollabBuilder::new(1, &id) + .with_device_id("1") .with_plugin(plugin.clone()) .build() .unwrap(), @@ -226,6 +237,7 @@ impl CollabPersistenceTest { }, Script::OpenDocumentWithDiskPlugin { id } => { let collab = CollabBuilder::new(1, &id) + .with_device_id("1") .with_plugin(self.disk_plugin.clone()) .build() .unwrap(); @@ -286,7 +298,10 @@ impl CollabPersistenceTest { self.collab_by_id.get(&id).unwrap().clone(), ); let snapshots = snapshot_plugin.get_snapshots(&id); - let collab = CollabBuilder::new(1, &id).build().unwrap(); + let collab = CollabBuilder::new(1, &id) + .with_device_id("1") + .build() + .unwrap(); collab.lock().with_origin_transact_mut(|txn| { txn.apply_update(Update::decode_v1(&snapshots[index as usize].data).unwrap()); }); @@ -295,7 +310,12 @@ impl CollabPersistenceTest { assert_json_diff::assert_json_eq!(json, expected); }, Script::AssertDocument { id, expected } => { - let collab = Arc::new(CollabBuilder::new(1, &id).build().unwrap()); + let collab = Arc::new( + CollabBuilder::new(1, &id) + .with_device_id("1") + .build() + .unwrap(), + ); collab.lock().add_plugin(self.disk_plugin.clone()); collab.lock().add_plugin(self.make_snapshot_plugin( self.uid, diff --git a/collab-plugins/tests/util/client.rs b/collab-plugins/tests/util/client.rs index 1fbc1d426..289900094 100644 --- a/collab-plugins/tests/util/client.rs +++ b/collab-plugins/tests/util/client.rs @@ -228,7 +228,7 @@ impl Rng { fn origin_from_tcp_stream(stream: &TcpStream) -> CollabOrigin { let address = stream.local_addr().unwrap(); - let origin = CollabClient::new(address.port() as i64, &address.to_string()); + let origin = CollabClient::new(address.port() as i64, address.to_string()); CollabOrigin::Client(origin) } diff --git a/collab-sync/src/server/broadcast.rs b/collab-sync/src/server/broadcast.rs index 1c5abf68e..2eaa8bd67 100644 --- a/collab-sync/src/server/broadcast.rs +++ b/collab-sync/src/server/broadcast.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use collab::core::collab::MutexCollab; -use collab::core::origin::{CollabClient, CollabOrigin}; +use collab::core::origin::CollabOrigin; use futures_util::{SinkExt, StreamExt}; use lib0::encoding::Write; use tokio::select; @@ -276,10 +276,3 @@ fn gen_awareness_update_message( let update = awareness.update_with_clients(changed)?; Ok(update) } - -pub fn server_origin() -> CollabClient { - CollabClient { - uid: 0, - device_id: "".to_string(), - } -} diff --git a/collab/src/core/collab.rs b/collab/src/core/collab.rs index 5322edf53..204333e4d 100644 --- a/collab/src/core/collab.rs +++ b/collab/src/core/collab.rs @@ -74,8 +74,13 @@ pub struct Collab { } impl Collab { - pub fn new>(uid: i64, object_id: T, plugins: Vec>) -> Collab { - let origin = CollabClient::new(uid, ""); + pub fn new>( + uid: i64, + object_id: T, + device_id: impl ToString, + plugins: Vec>, + ) -> Collab { + let origin = CollabClient::new(uid, device_id); Self::new_with_client(CollabOrigin::Client(origin), object_id, plugins) } @@ -639,10 +644,7 @@ impl CollabBuilder { } pub fn build(self) -> Result { - let origin = CollabOrigin::Client(CollabClient { - uid: self.uid, - device_id: self.device_id, - }); + let origin = CollabOrigin::Client(CollabClient::new(self.uid, self.device_id)); MutexCollab::new_with_raw_data(origin, &self.object_id, self.updates, self.plugins) } } diff --git a/collab/src/core/origin.rs b/collab/src/core/origin.rs index aa5eef688..6af1eb307 100644 --- a/collab/src/core/origin.rs +++ b/collab/src/core/origin.rs @@ -1,5 +1,6 @@ -use serde::{Deserialize, Serialize}; use std::fmt::{Display, Formatter}; + +use serde::{Deserialize, Serialize}; use yrs::{Origin, TransactionMut}; #[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)] @@ -52,7 +53,7 @@ impl From<&Origin> for CollabOrigin { #[derive(Serialize, Deserialize, Eq, PartialEq, Hash, Debug, Clone)] pub struct CollabClient { pub uid: i64, - pub device_id: String, + device_id: String, } impl Display for CollabClient { @@ -65,11 +66,13 @@ impl Display for CollabClient { } impl CollabClient { - pub fn new(uid: i64, device_id: &str) -> Self { - Self { - uid, - device_id: device_id.to_string(), - } + pub fn new(uid: i64, device_id: impl ToString) -> Self { + let device_id = device_id.to_string(); + debug_assert!( + !device_id.is_empty(), + "device_id should not be empty string" + ); + Self { uid, device_id } } } diff --git a/collab/tests/collab_test/helper.rs b/collab/tests/collab_test/helper.rs index 927524bb8..3c7d18200 100644 --- a/collab/tests/collab_test/helper.rs +++ b/collab/tests/collab_test/helper.rs @@ -30,6 +30,7 @@ pub fn make_collab_pair() -> (MutexCollab, MutexCollab, CollabStateCachePlugin) let update_cache = CollabStateCachePlugin::new(); let local_collab = CollabBuilder::new(1, "1") .with_plugin(update_cache.clone()) + .with_device_id("1") .build() .unwrap(); local_collab.lock().initialize(); @@ -40,6 +41,7 @@ pub fn make_collab_pair() -> (MutexCollab, MutexCollab, CollabStateCachePlugin) .insert_json_with_path(vec![], "document", test_document()); let updates = update_cache.get_updates(); let remote_collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_raw_data(updates.unwrap()) .build() .unwrap(); diff --git a/collab/tests/collab_test/insert_test.rs b/collab/tests/collab_test/insert_test.rs index 35ce1e0df..fd248156e 100644 --- a/collab/tests/collab_test/insert_test.rs +++ b/collab/tests/collab_test/insert_test.rs @@ -11,7 +11,7 @@ use crate::helper::{setup_log, Person, Position}; #[tokio::test] async fn insert_text() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); let _sub = collab.observer_data(|txn, event| { event.target().iter(txn).for_each(|(a, b)| { println!("{}: {}", a, b); @@ -26,7 +26,7 @@ async fn insert_text() { #[tokio::test] async fn insert_json_attrs() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); let object = Person { name: "nathan".to_string(), position: Position { @@ -51,7 +51,7 @@ async fn insert_json_attrs() { #[tokio::test] async fn observer_attr_mut() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); let object = Person { name: "nathan".to_string(), position: Position { @@ -78,7 +78,7 @@ async fn observer_attr_mut() { #[tokio::test] async fn remove_value() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); let object = Person { name: "nathan".to_string(), position: Position { @@ -101,7 +101,7 @@ async fn remove_value() { #[tokio::test] async fn retry_write_txn_success_test() { setup_log(); - let collab = Arc::new(Collab::new(1, "1", vec![])); + let collab = Arc::new(Collab::new(1, "1", "1", vec![])); let doc = collab.get_doc().clone(); let txn = TransactionRetry::new(&doc).get_write_txn_with(CollabOrigin::Empty); @@ -124,7 +124,7 @@ async fn retry_write_txn_success_test() { #[should_panic] async fn retry_write_txn_fail_test() { setup_log(); - let collab = Arc::new(Collab::new(1, "1", vec![])); + let collab = Arc::new(Collab::new(1, "1", "1", vec![])); let doc = collab.get_doc().clone(); let _txn = TransactionRetry::new(&doc).get_write_txn_with(CollabOrigin::Empty); @@ -143,7 +143,7 @@ async fn retry_write_txn_fail_test() { #[tokio::test] async fn undo_single_insert_text() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); collab.enable_undo_redo(); collab.insert("text", "hello world"); @@ -164,7 +164,7 @@ async fn undo_single_insert_text() { #[tokio::test] async fn redo_single_insert_text() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); collab.enable_undo_redo(); collab.insert("text", "hello world"); @@ -187,14 +187,14 @@ async fn redo_single_insert_text() { #[tokio::test] #[should_panic] async fn undo_manager_not_enable_test() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); collab.insert("text", "hello world"); collab.undo().unwrap(); } #[tokio::test] async fn undo_second_insert_text() { - let mut collab = Collab::new(1, "1", vec![]); + let mut collab = Collab::new(1, "1", "1", vec![]); collab.insert("1", "a"); collab.enable_undo_redo(); diff --git a/collab/tests/collab_test/restore_test.rs b/collab/tests/collab_test/restore_test.rs index 2702ebaee..4f7b90e8a 100644 --- a/collab/tests/collab_test/restore_test.rs +++ b/collab/tests/collab_test/restore_test.rs @@ -14,6 +14,7 @@ use crate::helper::{setup_log, CollabStateCachePlugin}; async fn restore_from_update() { let update_cache = CollabStateCachePlugin::new(); let collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_plugin(update_cache.clone()) .build() .unwrap(); @@ -22,6 +23,7 @@ async fn restore_from_update() { let updates = update_cache.get_updates().unwrap(); let restored_collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_raw_data(updates) .build() .unwrap(); @@ -34,6 +36,7 @@ async fn restore_from_update() { async fn restore_from_multiple_update() { let update_cache = CollabStateCachePlugin::new(); let collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_plugin(update_cache.clone()) .build() .unwrap(); @@ -47,6 +50,7 @@ async fn restore_from_multiple_update() { let updates = update_cache.get_updates().unwrap(); let restored_collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_raw_data(updates) .build() .unwrap(); @@ -57,6 +61,7 @@ async fn restore_from_multiple_update() { async fn apply_same_update_multiple_time() { let update_cache = CollabStateCachePlugin::new(); let collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_plugin(update_cache.clone()) .build() .unwrap(); @@ -65,6 +70,7 @@ async fn apply_same_update_multiple_time() { let updates = update_cache.get_updates().unwrap(); let restored_collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_raw_data(updates) .build() .unwrap(); @@ -84,6 +90,7 @@ async fn apply_same_update_multiple_time() { async fn apply_unordered_updates() { let update_cache = CollabStateCachePlugin::new(); let collab = CollabBuilder::new(1, "1") + .with_device_id("1") .with_plugin(update_cache.clone()) .build() .unwrap(); @@ -99,7 +106,10 @@ async fn apply_unordered_updates() { let mut updates = update_cache.get_updates().unwrap(); updates.reverse(); - let restored_collab = CollabBuilder::new(1, "1").build().unwrap(); + let restored_collab = CollabBuilder::new(1, "1") + .with_device_id("1") + .build() + .unwrap(); restored_collab.lock().initialize(); restored_collab.lock().with_origin_transact_mut(|txn| { //Out of order updates from the same peer will be stashed internally and their @@ -120,9 +130,15 @@ async fn apply_unordered_updates() { #[tokio::test] async fn root_change_test() { setup_log(); - let collab_1 = CollabBuilder::new(1, "1").build().unwrap(); + let collab_1 = CollabBuilder::new(1, "1") + .with_device_id("1") + .build() + .unwrap(); collab_1.lock().initialize(); - let collab_2 = CollabBuilder::new(1, "1").build().unwrap(); + let collab_2 = CollabBuilder::new(1, "1") + .with_device_id("1") + .build() + .unwrap(); collab_2.lock().initialize(); {