Skip to content

Commit aa48949

Browse files
authored
docs(eventually): add some missing documentation (#250)
* docs(aggregate/repository): add documentation * docs(event/store): add documentation * test(postgres): assert eventstore test failure using strings
1 parent 7f31cf2 commit aa48949

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

eventually-postgres/tests/event_store.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,29 @@ async fn it_handles_concurrent_writes_to_the_same_stream() {
168168
.into()];
169169

170170
let result = futures::join!(
171-
event_store
172-
.append(
173-
event_stream_id.clone(),
174-
StreamVersionExpected::MustBe(0),
175-
expected_events.clone(),
176-
)
177-
.map_err(Option::<version::ConflictError>::from),
178-
event_store
179-
.append(
180-
event_stream_id.clone(),
181-
StreamVersionExpected::MustBe(0),
182-
expected_events,
183-
)
184-
.map_err(Option::<version::ConflictError>::from)
171+
event_store.append(
172+
event_stream_id.clone(),
173+
StreamVersionExpected::MustBe(0),
174+
expected_events.clone(),
175+
),
176+
event_store.append(
177+
event_stream_id.clone(),
178+
StreamVersionExpected::MustBe(0),
179+
expected_events,
180+
)
185181
);
186182

187183
match result {
188184
(Ok(_), Err(err)) | (Err(err), Ok(_)) => {
189-
assert!(Option::<version::ConflictError>::from(err).is_some())
185+
let expected_err = event::AppendError::Concurrency(version::ConflictError {
186+
expected: 0,
187+
actual: 1,
188+
});
189+
190+
let actual_err_msg = format!("{}", err);
191+
let expected_err_msg = format!("{}", expected_err);
192+
193+
assert_eq!(expected_err_msg, actual_err_msg);
190194
}
191195
(first, second) => panic!(
192196
"invalid state detected, first: {:?}, second: {:?}",

eventually/src/aggregate/repository.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Module containing the definition of a [Repository], to fetch and store
2+
//! Aggregate Roots from a data store.
3+
//!
4+
//! If you are looking for the Event-sourced implementation of an Aggregate Repository,
5+
//! take a look at [EventSourced].
6+
17
use std::{fmt::Debug, marker::PhantomData};
28

39
use async_trait::async_trait;
@@ -13,27 +19,37 @@ pub enum GetError<I> {
1319
/// desired Aggregate [Root] could not be found in the data store.
1420
#[error("aggregate root was not found")]
1521
NotFound,
22+
23+
/// Error variant returned by [`Repository::get`] when the underlying
24+
/// concrete implementation has encountered an error.
1625
#[error(transparent)]
1726
Inner(#[from] I),
1827
}
1928

29+
/// Getter is a [Repository] trait used to get an [aggregate::Root]
30+
/// instance from a data store.
2031
#[async_trait]
2132
pub trait Getter<T>: Send + Sync
2233
where
2334
T: Aggregate,
2435
{
36+
/// Error type returned by the concrete implementation of the trait.
37+
/// It is returned in [get] using [GetError::Other].
2538
type Error: Send + Sync;
2639

2740
/// Loads an Aggregate Root instance from the data store,
2841
/// referenced by its unique identifier.
2942
async fn get(&self, id: &T::Id) -> Result<aggregate::Root<T>, GetError<Self::Error>>;
3043
}
3144

45+
/// Saver is a [Repository] trait used to save an [aggregate::Root]
46+
/// instance to a data store.
3247
#[async_trait]
3348
pub trait Saver<T>: Send + Sync
3449
where
3550
T: Aggregate,
3651
{
52+
/// Error type returned by the concrete implementation of the trait.
3753
type Error: Send + Sync;
3854

3955
/// Saves a new version of an Aggregate Root instance to the data store.

eventually/src/event/store.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Contains implementations of the [event::Store] trait and connected abstractions,
2+
//! such as the [std::collections::HashMap]'s based [InMemory] Event Store implementation.
3+
14
use std::{
25
collections::HashMap,
36
convert::Infallible,
@@ -32,6 +35,8 @@ where
3235
}
3336
}
3437

38+
/// In-memory implementation of [event::Store] trait,
39+
/// backed by a thread-safe [std::collections::HashMap].
3540
#[derive(Debug, Clone)]
3641
pub struct InMemory<Id, Evt>
3742
where
@@ -139,6 +144,11 @@ where
139144
}
140145
}
141146

147+
/// Decorator type for an [event::Store] implementation that tracks the list of
148+
/// recorded Domain Events through it.
149+
///
150+
/// Useful for testing purposes, i.e. asserting that Domain Events written throguh
151+
/// this Event Store instance are the ones expected.
142152
#[derive(Debug, Clone)]
143153
pub struct Tracking<T, StreamId, Event>
144154
where
@@ -158,13 +168,15 @@ where
158168
StreamId: Clone + Send + Sync,
159169
Event: message::Message + Clone + Send + Sync,
160170
{
171+
/// Returns the list of recoded Domain Events through this decorator so far.
161172
pub fn recorded_events(&self) -> Vec<event::Persisted<StreamId, Event>> {
162173
self.events
163174
.read()
164175
.expect("acquire lock on recorded events list")
165176
.clone()
166177
}
167178

179+
/// Resets the list of recorded Domain Events through this decorator.
168180
pub fn reset_recorded_events(&self) {
169181
self.events
170182
.write()
@@ -232,12 +244,16 @@ where
232244
}
233245
}
234246

247+
/// Extension trait that can be used to pull in supertypes implemented
248+
/// in this module.
235249
pub trait EventStoreExt<StreamId, Event>:
236250
event::Store<StreamId, Event> + Send + Sync + Sized
237251
where
238252
StreamId: Clone + Send + Sync,
239253
Event: message::Message + Clone + Send + Sync,
240254
{
255+
/// Returns a [Tracking] instance that decorates the original [event::Store]
256+
/// instanca this method has been called on.
241257
fn with_recorded_events_tracking(self) -> Tracking<Self, StreamId, Event> {
242258
Tracking {
243259
store: self,

0 commit comments

Comments
 (0)