azure_functions/event_hub/
runtime_information.rs

1use crate::util::deserialize_datetime;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5/// Represents the approximate receiver runtime information for a logical partition of an Event Hub.
6#[derive(Debug, Serialize, Deserialize)]
7#[serde(rename_all = "PascalCase")]
8pub struct RuntimeInformation {
9    /// The partition ID for a logical partition of an Event Hub.
10    pub partition_id: String,
11    /// The last sequence number of the event within the partition stream of the Event Hub.
12    pub last_sequence_number: i64,
13    /// The enqueued time (in UTC) of the last event.
14    #[serde(
15        rename = "LastEnqueuedTimeUtc",
16        deserialize_with = "deserialize_datetime"
17    )]
18    pub last_enqueued_time: DateTime<Utc>,
19    /// The offset of the last enqueued event.
20    pub last_enqueued_offset: Option<String>,
21    /// The time when the runtime information was retrieved.
22    #[serde(deserialize_with = "deserialize_datetime")]
23    pub retrieval_time: DateTime<Utc>,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use serde_json::from_str;
30
31    #[test]
32    fn it_deserializes_from_json() {
33        const JSON: &'static str = r#"{"PartitionId":"0","LastSequenceNumber":0,"LastEnqueuedTimeUtc":"0001-01-01T00:00:00","LastEnqueuedOffset":null,"RetrievalTime":"0001-01-01T00:00:00"}"#;
34
35        let info: RuntimeInformation =
36            from_str(JSON).expect("failed to parse runtime information JSON data");
37        assert_eq!(info.partition_id, "0");
38        assert_eq!(info.last_sequence_number, 0);
39        assert_eq!(
40            info.last_enqueued_time.to_rfc3339(),
41            "0001-01-01T00:00:00+00:00"
42        );
43        assert_eq!(info.last_enqueued_offset, None);
44        assert_eq!(
45            info.retrieval_time.to_rfc3339(),
46            "0001-01-01T00:00:00+00:00"
47        );
48    }
49}