66mod tokio_synced_clock;
77pub use tokio_synced_clock:: TokioSyncedClock ;
88
9+ use std:: sync:: Mutex ;
910use std:: { sync:: Arc , time:: SystemTime } ;
10-
1111use tokio_stream:: wrappers:: ReceiverStream ;
1212use tonic:: Response ;
1313
14+ use super :: MicrogridApiClient ;
1415use crate :: wall_clock_timer:: Clock as _;
1516use crate :: {
1617 client:: proto:: {
1718 common:: {
1819 metrics:: {
19- Bounds , Metric , MetricSample , MetricValueVariant , SimpleMetricValue , metric_value_variant,
20+ Bounds , Metric , MetricSample , MetricValueVariant , SimpleMetricValue ,
21+ metric_value_variant,
2022 } ,
2123 microgrid:: electrical_components:: {
2224 ElectricalComponent , ElectricalComponentCategory ,
2325 ElectricalComponentCategorySpecificInfo , ElectricalComponentConnection ,
2426 ElectricalComponentStateCode , ElectricalComponentStateSnapshot ,
25- ElectricalComponentTelemetry , Inverter , InverterType ,
27+ ElectricalComponentTelemetry , Inverter , InverterType , MetricConfigBounds ,
2628 electrical_component_category_specific_info:: Kind ,
27- MetricConfigBounds ,
2829 } ,
2930 } ,
3031 google:: protobuf,
@@ -38,7 +39,6 @@ use crate::{
3839 } ,
3940 quantity:: { Current , Power , ReactivePower , Voltage } ,
4041} ;
41- use super :: MicrogridApiClient ;
4242
4343/// A mock implementation of the `MicrogridApiClient` trait for testing purposes.
4444///
@@ -52,6 +52,7 @@ pub struct MockMicrogridApiClient {
5252 /// share a clone with [`LogicalMeterActor`], and pass another in via
5353 /// [`MockMicrogridApiClient::new_with_clock`].
5454 clock : TokioSyncedClock ,
55+ pub augment_bounds_calls : Arc < Mutex < Vec < AugmentElectricalComponentBoundsRequest > > > ,
5556}
5657
5758/// One row per emitted telemetry frame: `(power, reactive_power, voltage,
@@ -182,13 +183,18 @@ impl MockComponent {
182183 self
183184 }
184185
185- pub fn add_component_bounds ( mut self , metric : i32 , lower : Option < f32 > , upper : Option < f32 > ) -> Self {
186- self . component . metric_config_bounds . push (
187- MetricConfigBounds {
186+ pub fn add_component_bounds (
187+ mut self ,
188+ metric : i32 ,
189+ lower : Option < f32 > ,
190+ upper : Option < f32 > ,
191+ ) -> Self {
192+ self . component
193+ . metric_config_bounds
194+ . push ( MetricConfigBounds {
188195 metric,
189- config_bounds : Some ( Bounds { lower, upper} ) ,
190- }
191- ) ;
196+ config_bounds : Some ( Bounds { lower, upper } ) ,
197+ } ) ;
192198 self
193199 }
194200
@@ -298,6 +304,7 @@ impl MockMicrogridApiClient {
298304 components : vec ! [ ] ,
299305 connections : vec ! [ ] ,
300306 clock,
307+ augment_bounds_calls : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
301308 } ;
302309
303310 fn traverse ( node : & MockComponent , client : & mut MockMicrogridApiClient ) {
@@ -315,6 +322,13 @@ impl MockMicrogridApiClient {
315322
316323 this_client
317324 }
325+
326+ /// Return a handle to captured augment bounds requests.
327+ pub fn augment_bounds_calls_handle (
328+ & self ,
329+ ) -> Arc < Mutex < Vec < AugmentElectricalComponentBoundsRequest > > > {
330+ self . augment_bounds_calls . clone ( )
331+ }
318332}
319333
320334#[ async_trait:: async_trait]
@@ -510,7 +524,13 @@ impl MicrogridApiClient for MockMicrogridApiClient {
510524 _request : impl tonic:: IntoRequest < AugmentElectricalComponentBoundsRequest > + Send ,
511525 ) -> std:: result:: Result < tonic:: Response < AugmentElectricalComponentBoundsResponse > , tonic:: Status >
512526 {
513- unimplemented ! ( )
527+ // Capture calls for tests
528+ let req = _request. into_request ( ) . into_inner ( ) ;
529+ self . augment_bounds_calls . lock ( ) . unwrap ( ) . push ( req) ;
530+
531+ Ok ( Response :: new ( AugmentElectricalComponentBoundsResponse {
532+ valid_until_time : None ,
533+ } ) )
514534 }
515535}
516536
0 commit comments