Skip to content

Commit

Permalink
Added a backend test for export/import (#30072)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: e1859c238337c4d18095e49df21ffa9c9bc42e00
  • Loading branch information
nipunn1313 authored and Convex, Inc. committed Sep 25, 2024
1 parent dce2e98 commit 357917d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/application/src/snapshot_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,12 +1331,12 @@ pub async fn start_cloud_import<RT: Runtime>(
application: &Application<RT>,
identity: Identity,
source_object_key: FullyQualifiedObjectKey,
) -> anyhow::Result<()> {
) -> anyhow::Result<DeveloperDocumentId> {
let object_key: ObjectKey = application
.snapshot_imports_storage
.copy_object(source_object_key)
.await?;
store_uploaded_import(
let id = store_uploaded_import(
application,
identity,
ImportFormat::Zip,
Expand All @@ -1345,7 +1345,7 @@ pub async fn start_cloud_import<RT: Runtime>(
object_key,
)
.await?;
Ok(())
Ok(id)
}

pub async fn store_uploaded_import<RT: Runtime>(
Expand Down
11 changes: 11 additions & 0 deletions crates/application/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ use node_executor::{
};
use storage::{
LocalDirStorage,
Storage,
StorageUseCase,
};
use value::{
Expand Down Expand Up @@ -158,6 +159,8 @@ pub trait ApplicationTestExt<RT: Runtime> {
fields: IndexedFields,
) -> anyhow::Result<IndexedFields>;
fn database(&self) -> &Database<RT>;
fn snapshot_imports_storage(&self) -> Arc<dyn Storage>;
fn exports_storage(&self) -> Arc<dyn Storage>;
}

#[async_trait]
Expand Down Expand Up @@ -281,6 +284,14 @@ impl<RT: Runtime> ApplicationTestExt<RT> for Application<RT> {
Ok(application)
}

fn snapshot_imports_storage(&self) -> Arc<dyn Storage> {
self.snapshot_imports_storage.clone()
}

fn exports_storage(&self) -> Arc<dyn Storage> {
self.exports_storage.clone()
}

async fn test_one_off_scheduled_job_executor_run(
&self,
job: ScheduledJob,
Expand Down
17 changes: 17 additions & 0 deletions crates/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ pub trait Storage: Send + Sync + Debug {
/// Return a fully qualified key, including info on bucket name
/// and suitable for access in multi-tenant scenario
fn fully_qualified_key(&self, key: &ObjectKey) -> FullyQualifiedObjectKey;
fn test_only_decompose_fully_qualified_key(
&self,
key: FullyQualifiedObjectKey,
) -> anyhow::Result<ObjectKey>;
}

pub struct ObjectAttributes {
Expand Down Expand Up @@ -1016,6 +1020,19 @@ impl<RT: Runtime> Storage for LocalDirStorage<RT> {
path.to_string_lossy().to_string().into()
}

fn test_only_decompose_fully_qualified_key(
&self,
key: FullyQualifiedObjectKey,
) -> anyhow::Result<ObjectKey> {
let key: String = key.into();
let path = Path::new(&key);
let remaining = path.strip_prefix(&self.dir)?.to_string_lossy();
remaining
.strip_suffix(".blob")
.context("Doesn't end with .blob")?
.try_into()
}

fn get_small_range(
&self,
key: &ObjectKey,
Expand Down

0 comments on commit 357917d

Please sign in to comment.