style: cargo fmt --all
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use application::processing::{CompleteJobCommand, CompleteJobHandler};
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
||||
use domain::events::DomainEvent;
|
||||
use domain::ports::{JobBatchRepository, JobRepository};
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn completes_job() {
|
||||
@@ -18,10 +18,13 @@ async fn completes_job() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
let result = handler.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.status, JobStatus::Completed);
|
||||
assert!(result.result_data.is_some());
|
||||
@@ -37,17 +40,19 @@ async fn completes_job_and_updates_batch() {
|
||||
let batch_id = batch.batch_id;
|
||||
batch_repo.save(&batch).await.unwrap();
|
||||
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new())
|
||||
.with_batch(batch_id);
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id);
|
||||
job.start().unwrap();
|
||||
let job_id = job.job_id;
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
handler.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
||||
assert_eq!(updated_batch.completed_count, 1);
|
||||
@@ -65,10 +70,13 @@ async fn publishes_event() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
handler.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let events = event_pub.published().await;
|
||||
assert_eq!(events.len(), 1);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
use application::processing::{
|
||||
ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig,
|
||||
};
|
||||
use application::testing::{InMemoryPipelineRepository, InMemoryPluginRepository};
|
||||
use application::processing::{ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig};
|
||||
use domain::entities::{Plugin, PluginType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::PluginRepository;
|
||||
use domain::value_objects::{StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn creates_pipeline() {
|
||||
@@ -19,13 +21,22 @@ async fn creates_pipeline() {
|
||||
plugin_repo.save(&p2).await.unwrap();
|
||||
|
||||
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
||||
let pipeline = handler.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![
|
||||
PipelineStepConfig { plugin_id: p1_id, config: StructuredData::new() },
|
||||
PipelineStepConfig { plugin_id: p2_id, config: StructuredData::new() },
|
||||
],
|
||||
}).await.unwrap();
|
||||
let pipeline = handler
|
||||
.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![
|
||||
PipelineStepConfig {
|
||||
plugin_id: p1_id,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
PipelineStepConfig {
|
||||
plugin_id: p2_id,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
],
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pipeline.trigger_event, "asset.ingested");
|
||||
assert_eq!(pipeline.steps.len(), 2);
|
||||
@@ -37,12 +48,15 @@ async fn rejects_nonexistent_plugin() {
|
||||
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
||||
|
||||
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
||||
let result = handler.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![
|
||||
PipelineStepConfig { plugin_id: SystemId::new(), config: StructuredData::new() },
|
||||
],
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![PipelineStepConfig {
|
||||
plugin_id: SystemId::new(),
|
||||
config: StructuredData::new(),
|
||||
}],
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryJobRepository, StubEventPublisher};
|
||||
use application::processing::{EnqueueJobCommand, EnqueueJobHandler};
|
||||
use application::testing::{InMemoryJobRepository, StubEventPublisher};
|
||||
use domain::entities::{JobStatus, JobType};
|
||||
use domain::events::DomainEvent;
|
||||
use domain::value_objects::{StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn enqueues_job() {
|
||||
@@ -11,13 +11,16 @@ async fn enqueues_job() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
||||
|
||||
let job = handler.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ExtractMetadata,
|
||||
priority: 5,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
}).await.unwrap();
|
||||
let job = handler
|
||||
.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ExtractMetadata,
|
||||
priority: 5,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(job.status, JobStatus::Queued);
|
||||
assert_eq!(job.priority, 5);
|
||||
@@ -33,13 +36,16 @@ async fn enqueues_with_target_and_batch() {
|
||||
|
||||
let target = SystemId::new();
|
||||
let batch = SystemId::new();
|
||||
let job = handler.execute(EnqueueJobCommand {
|
||||
job_type: JobType::GenerateDerivative,
|
||||
priority: 10,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: Some(target),
|
||||
batch_id: Some(batch),
|
||||
}).await.unwrap();
|
||||
let job = handler
|
||||
.execute(EnqueueJobCommand {
|
||||
job_type: JobType::GenerateDerivative,
|
||||
priority: 10,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: Some(target),
|
||||
batch_id: Some(batch),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(job.target_asset_id, Some(target));
|
||||
assert_eq!(job.batch_id, Some(batch));
|
||||
@@ -51,13 +57,16 @@ async fn publishes_event() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
||||
|
||||
let job = handler.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ScanDirectory,
|
||||
priority: 1,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
}).await.unwrap();
|
||||
let job = handler
|
||||
.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ScanDirectory,
|
||||
priority: 1,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let events = event_pub.published().await;
|
||||
assert_eq!(events.len(), 1);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use application::processing::{FailJobCommand, FailJobHandler};
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
||||
use domain::events::DomainEvent;
|
||||
use domain::ports::{JobBatchRepository, JobRepository};
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn make_handler(
|
||||
job_repo: Arc<InMemoryJobRepository>,
|
||||
@@ -26,10 +26,13 @@ async fn retries_on_failure() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
let result = handler.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "transient error".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "transient error".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.status, JobStatus::Queued);
|
||||
assert_eq!(result.retry_count, 1);
|
||||
@@ -54,10 +57,13 @@ async fn fails_permanently_after_max_retries() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
let result = handler.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "fatal".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "fatal".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.status, JobStatus::Failed);
|
||||
assert_eq!(result.retry_count, 3);
|
||||
@@ -76,8 +82,7 @@ async fn updates_batch_on_permanent_failure() {
|
||||
let batch_id = batch.batch_id;
|
||||
batch_repo.save(&batch).await.unwrap();
|
||||
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new())
|
||||
.with_batch(batch_id);
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id);
|
||||
// Exhaust retries
|
||||
job.fail("err1");
|
||||
job.fail("err2");
|
||||
@@ -85,10 +90,13 @@ async fn updates_batch_on_permanent_failure() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
handler.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "permanent failure".into(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "permanent failure".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
||||
assert_eq!(updated_batch.failed_count, 1);
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryPluginRepository;
|
||||
use application::processing::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
||||
use application::testing::InMemoryPluginRepository;
|
||||
use domain::entities::{Plugin, PluginType};
|
||||
use domain::ports::PluginRepository;
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn creates_plugin() {
|
||||
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||
|
||||
let plugin = handler.execute(ManagePluginCommand {
|
||||
plugin_id: None,
|
||||
action: PluginAction::Create {
|
||||
name: "EXIF Extractor".into(),
|
||||
plugin_type: PluginType::MediaProcessor,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
}).await.unwrap();
|
||||
let plugin = handler
|
||||
.execute(ManagePluginCommand {
|
||||
plugin_id: None,
|
||||
action: PluginAction::Create {
|
||||
name: "EXIF Extractor".into(),
|
||||
plugin_type: PluginType::MediaProcessor,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(plugin.name, "EXIF Extractor");
|
||||
assert_eq!(plugin.plugin_type, PluginType::MediaProcessor);
|
||||
@@ -36,10 +39,13 @@ async fn enables_plugin() {
|
||||
plugin_repo.save(&plugin).await.unwrap();
|
||||
|
||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||
let result = handler.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Enable,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Enable,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.is_enabled);
|
||||
}
|
||||
@@ -52,10 +58,13 @@ async fn disables_plugin() {
|
||||
plugin_repo.save(&plugin).await.unwrap();
|
||||
|
||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||
let result = handler.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Disable,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Disable,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(!result.is_enabled);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod enqueue_job;
|
||||
mod start_job;
|
||||
mod complete_job;
|
||||
mod configure_pipeline;
|
||||
mod enqueue_job;
|
||||
mod fail_job;
|
||||
mod manage_plugin;
|
||||
mod configure_pipeline;
|
||||
mod start_job;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryJobRepository;
|
||||
use application::processing::{StartJobCommand, StartJobHandler};
|
||||
use application::testing::InMemoryJobRepository;
|
||||
use domain::entities::{Job, JobStatus, JobType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::JobRepository;
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn starts_queued_job() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::processing::{ReportBatchProgressHandler, ReportBatchProgressQuery};
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository};
|
||||
use application::processing::{ReportBatchProgressQuery, ReportBatchProgressHandler};
|
||||
use domain::entities::{Job, JobBatch, JobType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{JobBatchRepository, JobRepository};
|
||||
use domain::value_objects::{StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_progress() {
|
||||
@@ -21,7 +21,10 @@ async fn returns_progress() {
|
||||
job_repo.save(&j2).await.unwrap();
|
||||
|
||||
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
||||
let progress = handler.execute(ReportBatchProgressQuery { batch_id }).await.unwrap();
|
||||
let progress = handler
|
||||
.execute(ReportBatchProgressQuery { batch_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(progress.batch.batch_id, batch_id);
|
||||
assert_eq!(progress.jobs.len(), 2);
|
||||
@@ -33,9 +36,11 @@ async fn rejects_nonexistent_batch() {
|
||||
let job_repo = Arc::new(InMemoryJobRepository::new());
|
||||
|
||||
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
||||
let result = handler.execute(ReportBatchProgressQuery {
|
||||
batch_id: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ReportBatchProgressQuery {
|
||||
batch_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user