[−][src]Struct exonum_time::MockTimeProvider
Mock time provider for service testing.
In terms of use, the mock time provider is similar to Arc
; that is, clones of the provider
control the same time record as the original instance. Therefore, to use the mock provider,
one may clone its instance and use the clone to construct a TimeService
,
while keeping the original instance to adjust the time reported to the validators
along various test scenarios.
Examples
use chrono::{Utc, Duration, TimeZone}; use exonum::{helpers::Height, runtime::SnapshotExt}; use exonum_testkit::TestKit; use exonum_time::{MockTimeProvider, TimeSchema, TimeServiceFactory}; let service_name = "time"; let service_id = 12; let mock_provider = MockTimeProvider::default(); let mut testkit = TestKit::for_rust_service( TimeServiceFactory::with_provider(mock_provider.clone()), service_name, service_id, () ); mock_provider.add_time(Duration::seconds(15)); testkit.create_blocks_until(Height(2)); // The time reported by the mock time provider is reflected by the service. let snapshot = testkit.snapshot(); let schema: TimeSchema<_> = snapshot.service_schema(service_name).unwrap(); assert_eq!( Utc.timestamp(15, 0), schema.time.get().unwrap() );
Methods
impl MockTimeProvider
[src]
pub fn new(time: DateTime<Utc>) -> Self
[src]
Creates a new MockTimeProvider
with time value equal to time
.
pub fn time(&self) -> DateTime<Utc>
[src]
Gets the time value currently reported by the provider.
pub fn set_time(&self, new_time: DateTime<Utc>)
[src]
Sets the time value to new_time
.
pub fn add_time(&self, duration: Duration)
[src]
Adds duration
to the value of time
.
Trait Implementations
impl Clone for MockTimeProvider
[src]
fn clone(&self) -> MockTimeProvider
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for MockTimeProvider
[src]
impl Default for MockTimeProvider
[src]
impl From<MockTimeProvider> for Arc<dyn TimeProvider>
[src]
fn from(time_provider: MockTimeProvider) -> Self
[src]
impl TimeProvider for MockTimeProvider
[src]
fn current_time(&self) -> DateTime<Utc>
[src]
Auto Trait Implementations
impl RefUnwindSafe for MockTimeProvider
impl Send for MockTimeProvider
impl Sync for MockTimeProvider
impl Unpin for MockTimeProvider
impl UnwindSafe for MockTimeProvider
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
fn clear(&mut self)
impl<T> From<T> for T
[src]
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
unsafe fn initialize(place: *mut T)
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,