azure_functions/event_hub/
partition_context.rs

1use crate::event_hub::RuntimeInformation;
2use serde::{Deserialize, Serialize};
3
4/// Encapsulates information related to an Event Hubs partition.
5#[derive(Debug, Serialize, Deserialize)]
6#[serde(rename_all = "PascalCase")]
7pub struct PartitionContext {
8    /// The name of the consumer group.
9    pub consumer_group_name: String,
10    /// The path of the Event Hub.
11    pub event_hub_path: String,
12    /// The partition ID for the context.
13    pub partition_id: String,
14    /// The host owner for the partition.
15    pub owner: String,
16    /// The approximate receiver runtime information for a logical partition of the Event Hub.
17    pub runtime_information: RuntimeInformation,
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23    use serde_json::from_str;
24
25    #[test]
26    fn it_deserializes_from_json() {
27        const JSON: &'static str = r#"{"ConsumerGroupName":"$Default","EventHubPath":"test","PartitionId":"0","Owner":"40eeeb3a-3491-4072-ba37-59ecdc330b6e","RuntimeInformation":{"PartitionId":"0","LastSequenceNumber":0,"LastEnqueuedTimeUtc":"0001-01-01T00:00:00","LastEnqueuedOffset":null,"RetrievalTime":"0001-01-01T00:00:00"}}"#;
28
29        let context: PartitionContext =
30            from_str(JSON).expect("failed to parse partition context JSON data");
31
32        assert_eq!(context.consumer_group_name, "$Default");
33        assert_eq!(context.event_hub_path, "test");
34        assert_eq!(context.partition_id, "0");
35        assert_eq!(context.owner, "40eeeb3a-3491-4072-ba37-59ecdc330b6e");
36        assert_eq!(context.runtime_information.partition_id, "0");
37        assert_eq!(context.runtime_information.last_sequence_number, 0);
38        assert_eq!(
39            context.runtime_information.last_enqueued_time.to_rfc3339(),
40            "0001-01-01T00:00:00+00:00"
41        );
42        assert_eq!(context.runtime_information.last_enqueued_offset, None);
43        assert_eq!(
44            context.runtime_information.retrieval_time.to_rfc3339(),
45            "0001-01-01T00:00:00+00:00"
46        );
47    }
48}