File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
internal/mithril-dmq/src/test/double Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 44
55mod consumer;
66mod publisher;
7+ mod timestamp;
78
89pub use consumer:: * ;
910pub use publisher:: * ;
11+ pub use timestamp:: * ;
Original file line number Diff line number Diff line change 1+ use mithril_common:: StdResult ;
2+
3+ use crate :: model:: UnixTimestampProvider ;
4+
5+ /// Fake implementation of a Unix current timestamp provider. For testing purposes only.
6+ pub struct FakeUnixTimestampProvider ( u64 ) ;
7+
8+ impl FakeUnixTimestampProvider {
9+ /// Creates a new `FakeUnixTimestampProvider` with the given timestamp.
10+ pub fn new ( timestamp : u64 ) -> Self {
11+ Self ( timestamp)
12+ }
13+
14+ /// Computes the maximum timestamp that can be used with the given TTL and builds a new FakeUnixTimestampProvider.
15+ ///
16+ /// This is useful to create messages that are valid for the maximum possible time.
17+ pub fn max_timestamp_for_ttl ( ttl : u16 ) -> Self {
18+ Self ( u32:: MAX as u64 - ttl as u64 - 1 )
19+ }
20+ }
21+
22+ impl UnixTimestampProvider for FakeUnixTimestampProvider {
23+ fn current_timestamp ( & self ) -> StdResult < u64 > {
24+ Ok ( self . 0 )
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments