1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::util::deserialize_datetime;
use chrono::{DateTime, Utc};
use serde_derive::{Deserialize, Serialize};

/// Represents the approximate receiver runtime information for a logical partition of an Event Hub.
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct RuntimeInformation {
    /// The partition ID for a logical partition of an Event Hub.
    pub partition_id: String,
    /// The last sequence number of the event within the partition stream of the Event Hub.
    pub last_sequence_number: i64,
    /// The enqueued time (in UTC) of the last event.
    #[serde(
        rename = "LastEnqueuedTimeUtc",
        deserialize_with = "deserialize_datetime"
    )]
    pub last_enqueued_time: DateTime<Utc>,
    /// The offset of the last enqueued event.
    pub last_enqueued_offset: Option<String>,
    /// The time when the runtime information was retrieved.
    #[serde(deserialize_with = "deserialize_datetime")]
    pub retrieval_time: DateTime<Utc>,
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::from_str;

    #[test]
    fn it_deserializes_from_json() {
        const JSON: &'static str = r#"{"PartitionId":"0","LastSequenceNumber":0,"LastEnqueuedTimeUtc":"0001-01-01T00:00:00","LastEnqueuedOffset":null,"RetrievalTime":"0001-01-01T00:00:00"}"#;

        let info: RuntimeInformation =
            from_str(JSON).expect("failed to parse runtime information JSON data");
        assert_eq!(info.partition_id, "0");
        assert_eq!(info.last_sequence_number, 0);
        assert_eq!(
            info.last_enqueued_time.to_rfc3339(),
            "0001-01-01T00:00:00+00:00"
        );
        assert_eq!(info.last_enqueued_offset, None);
        assert_eq!(
            info.retrieval_time.to_rfc3339(),
            "0001-01-01T00:00:00+00:00"
        );
    }
}