bridge_embex_infrastructure/
pooling.rs1use std::time::Duration;
7
8#[derive(Debug, Clone)]
10pub struct PoolConfig {
11 pub max_connections: u32,
13 pub max_idle: u32,
15 pub idle_timeout: Duration,
17 pub connect_timeout: Duration,
19}
20
21impl Default for PoolConfig {
22 fn default() -> Self {
23 Self {
24 max_connections: 10,
25 max_idle: 10,
26 idle_timeout: Duration::from_secs(90),
27 connect_timeout: Duration::from_secs(30),
28 }
29 }
30}
31
32#[derive(Debug, Clone, PartialEq)]
34pub enum PoolingStatus {
35 Configurable {
37 max_connections: u32,
38 idle_timeout_secs: u64,
39 },
40 Default,
42 NotApplicable,
44}
45
46pub fn get_pooling_status(provider: &str) -> PoolingStatus {
48 match provider {
49 "pgvector" => PoolingStatus::Configurable {
50 max_connections: 10, idle_timeout_secs: 90,
52 },
53 "pinecone" => PoolingStatus::Configurable {
54 max_connections: 10, idle_timeout_secs: 90,
56 },
57 "milvus" => PoolingStatus::Configurable {
58 max_connections: 10, idle_timeout_secs: 90,
60 },
61 "weaviate" => PoolingStatus::Configurable {
62 max_connections: 10, idle_timeout_secs: 90,
64 },
65 "qdrant" => PoolingStatus::Default, "chroma" => PoolingStatus::Default, "lancedb" => PoolingStatus::NotApplicable, _ => PoolingStatus::Default,
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn test_pooling_status_pgvector() {
78 let status = get_pooling_status("pgvector");
79 assert!(matches!(status, PoolingStatus::Configurable { .. }));
80 }
81
82 #[test]
83 fn test_pooling_status_http_adapters() {
84 let providers = vec!["pinecone", "milvus", "weaviate"];
85 for provider in providers {
86 let status = get_pooling_status(provider);
87 assert!(matches!(status, PoolingStatus::Configurable { .. }),
88 "Provider {} should have configurable pooling", provider);
89 }
90 }
91
92 #[test]
93 fn test_pooling_status_internal_clients() {
94 let status_qdrant = get_pooling_status("qdrant");
95 assert_eq!(status_qdrant, PoolingStatus::Default);
96
97 let status_chroma = get_pooling_status("chroma");
98 assert_eq!(status_chroma, PoolingStatus::Default);
99 }
100
101 #[test]
102 fn test_pooling_status_lancedb() {
103 let status = get_pooling_status("lancedb");
104 assert_eq!(status, PoolingStatus::NotApplicable);
105 }
106}
107