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
use crate::event_hub::RuntimeInformation;
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct PartitionContext {
pub consumer_group_name: String,
pub event_hub_path: String,
pub partition_id: String,
pub owner: String,
pub runtime_information: RuntimeInformation,
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::from_str;
#[test]
fn it_deserializes_from_json() {
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"}}"#;
let context: PartitionContext =
from_str(JSON).expect("failed to parse partition context JSON data");
assert_eq!(context.consumer_group_name, "$Default");
assert_eq!(context.event_hub_path, "test");
assert_eq!(context.partition_id, "0");
assert_eq!(context.owner, "40eeeb3a-3491-4072-ba37-59ecdc330b6e");
assert_eq!(context.runtime_information.partition_id, "0");
assert_eq!(context.runtime_information.last_sequence_number, 0);
assert_eq!(
context.runtime_information.last_enqueued_time.to_rfc3339(),
"0001-01-01T00:00:00+00:00"
);
assert_eq!(context.runtime_information.last_enqueued_offset, None);
assert_eq!(
context.runtime_information.retrieval_time.to_rfc3339(),
"0001-01-01T00:00:00+00:00"
);
}
}