mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-12 07:36:29 +00:00
add tests and mocks
This commit is contained in:
@ -23,7 +23,7 @@ impl<D, S, I> UpdateActor<D, S, I>
|
||||
where
|
||||
D: AsRef<[u8]> + Sized + 'static,
|
||||
S: UpdateStoreStore,
|
||||
I: IndexActorHandle + 'static,
|
||||
I: IndexActorHandle + Clone + Send + Sync + 'static,
|
||||
{
|
||||
pub fn new(
|
||||
store: S,
|
||||
|
@ -24,7 +24,7 @@ where
|
||||
update_store_size: usize,
|
||||
) -> anyhow::Result<Self>
|
||||
where
|
||||
I: IndexActorHandle + 'static,
|
||||
I: IndexActorHandle + Clone + Send + Sync + 'static,
|
||||
{
|
||||
let path = path.as_ref().to_owned().join("updates");
|
||||
let (sender, receiver) = mpsc::channel(100);
|
||||
|
@ -23,6 +23,9 @@ pub type Result<T> = std::result::Result<T, UpdateError>;
|
||||
type UpdateStore = update_store::UpdateStore<UpdateMeta, UpdateResult, String>;
|
||||
type PayloadData<D> = std::result::Result<D, Box<dyn std::error::Error + Sync + Send + 'static>>;
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum UpdateError {
|
||||
#[error("error with update: {0}")]
|
||||
@ -34,6 +37,7 @@ pub enum UpdateError {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
#[cfg_attr(test, automock(type Data=Vec<u8>;))]
|
||||
pub trait UpdateActorHandle {
|
||||
type Data: AsRef<[u8]> + Sized + 'static + Sync + Send;
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use uuid::Uuid;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::fs;
|
||||
use tokio::sync::RwLock;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{Result, UpdateError, UpdateStore};
|
||||
use crate::index_controller::IndexActorHandle;
|
||||
use super::{UpdateStore, UpdateError, Result};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait UpdateStoreStore {
|
||||
@ -25,11 +25,7 @@ pub struct MapUpdateStoreStore<I> {
|
||||
}
|
||||
|
||||
impl<I: IndexActorHandle> MapUpdateStoreStore<I> {
|
||||
pub fn new(
|
||||
index_handle: I,
|
||||
path: impl AsRef<Path>,
|
||||
update_store_size: usize,
|
||||
) -> Self {
|
||||
pub fn new(index_handle: I, path: impl AsRef<Path>, update_store_size: usize) -> Self {
|
||||
let db = Arc::new(RwLock::new(HashMap::new()));
|
||||
let path = path.as_ref().to_owned();
|
||||
Self {
|
||||
@ -42,7 +38,10 @@ impl<I: IndexActorHandle> MapUpdateStoreStore<I> {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<I: IndexActorHandle + 'static> UpdateStoreStore for MapUpdateStoreStore<I> {
|
||||
impl<I> UpdateStoreStore for MapUpdateStoreStore<I>
|
||||
where
|
||||
I: IndexActorHandle + Clone + Send + Sync + 'static,
|
||||
{
|
||||
async fn get_or_create(&self, uuid: Uuid) -> Result<Arc<UpdateStore>> {
|
||||
match self.db.write().await.entry(uuid) {
|
||||
Entry::Vacant(e) => {
|
||||
|
Reference in New Issue
Block a user