sdf_metadata/metadata/io/
producer_config.rs

1use crate::wit::io::ProducerConfig;
2
3impl ProducerConfig {
4    pub fn merge(&mut self, other: &ProducerConfig) {
5        if self.linger_ms.is_none() {
6            self.linger_ms = other.linger_ms;
7        }
8        if self.compression.is_none() {
9            self.compression = other.compression;
10        }
11
12        if self.isolation.is_none() {
13            self.isolation = other.isolation;
14        }
15
16        if self.timeout_ms.is_none() {
17            self.timeout_ms = other.timeout_ms;
18        }
19
20        if self.batch_size_bytes.is_none() {
21            self.batch_size_bytes = other.batch_size_bytes;
22        }
23    }
24}
25
26#[allow(clippy::derivable_impls)]
27impl Default for ProducerConfig {
28    fn default() -> Self {
29        Self {
30            linger_ms: None,
31            batch_size_bytes: None,
32            isolation: None,
33            compression: None,
34            timeout_ms: None,
35        }
36    }
37}
38
39#[cfg(test)]
40mod test {
41    use crate::wit::io::Compression;
42
43    #[test]
44    fn test_producer_config_merge() {
45        let mut config1 = super::ProducerConfig {
46            linger_ms: Some(100),
47            compression: Some(Compression::Gzip),
48            ..Default::default()
49        };
50
51        let config2 = super::ProducerConfig {
52            linger_ms: Some(200),
53            batch_size_bytes: Some(1024),
54            isolation: Some(crate::wit::io::Isolation::ReadCommitted),
55            timeout_ms: Some(500),
56            ..Default::default()
57        };
58
59        config1.merge(&config2);
60
61        assert_eq!(config1.linger_ms, Some(100));
62        assert_eq!(config1.batch_size_bytes, Some(1024));
63        assert_eq!(
64            config1.isolation,
65            Some(crate::wit::io::Isolation::ReadCommitted)
66        );
67        assert_eq!(config1.compression, Some(Compression::Gzip));
68        assert_eq!(config1.timeout_ms, Some(500));
69    }
70}