Skip to content

Commit

Permalink
Update to latest deadpool and arangors version (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder committed Jun 19, 2024
1 parent 3676e13 commit ca8440d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions arangodb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "deadpool-arangodb"
version = "0.1.0"
edition = "2018"
edition = "2021"
resolver = "2"
authors = ["Daniel Wiesenberg <[email protected]>"]
description = "Dead simple async pool for ArangoDB"
Expand All @@ -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"

Expand Down
9 changes: 4 additions & 5 deletions arangodb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +36,7 @@ pub use deadpool::managed::reexports::*;
deadpool::managed_reexports!(
"arangors",
Manager,
deadpool::managed::Object<Manager>,
managed::Object<Manager>,
ClientError,
ConfigError
);
Expand Down Expand Up @@ -134,7 +134,6 @@ impl Manager {
}
}

#[async_trait]
impl managed::Manager for Manager {
type Type = ArangoConnection;
type Error = ClientError;
Expand All @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions arangodb/tests/arangodb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use config::ConfigError;
use serde::Deserialize;

use deadpool_arangodb::Runtime;
Expand All @@ -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<Self, ConfigError> {
let cfg = config::Config::builder()
.add_source(config::Environment::default().separator("__"))
.build()
.unwrap();
let mut cfg = cfg.try_into::<Self>().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());
Expand Down

0 comments on commit ca8440d

Please sign in to comment.