mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
add folder sync test
This commit is contained in:
@ -47,6 +47,7 @@ pin-project = "1.0.0"
|
||||
[dev-dependencies]
|
||||
flowy-test = { path = "../flowy-test" }
|
||||
flowy-document = { path = "../flowy-document", features = ["flowy_unit_test"]}
|
||||
|
||||
color-eyre = { version = "0.5", default-features = false }
|
||||
criterion = "0.3"
|
||||
rand = "0.7.3"
|
||||
|
@ -1,23 +0,0 @@
|
||||
use crate::{controller::DocumentController, errors::FlowyError};
|
||||
use flowy_database::ConnectionPool;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait DocumentUser: Send + Sync {
|
||||
fn user_dir(&self) -> Result<String, FlowyError>;
|
||||
fn user_id(&self) -> Result<String, FlowyError>;
|
||||
fn token(&self) -> Result<String, FlowyError>;
|
||||
fn db_pool(&self) -> Result<Arc<ConnectionPool>, FlowyError>;
|
||||
}
|
||||
|
||||
pub struct DocumentContext {
|
||||
pub controller: Arc<DocumentController>,
|
||||
pub user: Arc<dyn DocumentUser>,
|
||||
}
|
||||
|
||||
impl DocumentContext {
|
||||
pub fn init(&self) -> Result<(), FlowyError> {
|
||||
let _ = self.controller.init()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
use crate::{context::DocumentUser, core::ClientDocumentEditor, errors::FlowyError, DocumentCloudService};
|
||||
use crate::{core::ClientDocumentEditor, errors::FlowyError, DocumentCloudService};
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use dashmap::DashMap;
|
||||
@ -14,13 +14,21 @@ use lib_infra::future::FutureResult;
|
||||
use lib_ws::WSConnectState;
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
pub trait DocumentUser: Send + Sync {
|
||||
fn user_dir(&self) -> Result<String, FlowyError>;
|
||||
fn user_id(&self) -> Result<String, FlowyError>;
|
||||
fn token(&self) -> Result<String, FlowyError>;
|
||||
fn db_pool(&self) -> Result<Arc<ConnectionPool>, FlowyError>;
|
||||
}
|
||||
|
||||
|
||||
#[async_trait]
|
||||
pub(crate) trait DocumentWSReceiver: Send + Sync {
|
||||
async fn receive_ws_data(&self, data: ServerRevisionWSData) -> Result<(), FlowyError>;
|
||||
fn connect_state_changed(&self, state: WSConnectState);
|
||||
}
|
||||
type WebSocketDataReceivers = Arc<DashMap<String, Arc<dyn DocumentWSReceiver>>>;
|
||||
pub struct DocumentController {
|
||||
pub struct FlowyDocumentManager {
|
||||
cloud_service: Arc<dyn DocumentCloudService>,
|
||||
ws_receivers: WebSocketDataReceivers,
|
||||
web_socket: Arc<dyn RevisionWebSocket>,
|
||||
@ -28,7 +36,7 @@ pub struct DocumentController {
|
||||
user: Arc<dyn DocumentUser>,
|
||||
}
|
||||
|
||||
impl DocumentController {
|
||||
impl FlowyDocumentManager {
|
||||
pub fn new(
|
||||
cloud_service: Arc<dyn DocumentCloudService>,
|
||||
user: Arc<dyn DocumentUser>,
|
||||
@ -45,7 +53,7 @@ impl DocumentController {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn init(&self) -> FlowyResult<()> {
|
||||
pub fn init(&self) -> FlowyResult<()> {
|
||||
let notify = self.web_socket.subscribe_state_changed();
|
||||
listen_ws_state_changed(notify, self.ws_receivers.clone());
|
||||
|
||||
@ -119,7 +127,7 @@ impl DocumentController {
|
||||
}
|
||||
}
|
||||
|
||||
impl DocumentController {
|
||||
impl FlowyDocumentManager {
|
||||
async fn get_editor(&self, doc_id: &str) -> FlowyResult<Arc<ClientDocumentEditor>> {
|
||||
match self.open_cache.get(doc_id) {
|
||||
None => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
context::DocumentUser,
|
||||
core::{make_document_ws_manager, EditorCommand, EditorCommandQueue, EditorCommandSender},
|
||||
errors::FlowyError,
|
||||
DocumentUser,
|
||||
DocumentWSReceiver,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
|
@ -6,4 +6,4 @@ pub use editor::*;
|
||||
pub(crate) use queue::*;
|
||||
pub(crate) use web_socket::*;
|
||||
|
||||
pub const SYNC_INTERVAL_IN_MILLIS: u64 = 1000;
|
||||
pub const DOCUMENT_SYNC_INTERVAL_IN_MILLIS: u64 = 1000;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{context::DocumentUser, core::web_socket::EditorCommandReceiver};
|
||||
use crate::{core::web_socket::EditorCommandReceiver, DocumentUser};
|
||||
use async_stream::stream;
|
||||
use flowy_collaboration::{
|
||||
client_document::{history::UndoResult, ClientDocument},
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
core::{EditorCommand, SYNC_INTERVAL_IN_MILLIS},
|
||||
core::{EditorCommand, DOCUMENT_SYNC_INTERVAL_IN_MILLIS},
|
||||
DocumentWSReceiver,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
@ -46,7 +46,7 @@ pub(crate) async fn make_document_ws_manager(
|
||||
});
|
||||
|
||||
let sink_provider = Arc::new(DocumentWSSinkDataProviderAdapter(composite_sink_provider));
|
||||
let ping_duration = Duration::from_millis(SYNC_INTERVAL_IN_MILLIS);
|
||||
let ping_duration = Duration::from_millis(DOCUMENT_SYNC_INTERVAL_IN_MILLIS);
|
||||
let ws_manager = Arc::new(RevisionWebSocketManager::new(
|
||||
&doc_id,
|
||||
web_socket,
|
||||
|
@ -1,5 +1,4 @@
|
||||
pub mod context;
|
||||
mod controller;
|
||||
pub mod controller;
|
||||
pub mod core;
|
||||
// mod notify;
|
||||
pub mod protobuf;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use flowy_collaboration::entities::revision::RevisionState;
|
||||
use flowy_document::core::{ClientDocumentEditor, SYNC_INTERVAL_IN_MILLIS};
|
||||
use flowy_document::core::{ClientDocumentEditor, DOCUMENT_SYNC_INTERVAL_IN_MILLIS};
|
||||
use flowy_test::{helper::ViewTest, FlowySDKTest};
|
||||
use lib_ot::{core::Interval, rich_text::RichTextDelta};
|
||||
use std::sync::Arc;
|
||||
@ -26,7 +26,7 @@ impl EditorTest {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let _ = sdk.init_user().await;
|
||||
let test = ViewTest::new(&sdk).await;
|
||||
let editor = sdk.document_ctx.controller.open_document(&test.view.id).await.unwrap();
|
||||
let editor = sdk.document_manager.open_document(&test.view.id).await.unwrap();
|
||||
Self { sdk, editor }
|
||||
}
|
||||
|
||||
@ -79,6 +79,6 @@ impl EditorTest {
|
||||
assert_eq!(expected_delta, delta);
|
||||
},
|
||||
}
|
||||
sleep(Duration::from_millis(SYNC_INTERVAL_IN_MILLIS)).await;
|
||||
sleep(Duration::from_millis(DOCUMENT_SYNC_INTERVAL_IN_MILLIS)).await;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user