From ca8440db7d748261b3a55053f8ee099f7c4b6370 Mon Sep 17 00:00:00 2001 From: "Michael P. Jung" Date: Wed, 19 Jun 2024 10:37:43 +0000 Subject: [PATCH] Update to latest deadpool and arangors version (wip) --- arangodb/Cargo.toml | 8 ++++---- arangodb/src/lib.rs | 9 ++++----- arangodb/tests/arangodb.rs | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/arangodb/Cargo.toml b/arangodb/Cargo.toml index 6ca0d7f4..8e487f7a 100644 --- a/arangodb/Cargo.toml +++ b/arangodb/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "deadpool-arangodb" version = "0.1.0" -edition = "2018" +edition = "2021" resolver = "2" authors = ["Daniel Wiesenberg "] description = "Dead simple async pool for ArangoDB" @@ -16,14 +16,14 @@ all-features = true [features] default = ["rt_tokio_1"] rt_tokio_1 = ["deadpool/rt_tokio_1", "arangors/reqwest_async"] -rt_async-std_1 = ["deadpool/rt_async-std_1", "arangors/surf_async"] +#rt_async-std_1 = ["deadpool/rt_async-std_1", "arangors/reqwest_async"] [dependencies] -deadpool = { path = "../", version = "0.10.0", default-features = false, features = [ +deadpool = { path = "../", version = "0.12.0", default-features = false, features = [ "managed", "serde", ] } -arangors = "0.5.4" +arangors = { version = "0.6.0", default-features = false } serde = { version = "1.0", features = ["derive"] } url = "2.2" diff --git a/arangodb/src/lib.rs b/arangodb/src/lib.rs index 43d41399..9b4b47c3 100644 --- a/arangodb/src/lib.rs +++ b/arangodb/src/lib.rs @@ -25,7 +25,7 @@ mod config; use std::ops::{Deref, DerefMut}; use arangors::{uclient::ClientExt, ClientError, Connection as ArangoConnection}; -use deadpool::{async_trait, managed}; +use deadpool::managed; use url::Url; pub use arangors; @@ -36,7 +36,7 @@ pub use deadpool::managed::reexports::*; deadpool::managed_reexports!( "arangors", Manager, - deadpool::managed::Object, + managed::Object, ClientError, ConfigError ); @@ -134,7 +134,6 @@ impl Manager { } } -#[async_trait] impl managed::Manager for Manager { type Type = ArangoConnection; type Error = ClientError; @@ -147,10 +146,10 @@ impl managed::Manager for Manager { .await? }; - return Ok(conn); + Ok(conn) } - async fn recycle(&self, conn: &mut ArangoConnection) -> RecycleResult { + async fn recycle(&self, conn: &mut ArangoConnection, _metrics: &Metrics) -> RecycleResult { let url = Url::parse(&self.url).expect("Url should be valid at this point"); conn.session() // I don't know if this is the correct way to do it, but TRACE should allow us to check if the connection is still open, diff --git a/arangodb/tests/arangodb.rs b/arangodb/tests/arangodb.rs index a0ee045e..770ed49d 100644 --- a/arangodb/tests/arangodb.rs +++ b/arangodb/tests/arangodb.rs @@ -1,3 +1,4 @@ +use config::ConfigError; use serde::Deserialize; use deadpool_arangodb::Runtime; @@ -15,34 +16,35 @@ struct Config { } impl Config { - pub fn from_env() -> Self { - let mut cfg = config::Config::new(); - cfg.merge(config::Environment::new().separator("__")) + pub fn from_env() -> Result { + let cfg = config::Config::builder() + .add_source(config::Environment::default().separator("__")) + .build() .unwrap(); - let mut cfg = cfg.try_into::().unwrap(); + let mut cfg: Self = cfg.try_deserialize()?; cfg.arango .url .get_or_insert("http://localhost:8529".to_string()); - cfg + Ok(cfg) } } #[tokio::test] async fn create_database() { - let cfg = Config::from_env(); + let cfg = Config::from_env().unwrap(); let pool = cfg.arango.create_pool(Runtime::Tokio1).unwrap(); let conn = pool.get().await.unwrap(); let result = conn.create_database(&cfg.dbname).await; if let Err(e) = result { - assert!(false, "Failed to create database: {:?}", e) + panic!("Failed to create database: {:?}", e) }; let result = conn.db(&cfg.dbname).await; assert!(result.is_ok()); let result = conn.drop_database(&cfg.dbname).await; if let Err(e) = result { - assert!(false, "Failed to drop database: {:?}", e) + panic!("Failed to drop database: {:?}", e) }; let result = conn.db(&cfg.dbname).await; assert!(result.is_err());