feldera_types/transport/
url.rs1use serde::{Deserialize, Serialize};
2use utoipa::ToSchema;
3
4use crate::{
5 duration::{ConfigDuration, LegacyUnit},
6 duration_setting,
7};
8
9pub const DEFAULT_PAUSE_TIMEOUT: ConfigDuration = ConfigDuration::from_secs(60);
11
12fn default_pause_linger() -> String {
14 DEFAULT_PAUSE_TIMEOUT.to_string()
15}
16
17duration_setting!(duration_pause_linger, "pause_linger", LegacyUnit::Secs);
18
19#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
22pub struct UrlInputConfig {
23 pub path: String,
25
26 #[serde(
36 default,
37 alias = "pause_timeout",
38 deserialize_with = "duration_pause_linger",
39 skip_serializing_if = "Option::is_none"
40 )]
41 #[schema(value_type = Option<String>, default = default_pause_linger)]
42 pub pause_linger: Option<ConfigDuration>,
43}
44
45impl UrlInputConfig {
46 pub fn pause_linger(&self) -> ConfigDuration {
48 self.pause_linger.unwrap_or(DEFAULT_PAUSE_TIMEOUT)
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 fn parse(json: &str) -> UrlInputConfig {
57 serde_json::from_str(json).unwrap()
58 }
59
60 #[test]
63 fn pause_linger_accepts_both_spellings() {
64 for (json, expected) in [
65 (r#"{"path": "http://x"}"#, DEFAULT_PAUSE_TIMEOUT),
66 (
67 r#"{"path": "http://x", "pause_linger": "5m"}"#,
68 ConfigDuration::from_secs(300),
69 ),
70 (
71 r#"{"path": "http://x", "pause_timeout": 10}"#,
72 ConfigDuration::from_secs(10),
73 ),
74 ] {
75 assert_eq!(parse(json).pause_linger(), expected, "parsing {json}");
76 }
77 }
78
79 #[test]
80 fn unset_fields_do_not_serialize() {
81 let json = serde_json::to_string(&parse(r#"{"path": "http://x"}"#)).unwrap();
82 assert_eq!(json, r#"{"path":"http://x"}"#);
83 }
84}